X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2FConcurrentSkipList.h;h=2f8f02549d90c29d5ad911b3cb76e7865f42de66;hb=8712f36158b199cb2ffa778304ec181306a5f10d;hp=4aaf19bcd0eb9acf3c89c79a09e5ee5bac5b4523;hpb=eae5ede6dcdd1401daa7732c72196eb9540cb736;p=folly.git diff --git a/folly/ConcurrentSkipList.h b/folly/ConcurrentSkipList.h index 4aaf19bc..2f8f0254 100644 --- a/folly/ConcurrentSkipList.h +++ b/folly/ConcurrentSkipList.h @@ -1,5 +1,5 @@ /* - * Copyright 2014 Facebook, Inc. + * Copyright 2016 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -117,8 +117,7 @@ Sample usage: } */ -#ifndef FOLLY_CONCURRENT_SKIP_LIST_H_ -#define FOLLY_CONCURRENT_SKIP_LIST_H_ +#pragma once #include #include @@ -131,7 +130,7 @@ Sample usage: #include #include #include -#include +#include namespace folly { @@ -161,22 +160,35 @@ class ConcurrentSkipList { class Accessor; class Skipper; - explicit ConcurrentSkipList(int height, const NodeAlloc& alloc = NodeAlloc()) - : recycler_(alloc), - head_(NodeType::create(recycler_.alloc(), height, value_type(), true)), - size_(0) { } + explicit ConcurrentSkipList(int height, const NodeAlloc& alloc) + : recycler_(alloc), + head_(NodeType::create(recycler_.alloc(), height, value_type(), true)), + size_(0) {} + + explicit ConcurrentSkipList(int height) + : recycler_(), + head_(NodeType::create(recycler_.alloc(), height, value_type(), true)), + size_(0) {} // Convenient function to get an Accessor to a new instance. - static Accessor create(int height = 1, const NodeAlloc& alloc = NodeAlloc()) { + static Accessor create(int height, const NodeAlloc& alloc) { return Accessor(createInstance(height, alloc)); } + static Accessor create(int height = 1) { + return Accessor(createInstance(height)); + } + // Create a shared_ptr skiplist object with initial head height. - static std::shared_ptr createInstance( - int height = 1, const NodeAlloc& alloc = NodeAlloc()) { + static std::shared_ptr createInstance(int height, + const NodeAlloc& alloc) { return std::make_shared(height, alloc); } + static std::shared_ptr createInstance(int height = 1) { + return std::make_shared(height); + } + //=================================================================== // Below are implementation details. // Please see ConcurrentSkipList::Accessor for stdlib-like APIs. @@ -316,9 +328,9 @@ class ConcurrentSkipList { // locks acquired and all valid, need to modify the links under the locks. newNode = NodeType::create(recycler_.alloc(), nodeHeight, std::forward(data)); - for (int layer = 0; layer < nodeHeight; ++layer) { - newNode->setSkip(layer, succs[layer]); - preds[layer]->setSkip(layer, newNode); + for (int k = 0; k < nodeHeight; ++k) { + newNode->setSkip(k, succs[k]); + preds[k]->setSkip(k, newNode); } newNode->setFullyLinked(); @@ -366,8 +378,8 @@ class ConcurrentSkipList { continue; // this will unlock all the locks } - for (int layer = nodeHeight - 1; layer >= 0; --layer) { - preds[layer]->setSkip(layer, nodeToDelete->skip(layer)); + for (int k = nodeHeight - 1; k >= 0; --k) { + preds[k]->setSkip(k, nodeToDelete->skip(k)); } incrementSize(-1); @@ -787,5 +799,3 @@ class ConcurrentSkipList::Skipper { }; } // namespace folly - -#endif // FOLLY_CONCURRENT_SKIP_LIST_H_