diff --git a/fdbclient/include/fdbclient/VersionedMap.h b/fdbclient/include/fdbclient/VersionedMap.h index bd8f3eb482..bcff559d89 100644 --- a/fdbclient/include/fdbclient/VersionedMap.h +++ b/fdbclient/include/fdbclient/VersionedMap.h @@ -285,12 +285,17 @@ void insert(Reference>& p, Version at, const T& x) { if (!p) { p = makeReference>(x, at); } else { - bool direction = !(x < p->data); - Reference> child = p->child(direction, at); - insert(child, at, x); - p = update(p, direction, child, at); - if (p->child(direction, at)->priority > p->priority) - rotate(p, at, !direction); + int c = ::compare(x, p->data); + if (c == 0) { + p = makeReference>(p->priority, x, p->left(at), p->right(at), at); + } else { + const bool direction = !(c < 0); + Reference> child = p->child(direction, at); + insert(child, at, x); + p = update(p, direction, child, at); + if (p->child(direction, at)->priority > p->priority) + rotate(p, at, !direction); + } } } @@ -732,10 +737,6 @@ public: // insert() and erase() invalidate atLatest() and all iterators into it void insert(const K& k, const T& t) { insert(k, t, latestVersion); } void insert(const K& k, const T& t, Version insertAt) { - if (PTreeImpl::contains(roots.back().second, latestVersion, k)) - PTreeImpl::remove(roots.back().second, - latestVersion, - k); // FIXME: Make PTreeImpl::insert do this automatically (see also WriteMap.h FIXME) PTreeImpl::insert( roots.back().second, latestVersion, MapPair>(k, std::make_pair(t, insertAt))); } diff --git a/fdbclient/include/fdbclient/WriteMap.h b/fdbclient/include/fdbclient/WriteMap.h index f4d2a43511..b027b51818 100644 --- a/fdbclient/include/fdbclient/WriteMap.h +++ b/fdbclient/include/fdbclient/WriteMap.h @@ -90,6 +90,8 @@ struct WriteMapEntry { int compare(ExtStringRef const& r) const { return -r.compare(key); } + int compare(WriteMapEntry const& r) const { return key.compare(r.key); } + std::string toString() const { return printable(key); } };