#endif
}
+MatchKindCMP tree_cursor_t::compare_to(
+ const tree_cursor_t& o, value_magic_t magic) const
+{
+ // singleton
+ if (this == &o) {
+ return MatchKindCMP::EQ;
+ }
+
+ MatchKindCMP ret;
+ if (ref_leaf_node == o.ref_leaf_node) {
+ ret = position.compare_to(o.position);
+ } else {
+ auto key = get_key_view(magic);
+ auto o_key = o.get_key_view(magic);
+ ret = key.compare_to(o_key);
+ }
+ assert(ret != MatchKindCMP::EQ);
+ return ret;
+}
+
tree_cursor_t::future<>
tree_cursor_t::extend_value(context_t c, value_size_t extend_size)
{
/// Check that this is next to prv
void assert_next_to(const tree_cursor_t&, value_magic_t) const;
+ MatchKindCMP compare_to(const tree_cursor_t&, value_magic_t) const;
+
// public to Value
/// Get the latest value_header_t pointer for read.
}
}
- int cmp(const me_t& o) const {
+ MatchKindCMP compare_to(const me_t& o) const {
if (index > o.index) {
- return 1;
+ return MatchKindCMP::GT;
} else if (index < o.index) {
- return -1;
+ return MatchKindCMP::LT;
} else {
- return nxt.cmp(o.nxt);
+ return nxt.compare_to(o.nxt);
}
}
- bool operator>(const me_t& o) const { return cmp(o) > 0; }
- bool operator>=(const me_t& o) const { return cmp(o) >= 0; }
- bool operator<(const me_t& o) const { return cmp(o) < 0; }
- bool operator<=(const me_t& o) const { return cmp(o) <= 0; }
- bool operator==(const me_t& o) const { return cmp(o) == 0; }
- bool operator!=(const me_t& o) const { return cmp(o) != 0; }
+ bool operator>(const me_t& o) const { return (int)compare_to(o) > 0; }
+ bool operator>=(const me_t& o) const { return (int)compare_to(o) >= 0; }
+ bool operator<(const me_t& o) const { return (int)compare_to(o) < 0; }
+ bool operator<=(const me_t& o) const { return (int)compare_to(o) <= 0; }
+ bool operator==(const me_t& o) const { return (int)compare_to(o) == 0; }
+ bool operator!=(const me_t& o) const { return (int)compare_to(o) != 0; }
void assert_next_to(const me_t& prv) const {
#ifndef NDEBUG
return index;
}
- int cmp(const staged_position_t<STAGE_BOTTOM>& o) const {
+ MatchKindCMP compare_to(const staged_position_t<STAGE_BOTTOM>& o) const {
if (index > o.index) {
- return 1;
+ return MatchKindCMP::GT;
} else if (index < o.index) {
- return -1;
+ return MatchKindCMP::LT;
} else {
- return 0;
+ return MatchKindCMP::EQ;
}
}
- bool operator>(const me_t& o) const { return cmp(o) > 0; }
- bool operator>=(const me_t& o) const { return cmp(o) >= 0; }
- bool operator<(const me_t& o) const { return cmp(o) < 0; }
- bool operator<=(const me_t& o) const { return cmp(o) <= 0; }
- bool operator==(const me_t& o) const { return cmp(o) == 0; }
- bool operator!=(const me_t& o) const { return cmp(o) != 0; }
+ bool operator>(const me_t& o) const { return (int)compare_to(o) > 0; }
+ bool operator>=(const me_t& o) const { return (int)compare_to(o) >= 0; }
+ bool operator<(const me_t& o) const { return (int)compare_to(o) < 0; }
+ bool operator<=(const me_t& o) const { return (int)compare_to(o) <= 0; }
+ bool operator==(const me_t& o) const { return (int)compare_to(o) == 0; }
+ bool operator!=(const me_t& o) const { return (int)compare_to(o) != 0; }
me_t& operator-=(const me_t& o) {
assert(is_valid_index(o.index));
*p_tree->nm, p_tree->value_builder, p_cursor);
}
- bool operator==(const Cursor& x) const {
- return p_cursor == x.p_cursor;
- }
- bool operator!=(const Cursor& x) const {
- return !(*this == x);
- }
+ bool operator>(const Cursor& o) const { return (int)compare_to(o) > 0; }
+ bool operator>=(const Cursor& o) const { return (int)compare_to(o) >= 0; }
+ bool operator<(const Cursor& o) const { return (int)compare_to(o) < 0; }
+ bool operator<=(const Cursor& o) const { return (int)compare_to(o) <= 0; }
+ bool operator==(const Cursor& o) const { return (int)compare_to(o) != 0; }
+ bool operator!=(const Cursor& o) const { return (int)compare_to(o) == 0; }
btree_future<Cursor> get_next(Transaction& t) {
assert(!is_end());
).safe_then([this_obj] (Ref<tree_cursor_t> next_cursor) {
next_cursor->assert_next_to(
*this_obj.p_cursor, this_obj.p_tree->value_builder.get_header_magic());
- return Cursor{this_obj.p_tree, next_cursor};
+ auto ret = Cursor{this_obj.p_tree, next_cursor};
+ assert(this_obj < ret);
+ return ret;
});
}
}
Cursor(Btree* p_tree) : p_tree{p_tree} {}
+ MatchKindCMP compare_to(const Cursor& o) const {
+ assert(p_tree == o.p_tree);
+ if (p_cursor && o.p_cursor) {
+ return p_cursor->compare_to(
+ *o.p_cursor, p_tree->value_builder.get_header_magic());
+ } else if (!p_cursor && !o.p_cursor) {
+ return MatchKindCMP::EQ;
+ } else if (!p_cursor) {
+ return MatchKindCMP::GT;
+ } else { // !o.p_cursor
+ return MatchKindCMP::LT;
+ }
+ }
+
static Cursor make_end(Btree* p_tree) {
return {p_tree};
}