1
0
mirror of https://github.com/google/leveldb.git synced 2025-04-25 14:00:27 +08:00
This commit is contained in:
container-overflow 2025-03-16 03:04:02 +00:00 committed by GitHub
commit f5d69bfabe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -115,7 +115,8 @@ class SkipList {
//
// If prev is non-null, fills prev[level] with pointer to previous
// node at "level" for every level in [0..max_height_-1].
Node* FindGreaterOrEqual(const Key& key, Node** prev) const;
Node* FindGreaterOrEqual(const Key& key, Node** prev,
bool barrier_free = false) const;
// Return the latest node with a key < key.
// Return head_ if there is no such node.
@ -257,12 +258,12 @@ bool SkipList<Key, Comparator>::KeyIsAfterNode(const Key& key, Node* n) const {
template <typename Key, class Comparator>
typename SkipList<Key, Comparator>::Node*
SkipList<Key, Comparator>::FindGreaterOrEqual(const Key& key,
Node** prev) const {
SkipList<Key, Comparator>::FindGreaterOrEqual(const Key& key, Node** prev,
bool barrier_free) const {
Node* x = head_;
int level = GetMaxHeight() - 1;
while (true) {
Node* next = x->Next(level);
Node* next = barrier_free ? x->NoBarrier_Next(level) : x->Next(level);
if (KeyIsAfterNode(key, next)) {
// Keep searching in this list
x = next;
@ -336,7 +337,7 @@ void SkipList<Key, Comparator>::Insert(const Key& key) {
// TODO(opt): We can use a barrier-free variant of FindGreaterOrEqual()
// here since Insert() is externally synchronized.
Node* prev[kMaxHeight];
Node* x = FindGreaterOrEqual(key, prev);
Node* x = FindGreaterOrEqual(key, prev, true);
// Our data structure does not allow duplicate insertion
assert(x == nullptr || !Equal(key, x->key));