Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:49:46

0001 #pragma once
0002 /**
0003 sseq_array.h
0004 =============
0005 
0006 Facilitate history selection using seq array
0007 
0008 This is used from::
0009 
0010     sseq_record.h
0011 
0012 **/
0013 
0014 #include "NPX.h"
0015 #include "sseq.h"
0016 #include "sstr.h"
0017 
0018 struct sseq_array
0019 {
0020     std::vector<sseq> qq ;
0021     sseq_array( const NP* seq );
0022     NP* create_selection(const char* q_startswith);
0023     std::string desc() const ;
0024 };
0025 
0026 inline sseq_array::sseq_array(const NP* seq)
0027 {
0028     NPX::VecFromArray<sseq>(qq, seq );
0029 }
0030 
0031 /**
0032 sseq_array::create_selection
0033 -----------------------------
0034 
0035 Create array of int64_t indices into the source seq array
0036 with histories that match the argument, eg::
0037 
0038    "TO BT BT BT BT BR BT BT BT BT BT BT SC BT BT BT BT SD"
0039    "TO BT BT BT SA,TO BT BT BT EC"
0040 
0041 A comma can be used to delimit multiple histories that are
0042 individually used with the OR over all histories selection
0043 being returned.
0044 
0045 **/
0046 
0047 
0048 inline NP* sseq_array::create_selection(const char* q_startswith)
0049 {
0050     std::vector<std::string> q_sws ;
0051     sstr::Split(q_startswith, ',', q_sws );
0052 
0053     std::vector<int64_t> vv ;
0054     int nqq = int(qq.size());
0055     for(int i=0 ; i < nqq ; i++)
0056     {
0057         const sseq& q = qq[i] ;
0058         std::string his = q.seqhis_();
0059 
0060         int match = 0 ;
0061         for(int j=0 ; j < int(q_sws.size()) ; j++)
0062         {
0063             const char* q_sw = q_sws[j].c_str();
0064             bool startswith = 0==strncmp(his.c_str(), q_sw, strlen(q_sw));
0065             if(startswith) match += 1;
0066         }
0067         if(match > 0) vv.push_back(i);
0068     }
0069     NP* sel = NPX::Make<int64_t>(vv);
0070     return sel ;
0071 }
0072 
0073 /**
0074 sseq_array::desc
0075 ------------------
0076 
0077 Return summary of histories in the seq array.
0078 
0079 **/
0080 
0081 
0082 inline std::string sseq_array::desc() const
0083 {
0084     int nqq = int(qq.size());
0085     int edge = 10 ;
0086     std::stringstream ss ;
0087     ss << "[sseq_array::desc " << nqq << "\n"  ;
0088     for(int i=0 ; i < nqq ; i++)
0089     {
0090         if( ( i < edge)  || ((nqq - i) < edge) ) ss << std::setw(8) << i << "[" << qq[i].seqhis_() << "]\n" ;
0091     }
0092     ss << "]sseq_array::desc\n"  ;
0093     std::string str = ss.str();
0094     return str ;
0095 }