Skip to content

Commit

Permalink
whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
sears committed Apr 24, 2020
1 parent 4e5bf76 commit 897d895
Showing 1 changed file with 109 additions and 109 deletions.
218 changes: 109 additions & 109 deletions fdbclient/VersionedMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,63 +67,63 @@ namespace PTreeImpl {
PTree(PTree const&);
};

template <class T>
class PTreeFinger {
using PTreeFingerEntry = PTree<T> const*;
// This finger size supports trees with up to exp(96/4.3) ~= 4,964,514,749 entries.
// see also: check().
static constexpr size_t N = 96;
PTreeFingerEntry entries_[N];
size_t size_ = 0;
size_t bound_sz_ = 0;
template <class T>
class PTreeFinger {
using PTreeFingerEntry = PTree<T> const*;
// This finger size supports trees with up to exp(96/4.3) ~= 4,964,514,749 entries.
// see also: check().
static constexpr size_t N = 96;
PTreeFingerEntry entries_[N];
size_t size_ = 0;
size_t bound_sz_ = 0;

public:
PTreeFinger() {}

// Explicit copy constructors ensure we copy the live values in entries_.
PTreeFinger(PTreeFinger const& f) { *this = f; }
PTreeFinger(PTreeFinger&& f) { *this = f; }

PTreeFinger& operator=(PTreeFinger const& f) {
size_ = f.size_;
bound_sz_ = f.bound_sz_;
std::copy(f.entries_, f.entries_ + size_, entries_);
return *this;
}

PTreeFinger& operator=(PTreeFinger&& f) {
size_ = std::exchange(f.size_, 0);
bound_sz_ = f.bound_sz_;
std::copy(f.entries_, f.entries_ + size_, entries_);
return *this;
}

size_t size() const { return size_; }
PTree<T> const* back() const { return entries_[size_ - 1]; }
void pop_back() { size_--; }
void clear() { size_ = 0; }
PTree<T> const* operator[](size_t i) const { return entries_[i]; }

void resize(size_t sz) {
size_ = sz;
ASSERT(size_ < N);
}

void push_back(PTree<T> const* node) {
entries_[size_++] = { node };
ASSERT(size_ < N);
}

void push_for_bound(PTree<T> const* node, bool less) {
push_back(node);
bound_sz_ = less ? size_ : bound_sz_;
}

// remove the end of the finger so that the last entry is less than the probe
void trim_to_bound() { size_ = bound_sz_; }
};

template<class T>
PTreeFinger() {}

// Explicit copy constructors ensure we copy the live values in entries_.
PTreeFinger(PTreeFinger const& f) { *this = f; }
PTreeFinger(PTreeFinger&& f) { *this = f; }

PTreeFinger& operator=(PTreeFinger const& f) {
size_ = f.size_;
bound_sz_ = f.bound_sz_;
std::copy(f.entries_, f.entries_ + size_, entries_);
return *this;
}

PTreeFinger& operator=(PTreeFinger&& f) {
size_ = std::exchange(f.size_, 0);
bound_sz_ = f.bound_sz_;
std::copy(f.entries_, f.entries_ + size_, entries_);
return *this;
}

size_t size() const { return size_; }
PTree<T> const* back() const { return entries_[size_ - 1]; }
void pop_back() { size_--; }
void clear() { size_ = 0; }
PTree<T> const* operator[](size_t i) const { return entries_[i]; }

void resize(size_t sz) {
size_ = sz;
ASSERT(size_ < N);
}

void push_back(PTree<T> const* node) {
entries_[size_++] = { node };
ASSERT(size_ < N);
}

void push_for_bound(PTree<T> const* node, bool less) {
push_back(node);
bound_sz_ = less ? size_ : bound_sz_;
}

// remove the end of the finger so that the last entry is less than the probe
void trim_to_bound() { size_ = bound_sz_; }
};

template<class T>
static Reference<PTree<T>> update( Reference<PTree<T>> const& node, bool which, Reference<PTree<T>> const& ptr, Version at ) {
if (ptr.getPtr() == node->child(which, at).getPtr()/* && node->replacedVersion <= at*/) {
return node;
Expand Down Expand Up @@ -172,32 +172,32 @@ namespace PTreeImpl {

// TODO: Remove the number of invocations of operator<, and replace with something closer to memcmp.
// and same for upper_bound.
template <class T, class X>
void lower_bound(const Reference<PTree<T>>& p, Version at, const X& x, PTreeFinger<T>& f) {
if (!p) {
f.trim_to_bound();
return;
template <class T, class X>
void lower_bound(const Reference<PTree<T>>& p, Version at, const X& x, PTreeFinger<T>& f) {
if (!p) {
f.trim_to_bound();
return;
}
comparison cmp = compare(x, p->data);
f.push_for_bound(p.getPtr(), cmp < 0);
if (cmp == 0) return;
lower_bound(p->child(cmp > 0, at), at, x, f);
}
}

template <class T, class X>
void upper_bound(const Reference<PTree<T>>& p, Version at, const X& x, PTreeFinger<T>& f) {
if (!p) {
f.trim_to_bound();
return;
template <class T, class X>
void upper_bound(const Reference<PTree<T>>& p, Version at, const X& x, PTreeFinger<T>& f) {
if (!p) {
f.trim_to_bound();
return;
}
bool less = x < p->data;
f.push_for_bound(p.getPtr(), less);
upper_bound(p->child(!less, at), at, x, f);
}
}

template <class T, bool forward>
void move(Version at, PTreeFinger<T>& f) {
ASSERT(f.size());
template <class T, bool forward>
void move(Version at, PTreeFinger<T>& f) {
ASSERT(f.size());
const PTree<T> *n;
n = f.back();
if (n->child(forward, at)){
Expand All @@ -212,11 +212,11 @@ namespace PTreeImpl {
f.pop_back();
} while (f.size() && f.back()->child(forward, at).getPtr() == n);
}
}
}

template <class T, bool forward>
int halfMove(Version at, PTreeFinger<T>& f) {
// Post: f[:return_value] is the finger that would have been returned by move<forward>(at,f), and f[:original_length_of_f] is unmodified
template <class T, bool forward>
int halfMove(Version at, PTreeFinger<T>& f) {
// Post: f[:return_value] is the finger that would have been returned by move<forward>(at,f), and f[:original_length_of_f] is unmodified
ASSERT(f.size());
const PTree<T> *n;
n = f.back();
Expand All @@ -235,35 +235,35 @@ namespace PTreeImpl {
} while (s && f[s-1]->child(forward, at).getPtr() == n);
return s;
}
}
}

template <class T>
void next(Version at, PTreeFinger<T>& f) {
move<T,true>(at, f);
}
template <class T>
void next(Version at, PTreeFinger<T>& f) {
move<T,true>(at, f);
}

template <class T>
void previous(Version at, PTreeFinger<T>& f) {
move<T,false>(at, f);
}
template <class T>
void previous(Version at, PTreeFinger<T>& f) {
move<T,false>(at, f);
}

template <class T>
int halfNext(Version at, PTreeFinger<T>& f) {
return halfMove<T,true>(at, f);
}
template <class T>
int halfNext(Version at, PTreeFinger<T>& f) {
return halfMove<T,true>(at, f);
}

template <class T>
int halfPrevious(Version at, PTreeFinger<T>& f) {
return halfMove<T,false>(at, f);
}
template <class T>
int halfPrevious(Version at, PTreeFinger<T>& f) {
return halfMove<T,false>(at, f);
}

template <class T>
T get(PTreeFinger<T>& f) {
ASSERT(f.size());
template <class T>
T get(PTreeFinger<T>& f) {
ASSERT(f.size());
return f.back()->data;
}
}

// Modifies p to point to a PTree with x inserted
// Modifies p to point to a PTree with x inserted
template<class T>
void insert(Reference<PTree<T>>& p, Version at, const T& x) {
if (!p){
Expand Down Expand Up @@ -292,24 +292,24 @@ namespace PTreeImpl {
return lastNode(p->right(at), at);
}

template <class T, bool last>
void firstOrLastFinger(const Reference<PTree<T>>& p, Version at, PTreeFinger<T>& f) {
if (!p) return;
template <class T, bool last>
void firstOrLastFinger(const Reference<PTree<T>>& p, Version at, PTreeFinger<T>& f) {
if (!p) return;
f.push_back(p.getPtr());
firstOrLastFinger<T, last>(p->child(last, at), at, f);
}
}

template <class T>
void first(const Reference<PTree<T>>& p, Version at, PTreeFinger<T>& f) {
return firstOrLastFinger<T, false>(p, at, f);
}
template <class T>
void first(const Reference<PTree<T>>& p, Version at, PTreeFinger<T>& f) {
return firstOrLastFinger<T, false>(p, at, f);
}

template <class T>
void last(const Reference<PTree<T>>& p, Version at, PTreeFinger<T>& f) {
return firstOrLastFinger<T, true>(p, at, f);
}
template <class T>
void last(const Reference<PTree<T>>& p, Version at, PTreeFinger<T>& f) {
return firstOrLastFinger<T, true>(p, at, f);
}

// modifies p to point to a PTree with the root of p removed
// modifies p to point to a PTree with the root of p removed
template<class T>
void removeRoot(Reference<PTree<T>>& p, Version at) {
if (!p->right(at))
Expand Down

0 comments on commit 897d895

Please sign in to comment.