forked from kohler/masstree-beta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
masstree_tcursor.hh
130 lines (111 loc) · 4.13 KB
/
masstree_tcursor.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/* Masstree
* Eddie Kohler, Yandong Mao, Robert Morris
* Copyright (c) 2012-2013 President and Fellows of Harvard College
* Copyright (c) 2012-2013 Massachusetts Institute of Technology
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, subject to the conditions
* listed in the Masstree LICENSE file. These conditions include: you must
* preserve this copyright notice, and you cannot mention the copyright
* holders in advertising related to the Software without their permission.
* The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This
* notice is a summary of the Masstree LICENSE file; the license in that file
* is legally binding.
*/
#ifndef MASSTREE_TCURSOR_HH
#define MASSTREE_TCURSOR_HH 1
#include "masstree.hh"
#include "masstree_key.hh"
namespace Masstree {
template <typename P> struct gc_layer_rcu_callback;
template <typename P>
class unlocked_tcursor {
public:
typedef typename P::value_type value_type;
typedef key<typename P::ikey_type> key_type;
value_type datum_;
unlocked_tcursor(const basic_table<P> &table, Str str)
: ka_(str), tablep_(&table) {
}
unlocked_tcursor(const basic_table<P> &table, const char *s, int len)
: ka_(s, len), tablep_(&table) {
}
bool find_unlocked(threadinfo *ti);
private:
key_type ka_;
const basic_table<P> *tablep_;
};
template <typename P>
class tcursor {
public:
typedef node_base<P> node_type;
typedef leaf<P> leaf_type;
typedef internode<P> internode_type;
typedef typename P::value_type value_type;
typedef leafvalue<P> leafvalue_type;
typedef typename leaf_type::permuter_type permuter_type;
typedef typename P::ikey_type ikey_type;
typedef key<ikey_type> key_type;
typedef typename leaf<P>::nodeversion_type nodeversion_type;
tcursor(basic_table<P> &table, Str str)
: ka_(str), tablep_(&table) {
}
tcursor(basic_table<P> &table, const char *s, int len)
: ka_(s, len), tablep_(&table) {
}
inline bool has_value() const {
return kp_ >= 0;
}
inline value_type &value() const {
return n_->lv_[kp_].value();
}
inline bool is_first_layer() const {
return !ka_.is_shifted();
}
inline kvtimestamp_t node_timestamp() const {
return n_->node_ts_;
}
inline kvtimestamp_t &node_timestamp() {
return n_->node_ts_;
}
inline bool find_locked(threadinfo *ti);
inline bool find_insert(threadinfo *ti);
inline void finish(int answer, threadinfo *ti);
private:
leaf_type *n_;
key_type ka_;
int ki_;
int kp_;
basic_table<P> *tablep_;
int state_;
inline node_type *reset_retry() {
ka_.unshift_all();
return tablep_->root_;
}
inline node_type *get_leaf_locked(node_type *root, nodeversion_type &v, threadinfo *ti);
inline node_type *check_leaf_locked(node_type *root, nodeversion_type v, threadinfo *ti);
inline node_type *check_leaf_insert(node_type *root, nodeversion_type v, threadinfo *ti);
static inline node_type *insert_marker() {
return reinterpret_cast<node_type *>(uintptr_t(1));
}
static inline node_type *found_marker() {
return reinterpret_cast<node_type *>(uintptr_t(0));
}
node_type *finish_split(threadinfo *ti);
inline void finish_insert();
inline bool finish_remove(threadinfo *ti);
static void collapse(internode_type *p, ikey_type ikey,
basic_table<P> &table, Str prefix, threadinfo *ti);
/** Remove @a leaf from the Masstree rooted at @a rootp.
* @param prefix String defining the path to the tree containing this leaf.
* If removing a leaf in layer 0, @a prefix is empty.
* If removing, for example, the node containing key "01234567ABCDEF" in the layer-1 tree
* rooted at "01234567", then @a prefix should equal "01234567". */
static bool remove_leaf(leaf_type *leaf,
basic_table<P> &table, Str prefix, threadinfo *ti);
bool gc_layer(threadinfo *ti);
friend struct gc_layer_rcu_callback<P>;
};
} // namespace Masstree
#endif