<
typenameBV,
typenameVT,
typenameTOut>
25 for(
autoit = vect.begin(); it != vect.end(); ++it)
30 assert(bv.count() == vect.size());
37 template<
typenameBV,
typenameVT,
typenameTOut>
40 for(
autoit = vect.begin(); it != vect.end(); ++it)
53 template<
typenameBV,
typenameVT>
56 for(
autoit = vect.begin(); it != vect.end(); ++it)
62cerr <<
"Error! Vector(ref) comparison failed. v="<< v
70 auto count= bv.count();
71 if(
count!= vect.size())
73cerr <<
"Error! Vector(ref) size cmp failed. vect.size()="<< vect.size()
74<<
" bv.count()="<<
count<< endl;
83 template<
typenameBV,
typenameVT>
84 void compare_BV(
constBV& bv,
const VT& vect,
boolcompare_count =
true)
86 typenameBV::enumerator en = bv.first();
88 for(
autoit = vect.begin(); it != vect.end(); ++it, ++en)
93cerr <<
"Error! Vector(en) comparison failed. enumerator invalid at value="<< v0
100cerr <<
"Error! Vector(en) comparison failed. v0="<< v0
105 if((v1 != prev_id) && compare_count)
107 auto r= bv.count_range(prev_id, v1);
110cerr <<
"Error! Vector(en) comparison failed. count_range() = "<<
r 111<<
" ["<< prev_id <<
", "<< v1 <<
"]" 115 bool b= bv.any_range(prev_id, v1);
126 auto count= bv.count();
127 if(
count!= vect.size())
129cerr <<
"Error! Vector(en) size cmp failed. vect.size()="<< vect.size()
130<<
" bv.count()="<<
count<< endl;
145 typenameBV::size_type intervals_c = 1;
147 typenameBV::enumerator en1 = bv.get_enumerator(0);
148 typenameBV::enumerator en2 = bv_inv.get_enumerator(0);
152 typenameBV::size_type from = *en1;
153 typenameBV::size_type to = *en2;
159all_one = bv.is_all_one_range(from, to-1);
161any_one = bv.any_range(from, to - 1);
167all_one = bv.is_all_one_range(from, to);
169 auto cnt= bv.count_range(from, to);
170any_one = bv.any_range(from, to);
184all_one = bv.is_all_one_range(from, to);
186 typenameBV::size_type
cnt= bv.count_range(to, from);
188any_one = bv.any_range(to, from);
201all_one = bv.is_all_one_range(from, to);
203 typenameBV::size_type
cnt= bv.count_range(from, to);
206any_one = bv.any_range(from, to);
213 if(intervals != intervals_c)
215 typenameBV::size_type diff;
216diff =
std::max(intervals, intervals_c) -
std::min(intervals, intervals_c);
219cerr <<
"Intervals difference:"<< diff << endl;
229 typenameBV::size_type from,
typenameBV::size_type to)
237 while(ien.
valid())
243 autoend = ien.
end();
247bv.set_range(
st, end);
253 template<
typenameBV>
256 typenameBV::allocator_pool_type pool;
258 typenameBV::size_type
f,
l, m;
259 auto b= bv.find_range(
f,
l);
273 typenameBV::mem_pool_guard g1(pool, bv2);
274 typenameBV::mem_pool_guard g2(pool, bv2_c);
279 eq= bv2.equal(bv2_c);
285 typenameBV::mem_pool_guard g1(pool, bv2);
286 typenameBV::mem_pool_guard g2(pool, bv2_c);
288bv2_c.copy_range(bv, 0,
l);
291 eq= bv2.equal(bv2_c);
297 typenameBV::mem_pool_guard g1(pool, bv2);
298 typenameBV::mem_pool_guard g2(pool, bv2_c);
300bv2_c.copy_range(bv,
f,
l);
303 eq= bv2.equal(bv2_c);
309 typenameBV::mem_pool_guard g1(pool, bv2);
310 typenameBV::mem_pool_guard g2(pool, bv2_c);
315 eq= bv2.equal(bv2_c);
321 typenameBV::mem_pool_guard g1(pool, bv2);
322 typenameBV::mem_pool_guard g2(pool, bv2_c);
324bv2_c.copy_range(bv, m,
l);
327 eq= bv2.equal(bv2_c);
333 typenameBV::mem_pool_guard g1(pool, bv2);
334 typenameBV::mem_pool_guard g2(pool, bv2_c);
336bv2_c.copy_range(bv,
f, m);
339 eq= bv2.equal(bv2_c);
347 template<
classSV,
classVect>
350 if(vect.size() != sv.size())
352cerr <<
"Sparse vector size test failed!"<< vect.size() <<
"!="<< sv.size() << endl;
356 if(sv.is_nullable())
358 const typenameSV::bvector_type* bv_null = sv.get_null_bvector();
360 autonon_null_cnt = bv_null->count();
361 if(vect.size() != non_null_cnt)
363 if(!interval_filled)
365cerr <<
"NULL vector count failed."<< non_null_cnt <<
" size="<< vect.size() << endl;
372 typenameSV::const_iterator it = sv.begin();
373 typenameSV::const_iterator it_end = sv.end();
375 for(
unsigned i= 0;
i< vect.size(); ++
i)
381 int cmp= sv.compare(
i, v1);
385 cmp= sv.compare(
i, v1-1);
391cerr <<
"SV discrepancy:"<<
"sv["<<
i<<
"]="<<
v2 392<<
" vect["<<
i<<
"]="<< v1
398cerr <<
"SV discrepancy:"<<
"sv["<<
i<<
"]="<<
v2 408cerr <<
"sv const_iterator discrepancy!"<< endl;
409 assert(0);
return false;
415std::vector<typename SV::value_type> v1(sv.size());
416std::vector<typename SV::value_type> v1r(sv.size());
417sv.extract(&v1[0], sv.size(), 0);
418sv.extract_range(&v1r[0], sv.size(), 0);
419 for(
unsigned i= 0;
i< sv.size(); ++
i)
421 if(v1r[
i] != v1[
i] || v1[
i] != vect[
i])
423cerr <<
"TestEqualSparseVectors Extract 1 failed at:"<<
i 424<<
" v1[i]="<< v1[
i] <<
" v1r[i]="<< v1r[
i]
434bm::sparse_vector_serialize<SV>(sv, sv_lay, tb);
436 const unsigned char*
buf= sv_lay.
buf();
440cerr <<
"De-Serialization error"<< endl;
443 if(sv.is_nullable() != sv2.is_nullable())
445cerr <<
"Serialization comparison of two svectors failed (NULL vector)"<< endl;
448 const typenameSV::bvector_type* bv_null = sv.get_null_bvector();
449 const typenameSV::bvector_type* bv_null2 = sv.get_null_bvector();
451 if(bv_null != bv_null2 && (bv_null == 0 || bv_null2 == 0))
453cerr <<
"Serialization comparison (NUUL vector missing)!"<< endl;
458 if(bv_null->compare(*bv_null2) != 0)
460cerr <<
"Serialization comparison of two svectors (NULL vectors unmatch)!"<< endl;
466cerr <<
"Serialization comparison of two svectors failed"<< endl;
473 template<
typenameSV,
typenameVT>
476 for(
autoit = vect.begin(); it != vect.end(); ++it)
484 template<
typenameSV,
typenameVT>
487 for(
size_t i= 0;
i!= vect.size(); ++
i)
493std::cerr <<
"SV compare failed at:"<<
i 494<<
" v="<< v <<
" sv[]="<< vv << std::endl;
503 template<
typenameSV,
typenameVT>
507 typenameSV::back_insert_iterator bi(sv->get_back_inserter());
508 autov_prev = vect[0];
512 for(
autoit = vect.begin(); it != vect.end(); ++it)
518 typenameSV::size_type diff = v - v_prev;
529 template<
typenameCSV,
typenameSV>
545 size_tcsv_size = csv.size();
546 size_tsv_size = sv.size();
547 size_tsv_s_size = sv_s.size();
549 const typenameSV::bvector_type* bv_null_sv = sv.get_null_bvector();
550 const typenameSV::bvector_type* bv_null_sv_s = sv_s.get_null_bvector();
551 const typenameSV::bvector_type* bv_null_csv = csv.get_null_bvector();
553 if(csv_size != sv_size || sv_s_size != sv_size)
555 assert(bv_null_sv != bv_null_csv);
557 autocnt_sv = bv_null_sv->count();
558 autocnt_sv_s = bv_null_sv_s->count();
559 autocnt_csv = bv_null_csv->count();
561 if(cnt_sv != cnt_csv)
563cerr <<
"Sparse compressed vector comparison failed (size check):" 564<<
"csv.size()="<< csv_size
565<<
"sv.size()="<< sv_size
566<<
"cnt sv = "<< cnt_sv
567<<
"cnt csv = "<< cnt_csv
571 if(cnt_sv_s != cnt_csv)
573cerr <<
"Restored Sparse vector comparison failed (size check):" 574<<
"csv.size()="<< csv_size
575<<
"sv_s.size()="<< sv_s_size
576<<
"cnt sv = "<< cnt_sv
577<<
"cnt csv = "<< cnt_csv
587 cmp= bv_null_sv->compare(*bv_null_sv_s);
589 cmp= bv_null_sv->compare(*bv_null_csv);
593 typenameSV::size_type sv_first, sv_last;
594 typenameSV::size_type sv_s_first, sv_s_last;
595 typenameSV::size_type csv_first, csv_last;
597 boolfound_sv = bv_null_sv->find_range(sv_first, sv_last);
598 boolfound_sv_s = bv_null_sv_s->find_range(sv_s_first, sv_s_last);
599 boolfound_csv = bv_null_csv->find_range(csv_first, csv_last);
603 assert(found_sv_s && found_csv);
609sv_first = sv_last = sv_s_first = sv_s_last = csv_first = csv_last = 0;
612 if(csv_first != sv_first)
614cerr << csv_first <<
"!="<< sv_first << endl;
617 if(csv_last != sv_last)
619cerr << sv_s_last <<
"!="<< sv_last << endl;
623 if(sv_s_first != sv_first)
625cerr << sv_s_first <<
"!="<< sv_first << endl;
628 if(sv_s_last != sv_last)
630cerr << sv_s_last <<
"!="<< sv_last << endl;
634 assert(sv_first == sv_s_first && sv_first == csv_first);
635 assert(sv_last == sv_s_last && sv_last == csv_last);
638cout <<
"detailed compare from="<< sv_first <<
" to="<< sv_size <<
"..."<< flush;
639 for(
typenameSV::size_type
i= sv_first;
i< sv_size; ++
i)
641 boolis_null_sv = sv.is_null(
i);
642 boolis_null_sv_s = sv_s.is_null(
i);
643 boolis_null_csv = csv.is_null(
i);
644 if(is_null_sv != is_null_csv || is_null_sv != is_null_sv_s)
646cerr <<
"Detailed csv check failed (null mismatch) at i="<<
i 647<<
" sv="<< is_null_sv
648<<
" sv_s="<< is_null_sv_s
649<<
" csv="<< is_null_csv
651 int cmp= bv_null_sv->compare(*bv_null_csv);
654cerr <<
"1. cmp="<<
cmp<< endl;
657 cmp= bv_null_sv->compare(*bv_null_sv_s);
660cerr <<
"2. cmp="<<
cmp<< endl;
669 autov1_s = sv_s[
i];
672 if(v1 !=
v2|| v1_s != v1)
674cerr <<
"Detailed csv check failed (value mismatch) at i="<<
i 683cout <<
"OK"<< endl;
689bm::sparse_vector_serialize<CSV>(csv, sv_lay, tb);
692 const unsigned char*
buf= sv_lay.
buf();
695 if(!csv.equal(csv1))
697cerr <<
"Conpressed sparse vector serialization comparison failed!"<< endl;
706 template<
typenameCSV>
708 typenameCSV::size_type from,
typenameCSV::size_type
size)
710std::vector<typename CSV::value_type> vect, vect2, vect_tmp;
712vect2.resize(
size);
713vect_tmp.resize(
size);
715 typenameCSV::size_type sz = csv.decode(&vect[0], from,
size);
716 typenameCSV::size_type sz2 = csv.decode_buf(&vect2[0], &vect_tmp[0], from,
size);
719 typenameCSV::const_iterator it = csv.get_const_iterator(from);
720 typenameCSV::size_type ex_idx = 0;
721 for(
typenameCSV::size_type
i= from;
i< from + sz; ++
i)
723 autov = csv.get(
i);
724 autovx = vect[ex_idx];
725 autovx2 = vect[ex_idx];
728 if(v != vx || v != vx2 || v != vx_it)
730cerr <<
"compressed vector decode mismatch from=" 731<< from <<
" idx="<<
i 732<<
" v="<< v <<
" vx="<< vx
741 template<
typenameCSV>
744 auto size= csv.size();
748 typenameCSV::size_type size1 = 100;
749 for(
typenameCSV::size_type
i= 0;
i< size1; )
753cout <<
"\r"<<
i<<
"/"<< size1 << flush;
760 typenameCSV::size_type size1 = 100000;
761 for(
typenameCSV::size_type
i= 0;
i< size1; )
764cout <<
"\r"<<
i<<
"/"<< size1 << flush;
772 typenameCSV::size_type size1 =
size;
773 for(
typenameCSV::size_type
i=
size-
size/ 2;
i< size1; )
776cout <<
"\r"<<
i<<
"/"<< size1 << flush;
785cout <<
"\r"<<
i<<
"/"<<
size<< flush;
795cout <<
"\r"<<
i<<
"/"<<
size<< flush;
797 size-= rand() % 25000;;
806 if(sv1.size() != sv2.size())
808cerr <<
"TestEqualSparseVectors failed incorrect size"<< endl;
812 if(sv1.is_nullable() == sv2.is_nullable())
814 bool b= sv1.equal(sv2);
817cerr <<
"sv1.equal(sv2) failed"<< endl;
820 const typenameSV::bvector_type* bv_null1 = sv1.get_null_bvector();
821 const typenameSV::bvector_type* bv_null2 = sv2.get_null_bvector();
823 if(bv_null1 != bv_null2)
825 int r= bv_null1->compare(*bv_null2);
828cerr <<
"sparse NULL-vectors comparison failed"<< endl;
842std::vector<unsigned> v1(sv1.size());
843std::vector<unsigned> v1r(sv1.size());
844std::vector<unsigned> v1p(sv1.size());
846sv1.extract(&v1[0], sv1.size(), 0);
847sv1.extract_range(&v1r[0], sv1.size(), 0);
848sv1.extract_planes(&v1p[0], sv1.size(), 0);
850 for(
typenameSV::size_type
i= 0;
i< sv1.size(); ++
i)
852 if(v1r[
i] != v1[
i] || v1p[
i] != v1[
i])
854cerr <<
"TestEqualSparseVectors Extract 1 failed at:"<<
i 855<<
" v1[i]="<< v1[
i] <<
" v1r[i]="<< v1r[
i] <<
" v1p[i]="<< v1p[
i]
865std::vector<unsigned> v1(sv1.size());
866std::vector<unsigned> v1r(sv1.size());
867std::vector<unsigned> v1p(sv1.size());
869 typenameSV::size_type pos = sv1.size() / 2;
871sv1.extract(&v1[0], sv1.size(), pos);
872sv1.extract_range(&v1r[0], sv1.size(), pos);
873sv1.extract_planes(&v1p[0], sv1.size(), pos);
875 for(
typenameSV::size_type
i= 0;
i< sv1.size(); ++
i)
877 if(v1r[
i] != v1[
i] || v1p[
i] != v1[
i])
879cerr <<
"TestEqualSparseVectors Extract 1 failed at:"<<
i 880<<
" v1[i]="<< v1[
i] <<
" v1r[i]="<< v1r[
i] <<
" v1p[i]="<< v1p[
i]
893 bool b= svv1.equal(svv2, is_null);
896cerr <<
"Equal, copyctor comparison failed"<< endl;
901 b= svv1.equal(svv2, is_null);
904cerr <<
"Equal, copyctor-swap comparison failed"<< endl;
913sv3.resize(sv1.size());
914 for(
typenameSV::size_type
i= 0;
i< sv1.size(); ++
i)
917 unsignedv1 = sv1[
i];
918 unsigned v2= sv3[
i];
921cerr <<
"1. sparse_vector reference assignment validation failed"<< endl;
926 bool b= sv1.equal(sv3, is_null);
929cerr <<
"2. sparse_vector reference assignment validation failed"<< endl;
937 typenameSV::const_iterator it1 = sv1.begin();
938 typenameSV::const_iterator it2 = sv2.begin();
939 typenameSV::const_iterator it1_end = sv1.end();
941 for(; it1 < it1_end; ++it1, ++it2)
945cerr <<
"1. sparse_vector::const_iterator validation failed"<< endl;
959 const unsigned char*
buf= sv_lay.
buf();
960 size_tbuf_size = sv_lay.
size();
962vector<unsigned char> tmp_buf(buf_size);
963::memcpy(&tmp_buf[0],
buf, buf_size);
969cerr <<
"De-Serialization error in TestEqualSparseVectors()"<< endl;
973 const typenameSV::bvector_type* bv_null1 = sv1.get_null_bvector();
974 const typenameSV::bvector_type* bv_null2 = sv2.get_null_bvector();
975 const typenameSV::bvector_type* bv_null3 = sv3.get_null_bvector();
977 if(bv_null1 && bv_null3)
979 int r= bv_null1->compare(*bv_null3);
982cerr <<
"2. NULL bvectors comparison failed"<< endl;
986 if(bv_null1 && bv_null2)
988 int r= bv_null1->compare(*bv_null2);
991cerr <<
"3. NULL bvectors comparison failed"<< endl;
997 if(!sv1.equal(sv3, is_null) )
999cerr <<
"Serialization comparison of two svectors failed (1)"<< endl;
1003 if(!sv2.equal(sv3, is_null))
1005cerr <<
"Serialization comparison of two svectors failed (2)"<< endl;
1016 template<
typenameSSV>
1018 conststd::vector<string>& str_coll)
1020 assert(str_sv.size() == str_coll.size());
1022 stringstr_h =
"z";
1023 stringstr_l =
"A";
1025 typedef typenameSSV::bvector_type
bvect;
1029 typenameSSV::const_iterator it = str_sv.begin();
1031 for(
typenameSSV::size_type
i= 0;
i< str_sv.size(); ++
i, ++it)
1034 assert(it != str_sv.end());
1036str_sv.get(
i,
str);
1037 const string& str_control = str_coll[
i];
1038 if(
str!= str_control)
1040std::cerr <<
"String mis-match at:"<<
i<< std::endl;
1044 const char* s = *it;
1048cerr <<
"Iterator comparison failed! "<< s <<
" != "<< str_control
1052 typenameSSV::const_iterator it2 = str_sv.get_const_iterator(
i);
1058cerr <<
"2. Iterator comparison failed! "<< s <<
" != "<< str_control
1063 int cmp= str_sv.compare(
i, str_control.c_str());
1066std::cerr <<
"String comparison failure at:"<<
i<< std::endl;
1069 if(!str_sv.is_remap())
1071 cmp= str_sv.compare(
i, str_h.c_str());
1081 cmp= str_sv.compare(
i, str_l.c_str());
1092 typenameSSV::size_type pos;
1093 boolfound = scanner.
find_eq_str(str_sv, str_control.c_str(), pos);
1096cerr <<
"Scanner search failed! "<< str_control << endl;
1100 if(
i% 100000 == 0)
1102cout <<
"\r"<<
i<<
" / "<< str_sv.size() << flush;
1109 template<
typenameBV>
1113 typenameBV::size_type pos, pos_c, pos_l;
1114 f= bv1.find_first_mismatch(bv2, pos);
1116bv_x.bit_xor(bv1, bv2, BV::opt_compress);
1119 auto a= bv_x.any();
1125 boolf2 = bv1.find_first_mismatch(bv2, pos_l, pos);
1130f2 = bv1.find_first_mismatch(bv2, pos_l, pos-1);
1135 boolcf = bv_x.find(pos_c);
1139 f= bv2.find_first_mismatch(bv1, pos);
#define BM_DECLARE_TEMP_BLOCK(x)
forward iterator class to traverse bit-vector as ranges
bool valid() const noexcept
Returns true if enumerator is valid (false if traversal is done)
size_type start() const noexcept
Return interval start/left as bit-vector coordinate 011110 [left..right].
size_type end() const noexcept
Return interval end/right as bit-vector coordinate 011110 [left..right].
algorithms for sparse_vector scan/search
bool find_eq_str(const SV &sv, const value_type *str, bvector_type &bv_out)
find sparse vector elements (string)
static const char * str(char *buf, int n)
null_support
NULL-able value support.
@ use_null
support "non-assigned" or "NULL" logic
@ no_null
do not support NULL values
bool is_interval(const BV &bv, typename BV::size_type left, typename BV::size_type right) noexcept
Returns true if range is all 1s flanked with 0s Function performs the test on a closed range [left,...
BV::size_type count_intervals(const BV &bv)
Compute number of bit intervals (GAPs) in the bitvector.
void sparse_vector_serialize(const SV &sv, sparse_vector_serial_layout< SV > &sv_layout, bm::word_t *temp_block=0)
Serialize sparse vector into a memory buffer(s) structure.
int sparse_vector_deserialize(SV &sv, const unsigned char *buf, bm::word_t *temp_block=0)
Deserialize sparse vector.
void xor_swap(W &x, W &y) noexcept
XOR swap two variables.
size_t print_bvector_stat(TOut &tout, const BV &bvect)
void print_stat(TOut &tout, const BV &bv, typename BV::block_idx_type blocks=0)
double value_type
The numeric datatype used by the parser.
const struct ncbi::grid::netcache::search::fields::SIZE size
int strcmp(const char *str1, const char *str2)
bool eq(T x_, T y_, T round_)
double r(size_t dimension_, const Int4 *score_, const double *prob_, double theta_)
static SLJIT_INLINE sljit_ins st(sljit_gpr r, sljit_s32 d, sljit_gpr x, sljit_gpr b)
static SLJIT_INLINE sljit_ins l(sljit_gpr r, sljit_s32 d, sljit_gpr x, sljit_gpr b)
bm::bvector< dbg_alloc > bvect
layout class for serialization buffer structure
const unsigned char * buf() const noexcept
Return serialization buffer pointer.
size_t size() const noexcept
return current serialized size
void compare_BV_set_ref(const BV &bv, const VT &vect, bool compare_count=true)
CMP bit-vector using ref syntax.
void CheckCompressedDecode(const CSV &csv, typename CSV::size_type from, typename CSV::size_type size)
bool CompareSparseVector(const SV &sv, const Vect &vect, bool interval_filled=false)
void TestFindDiff(const BV &bv1, BV &bv2)
void interval_copy_range(BV &bv, const BV &bv_src, typename BV::size_type from, typename BV::size_type to)
void IntervalsCheck(const BV &bv)
void compare_SV_set_ref(const SV &sv, const VT &vect)
void load_SV_set_ref(SV *sv, const VT &vect)
void CompareStrSparseVector(const SSV &str_sv, const std::vector< string > &str_coll)
void DetailedCheckCompressedDecode(const CSV &csv)
void clear_BV_set_ref(TOut &tout, BV &bv, const VT &vect, bool print_stat=true)
Load bit-vector using ref syntax.
void compare_BV(const BV &bv, const VT &vect, bool compare_count=true)
CMP bit-vector using enumerator.
void bulk_load_SV_set_ref(SV *sv, const VT &vect)
void IntervalsEnumeratorCheck(const BV &bv)
bool TestEqualSparseVectors(const SV &sv1, const SV &sv2, bool detailed=true)
void load_BV_set_ref(TOut &tout, BV &bv, const VT &vect, bool print_stat=true)
Load bit-vector using ref syntax.
void DetailedCompareSparseVectors(const CSV &csv, const SV &sv)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4