7 #ifndef swcdb_db_Cells_KeyComparator_h
8 #define swcdb_db_Cells_KeyComparator_h
18 namespace SWC {
namespace DB {
28 const uint8_t *p1, uint32_t p1_len,
29 const uint8_t *p2, uint32_t p2_len)
32 template<Types::KeySeq T_seq>
36 const uint8_t *p2, uint32_t p2_len)
43 const uint8_t *p1, uint32_t p1_len,
44 const uint8_t *p2, uint32_t p2_len)
47 template<Types::KeySeq T_seq>
51 const uint8_t *p1, uint32_t p1_len,
52 const uint8_t *p2, uint32_t p2_len)
62 template<Types::KeySeq T_seq>
97 template<Types::KeySeq T_seq>
112 template<Types::
KeySeq T_seq>
115 compare(const Cell::Key& key, const Cell::Key& other,
123 const Cell::Key& key, const Cell::KeyVec& other,
124 Condition::
Comp break_if, uint32_t max = 0,
bool empty_ok=false)
127 template<Types::
KeySeq T_seq>
130 compare(const Cell::Key& key, const Cell::KeyVec& other,
131 Condition::
Comp break_if, uint32_t max,
bool empty_ok)
137 align(const Types::
KeySeq seq, const Cell::Key& key,
138 Cell::KeyVec& start, Cell::KeyVec& finish)
141 template<Types::
KeySeq T_seq>
144 align(const Cell::Key& key, Cell::KeyVec& start, Cell::KeyVec& finish)
151 const Cell::KeyVec& other, Condition::
Comp comp)
154 template<Types::
KeySeq T_seq>
157 align(Cell::KeyVec& key, const Cell::KeyVec& other, Condition::
Comp comp)
169 const uint8_t *p2, uint32_t p2_len) noexcept {
176 condition<Types::KeySeq::VOLUME>(
const uint8_t *p1, uint32_t p1_len,
177 const uint8_t *p2, uint32_t p2_len) noexcept {
184 const uint8_t *p1, uint32_t p1_len,
185 const uint8_t *p2, uint32_t p2_len) noexcept {
188 case Types::KeySeq::LEXIC:
189 case Types::KeySeq::FC_LEXIC:
190 return condition<Types::KeySeq::LEXIC>(p1, p1_len, p2, p2_len);
192 case Types::KeySeq::VOLUME:
194 return condition<Types::KeySeq::VOLUME>(p1, p1_len, p2, p2_len);
209 const uint8_t *p1, uint32_t p1_len,
210 const uint8_t *p2, uint32_t p2_len) noexcept {
218 const uint8_t *p1, uint32_t p1_len,
219 const uint8_t *p2, uint32_t p2_len) noexcept {
226 const uint8_t *p1, uint32_t p1_len,
227 const uint8_t *p2, uint32_t p2_len) noexcept {
230 case Types::KeySeq::LEXIC:
231 case Types::KeySeq::FC_LEXIC:
232 return is_matching<Types::KeySeq::LEXIC>(comp, p1, p1_len, p2, p2_len);
234 case Types::KeySeq::VOLUME:
236 return is_matching<Types::KeySeq::VOLUME>(comp, p1, p1_len, p2, p2_len);
247 template<Types::KeySeq T_seq>
252 const uint8_t* p1 = key.
data;
253 const uint8_t* p2 = other.
data;
259 if((comp = condition<T_seq>(p1, sz1, p2, sz2)) !=
Condition::EQ)
271 compare<Types::KeySeq::FC_LEXIC>(
const Cell::Key& key,
277 : compare<Types::KeySeq::LEXIC>(key, other) );
283 compare<Types::KeySeq::FC_VOLUME>(
const Cell::Key& key,
289 : compare<Types::KeySeq::VOLUME>(key, other) );
298 case Types::KeySeq::LEXIC:
299 return compare<Types::KeySeq::LEXIC>(key, other);
301 case Types::KeySeq::VOLUME:
302 return compare<Types::KeySeq::VOLUME>(key, other);
304 case Types::KeySeq::FC_LEXIC:
305 return compare<Types::KeySeq::FC_LEXIC>(key, other);
308 return compare<Types::KeySeq::FC_VOLUME>(key, other);
319 template<Types::KeySeq T_seq>
328 const uint8_t* p1 = opt_empty.
data;
329 const uint8_t* p2 = other.
data;
336 if((comp = condition<T_seq>(p1, sz1, p2, sz2)) !=
Condition::EQ)
341 (!max || max > opt_empty.
count || max > other.
count)
349 compare_opt<Types::KeySeq::FC_LEXIC>(
352 if(!max || max > opt_empty.
count || max > other.
count) {
358 return compare_opt<Types::KeySeq::LEXIC>(
359 opt_empty, other, max, empty_eq);
365 compare_opt<Types::KeySeq::FC_VOLUME>(
368 if(!max || max > opt_empty.
count || max > other.
count) {
374 return compare_opt<Types::KeySeq::VOLUME>(
375 opt_empty, other, max, empty_eq);
383 return compare_opt<Types::KeySeq::LEXIC>(
384 opt_empty, other, max, empty_eq);
391 return compare_opt<Types::KeySeq::VOLUME>(
392 opt_empty, other, max, empty_eq);
399 return compare_opt<Types::KeySeq::FC_LEXIC>(
400 opt_empty, other, max, empty_eq);
407 return compare_opt<Types::KeySeq::FC_VOLUME>(
408 opt_empty, other, max, empty_eq);
421 case Types::KeySeq::LEXIC:
422 return compare_opt<Types::KeySeq::LEXIC>(
423 key, other, max,
false);
425 case Types::KeySeq::VOLUME:
426 return compare_opt<Types::KeySeq::VOLUME>(
427 key, other, max,
false);
429 case Types::KeySeq::FC_LEXIC:
430 return compare_opt<Types::KeySeq::FC_LEXIC>(
431 key, other, max,
false);
434 return compare_opt<Types::KeySeq::FC_VOLUME>(
435 key, other, max,
false);
446 template<Types::KeySeq T_seq>
451 const uint8_t* p1 = key.
data;
452 const uint8_t* p2 = other.
data;
457 for(
uint24_t c = 0; c<max; ++c, p1 += sz1, p2 += sz2) {
468 if(condition<T_seq>(p1, sz1, p2, sz2) == break_if)
477 compare<Types::KeySeq::FC_LEXIC>(
480 if(!max || max > key.
count || max > other.
count ) {
486 return compare<Types::KeySeq::LEXIC>(key, other, break_if, max, empty_ok);
492 compare<Types::KeySeq::FC_VOLUME>(
495 if(!max || max > key.
count || max > other.
count ) {
501 return compare<Types::KeySeq::VOLUME>(key, other, break_if, max, empty_ok);
511 case Types::KeySeq::LEXIC:
512 return compare<Types::KeySeq::LEXIC>(
513 key, other, break_if, max, empty_ok);
515 case Types::KeySeq::VOLUME:
516 return compare<Types::KeySeq::VOLUME>(
517 key, other, break_if, max, empty_ok);
519 case Types::KeySeq::FC_LEXIC:
520 return compare<Types::KeySeq::FC_LEXIC>(
521 key, other, break_if, max, empty_ok);
524 return compare<Types::KeySeq::FC_VOLUME>(
525 key, other, break_if, max, empty_ok);
536 template<Types::KeySeq T_seq>
541 const uint8_t* ptr = key.
data;
545 for(uint32_t c = 0; c<max; ++c, ptr += len) {
556 if(condition<T_seq>(ptr, len, r.data(), r.length())
566 compare<Types::KeySeq::FC_LEXIC>(
569 if(!max || max > key.
count || max > other.
size() ) {
575 return compare<Types::KeySeq::LEXIC>(key, other, break_if, max, empty_ok);
581 compare<Types::KeySeq::FC_VOLUME>(
584 if(!max || max > key.
count || max > other.
size() ) {
590 return compare<Types::KeySeq::VOLUME>(key, other, break_if, max, empty_ok);
600 case Types::KeySeq::LEXIC:
601 return compare<Types::KeySeq::LEXIC>(
602 key, other, break_if, max, empty_ok);
604 case Types::KeySeq::VOLUME:
605 return compare<Types::KeySeq::VOLUME>(
606 key, other, break_if, max, empty_ok);
608 case Types::KeySeq::FC_LEXIC:
609 return compare<Types::KeySeq::FC_LEXIC>(
610 key, other, break_if, max, empty_ok);
613 return compare<Types::KeySeq::FC_VOLUME>(
614 key, other, break_if, max, empty_ok);
625 template<Types::KeySeq T_seq>
629 const uint8_t* ptr = key.
data;
632 auto it_min = start.
begin();
633 auto it_max = finish.
begin();
637 if(it_min == start.
cend()) {
640 it_min = start.
end();
642 if(condition<T_seq>(it_min->data(), it_min->size(),
644 it_min->assign(ptr, len);
650 if(it_max == finish.
cend()) {
651 finish.
add(ptr, len);
653 it_max = finish.
end();
655 if(condition<T_seq>(it_max->data(), it_max->size(),
657 it_max->assign(ptr, len);
672 case Types::KeySeq::LEXIC:
673 case Types::KeySeq::FC_LEXIC:
674 return align<Types::KeySeq::LEXIC>(key, start, finish);
676 case Types::KeySeq::VOLUME:
678 return align<Types::KeySeq::VOLUME>(key, start, finish);
689 template<Types::KeySeq T_seq>
702 auto it2 = other.
cbegin();
703 for(
auto it1 = key.
begin(); min; --min, ++it1, ++it2) {
704 if(condition<T_seq>(it1->data(), it1->size(),
705 it2->data(), it2->size())
713 while(++it2 != other.
cend());
725 case Types::KeySeq::LEXIC:
726 case Types::KeySeq::FC_LEXIC:
727 return align<Types::KeySeq::LEXIC>(key, other, comp);
729 case Types::KeySeq::VOLUME:
731 return align<Types::KeySeq::VOLUME>(key, other, comp);
745 #endif // swcdb_db_Cells_KeyComparator_h