MCPcopy Create free account
hub / github.com/Clarionos/clarion / iterator

Class iterator

tests/clio/database.cpp:457–508  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

455 }
456
457 struct iterator
458 {
459 iterator() {}
460 const T& operator*() const { return pos->value(); }
461 iterator& operator++()
462 {
463 if (not pos)
464 return *this;
465 // std::cout << "start: " << **this << "\n";
466
467 auto& right = pos->right();
468 if (right)
469 {
470 pos = right;
471 // std::cout << " go right to: " << **this << "\n";
472 while (auto& left = pos->left())
473 {
474 pos = left;
475 // std::cout << " go left to: " << **this << "\n";
476 }
477 }
478 else
479 {
480 // std::cout << " go to parent while parent right != me\n";
481 while (auto& parent = pos->parent())
482 {
483 if (parent->right() == pos)
484 {
485 pos = parent;
486 // std::cout << " go to next parent: " << **this << "\n";
487 }
488 else
489 {
490 // std::cout << " go to parent: " << **this << "\n";
491 pos = parent;
492 return *this;
493 }
494 }
495 // std::cout << " no more parents! We are done\n";
496 pos = node_cptr();
497 }
498 return *this;
499 }
500
501 friend bool operator==(const iterator& a, const iterator& b) { return a.pos == b.pos; }
502 friend bool operator!=(const iterator& a, const iterator& b) { return a.pos != b.pos; }
503
504 private:
505 friend class tree_cache;
506 iterator(const node_cptr& p) : pos(p) {}
507 node_cptr pos;
508 };
509
510 iterator lower_bound(const T& v) const { return lower_bound(v, root()); }
511 iterator end() const { return iterator(node_cptr()); }

Callers 2

endMethod · 0.70
lower_boundMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected