Commit d7e90075 authored by Philip Pronin's avatar Philip Pronin Committed by Facebook GitHub Bot

expose ConcurrentSkipList::size

Summary:
It is safe to expose `size()` without requirement to go through
accessor (which adds reference tracking overhead).

Reviewed By: yfeldblum

Differential Revision: D28591686

fbshipit-source-id: ea0be2a34df01488402e53fdfbe232ee710f03f7
parent f498404b
......@@ -165,13 +165,13 @@ class ConcurrentSkipList {
explicit ConcurrentSkipList(int height, const NodeAlloc& alloc)
: recycler_(alloc),
head_(NodeType::create(recycler_.alloc(), height, value_type(), true)),
size_(0) {}
head_(NodeType::create(recycler_.alloc(), height, value_type(), true)) {
}
explicit ConcurrentSkipList(int height)
: recycler_(),
head_(NodeType::create(recycler_.alloc(), height, value_type(), true)),
size_(0) {}
head_(NodeType::create(recycler_.alloc(), height, value_type(), true)) {
}
// Convenient function to get an Accessor to a new instance.
static Accessor create(int height, const NodeAlloc& alloc) {
......@@ -192,6 +192,9 @@ class ConcurrentSkipList {
return std::make_shared<ConcurrentSkipList>(height);
}
size_t size() const { return size_.load(std::memory_order_relaxed); }
bool empty() const { return size() == 0; }
//===================================================================
// Below are implementation details.
// Please see ConcurrentSkipList::Accessor for stdlib-like APIs.
......@@ -247,8 +250,6 @@ class ConcurrentSkipList {
return foundLayer;
}
size_t size() const { return size_.load(std::memory_order_relaxed); }
int height() const { return head_.load(std::memory_order_consume)->height(); }
int maxLayer() const { return height() - 1; }
......@@ -529,7 +530,7 @@ class ConcurrentSkipList {
detail::NodeRecycler<NodeType, NodeAlloc> recycler_;
std::atomic<NodeType*> head_;
std::atomic<size_t> size_;
std::atomic<size_t> size_{0};
};
template <typename T, typename Comp, typename NodeAlloc, int MAX_HEIGHT>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment