Changeset View
Changeset View
Standalone View
Standalone View
src/radix.h
Show First 20 Lines • Show All 168 Lines • ▼ Show 20 Lines | bool insert(const K &key, RCUPtr<T> value) { | ||||
// The element was already in the tree. | // The element was already in the tree. | ||||
const K &leafKey = e.getLeaf()->getId(); | const K &leafKey = e.getLeaf()->getId(); | ||||
if (key == leafKey) { | if (key == leafKey) { | ||||
return false; | return false; | ||||
} | } | ||||
// There is an element there, but it isn't a subtree. We need to | // There is an element there, but it isn't a subtree. We need to | ||||
// convert it into a subtree and resume insertion into that subtree. | // convert it into a subtree and resume insertion into that subtree. | ||||
std::unique_ptr<RadixNode> newChild = | auto newChild = std::make_unique<RadixNode>(level, leafKey, e); | ||||
std::make_unique<RadixNode>(level, leafKey, e); | |||||
if (eptr->compare_exchange_strong(e, | if (eptr->compare_exchange_strong(e, | ||||
RadixElement(newChild.get()))) { | RadixElement(newChild.get()))) { | ||||
// We have a subtree, resume normal operations from there. | // We have a subtree, resume normal operations from there. | ||||
newChild.release(); | newChild.release(); | ||||
} else { | } else { | ||||
// We failed to insert our subtree, clean it before it is freed. | // We failed to insert our subtree, clean it before it is freed. | ||||
newChild->get(level, leafKey)->store(RadixElement()); | newChild->get(level, leafKey)->store(RadixElement()); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 100 Lines • Show Last 20 Lines |