2 * Eddie Kohler, Yandong Mao, Robert Morris
3 * Copyright (c) 2012-2014 President and Fellows of Harvard College
4 * Copyright (c) 2012-2014 Massachusetts Institute of Technology
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, subject to the conditions
9 * listed in the Masstree LICENSE file. These conditions include: you must
10 * preserve this copyright notice, and you cannot mention the copyright
11 * holders in advertising related to the Software without their permission.
12 * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This
13 * notice is a summary of the Masstree LICENSE file; the license in that file
16 #ifndef MASSTREE_GET_HH
17 #define MASSTREE_GET_HH 1
18 #include "masstree_tcursor.hh"
19 #include "masstree_key.hh"
23 bool unlocked_tcursor<P>::find_unlocked(threadinfo& ti)
26 key_indexed_position kx;
27 node_base<P>* root = const_cast<node_base<P>*>(root_);
30 n_ = root->reach_leaf(ka_, v_, ti);
37 perm_ = n_->permutation();
38 kx = leaf<P>::bound_type::lower(ka_, *this);
41 lv_.prefetch(n_->keylenx_[kx.p]);
42 match = n_->ksuf_matches(kx.p, ka_);
45 if (n_->has_changed(v_)) {
46 ti.mark(threadcounter(tc_stable_leaf_insert + n_->simple_has_split(v_)));
47 n_ = n_->advance_to_key(ka_, v_, ti);
60 inline bool basic_table<P>::get(Str key, value_type &value,
63 unlocked_tcursor<P> lp(*this, key);
64 bool found = lp.find_unlocked(ti);
71 bool tcursor<P>::find_locked(threadinfo& ti)
73 node_base<P>* root = const_cast<node_base<P>*>(root_);
78 n_ = root->reach_leaf(ka_, v, ti);
85 perm = n_->permutation();
87 kx_ = leaf<P>::bound_type::lower(ka_, *n_);
89 leafvalue<P> lv = n_->lv_[kx_.p];
90 lv.prefetch(n_->keylenx_[kx_.p]);
91 state_ = n_->ksuf_matches(kx_.p, ka_);
92 if (state_ < 0 && !n_->has_changed(v) && !lv.layer()->has_split()) {
93 ka_.shift_by(-state_);
100 n_->lock(v, ti.lock_fence(tc_leaf_lock));
101 if (n_->has_changed(v) || n_->permutation() != perm) {
102 ti.mark(threadcounter(tc_stable_leaf_insert + n_->simple_has_split(v)));
104 n_ = n_->advance_to_key(ka_, v, ti);
106 } else if (unlikely(state_ < 0)) {
107 ka_.shift_by(-state_);
108 n_->lv_[kx_.p] = root = n_->lv_[kx_.p].layer()->unsplit_ancestor();
111 } else if (unlikely(n_->deleted_layer())) {
113 root = const_cast<node_base<P>*>(root_);
119 } // namespace Masstree