libfoedus-core
FOEDUS Core Library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
foedus::storage::array::LookupRouteFinder Class Reference

Packages logic and required properties to calculate LookupRoute in array storage from offset. More...

Detailed Description

Packages logic and required properties to calculate LookupRoute in array storage from offset.

This class is completely header-only, immutable, and also a POD.

Optimization
This class uses efficient division to determine the route. We originally used simple std::lldiv(), which caused 20% of CPU cost in read-only experiment. wow. The code below now costs only 6%.

Definition at line 86 of file array_route.hpp.

#include <array_route.hpp>

Public Member Functions

 LookupRouteFinder ()
 
 LookupRouteFinder (uint8_t levels, uint16_t payload_size)
 
LookupRoute find_route (ArrayOffset offset) const __attribute__((always_inline))
 
LookupRoute find_route_and_switch (ArrayOffset offset, ArrayOffset *page_starts, ArrayOffset *page_ends) const __attribute__((always_inline))
 find_route() plus calculates where page switches. More...
 
uint8_t get_levels () const __attribute__((always_inline))
 
uint16_t get_records_in_leaf () const __attribute__((always_inline))
 

Constructor & Destructor Documentation

foedus::storage::array::LookupRouteFinder::LookupRouteFinder ( )
inline

Definition at line 88 of file array_route.hpp.

89  : levels_(0),
90  records_in_leaf_(0),
91  leaf_fanout_div_(1),
92  interior_fanout_div_(1) {
93  }
foedus::storage::array::LookupRouteFinder::LookupRouteFinder ( uint8_t  levels,
uint16_t  payload_size 
)
inline

Definition at line 94 of file array_route.hpp.

95  : levels_(levels),
96  records_in_leaf_(to_records_in_leaf(payload_size)),
97  leaf_fanout_div_(records_in_leaf_),
98  interior_fanout_div_(kInteriorFanout) {
99  }
uint16_t to_records_in_leaf(uint16_t payload_size)
Definition: array_route.hpp:71
const uint16_t kInteriorFanout
Max number of entries in an interior page of array storage.
Definition: array_id.hpp:110

Member Function Documentation

LookupRoute foedus::storage::array::LookupRouteFinder::find_route ( ArrayOffset  offset) const
inline

Definition at line 134 of file array_route.hpp.

References ASSERT_ND, foedus::assorted::ConstDiv::div64(), foedus::storage::array::kInteriorFanout, foedus::storage::array::LookupRoute::route, and foedus::storage::array::LookupRoute::word.

Referenced by foedus::storage::array::ArrayStoragePimpl::lookup_for_read(), foedus::storage::array::ArrayStoragePimpl::lookup_for_read_batch(), foedus::storage::array::ArrayStoragePimpl::lookup_for_write(), and foedus::storage::array::ArrayStoragePimpl::lookup_for_write_batch().

134  {
135  LookupRoute ret;
136  ret.word = 0;
137  ArrayOffset old = offset;
138  offset = leaf_fanout_div_.div64(offset);
139  ret.route[0] = old - offset * records_in_leaf_;
140  for (uint8_t level = 1; level < levels_ - 1; ++level) {
141  old = offset;
142  offset = interior_fanout_div_.div64(offset);
143  ret.route[level] = old - offset * kInteriorFanout;
144  }
145  if (levels_ > 1) {
146  // the last level is done manually because we don't need any division there
147  ASSERT_ND(offset < kInteriorFanout);
148  ret.route[levels_ - 1] = offset;
149  }
150 
151  return ret;
152 }
uint64_t ArrayOffset
The only key type in array storage.
Definition: array_id.hpp:48
const uint16_t kInteriorFanout
Max number of entries in an interior page of array storage.
Definition: array_id.hpp:110
#define ASSERT_ND(x)
A warning-free wrapper macro of assert() that has no performance effect in release mode even when 'x'...
Definition: assert_nd.hpp:72
uint64_t div64(uint64_t n) const
64-bit integer division that outputs both quotient and remainder.
Definition: const_div.hpp:241

Here is the call graph for this function:

Here is the caller graph for this function:

LookupRoute foedus::storage::array::LookupRouteFinder::find_route_and_switch ( ArrayOffset  offset,
ArrayOffset page_starts,
ArrayOffset page_ends 
) const
inline

find_route() plus calculates where page switches.

Parameters
[in]offsetarray offset
[out]page_startsminimal offset that belongs to the same page as the given offset
[out]page_endsminimal offset that belongs to a page different from the given offset
Invariant
page_starts <= offset < page_ends
(page_starts / records_in_leaf_) == (offset / records_in_leaf_)
(page_ends / records_in_leaf_) == (offset / records_in_leaf_) + 1
page_starts % records_in_leaf_ == 0 && page_ends % records_in_leaf_ == 0

Using the additional outputs, the caller can avoid re-calculating route if the offset is within page_starts and page_ends. This is currently used in ArrayComposer.

Definition at line 154 of file array_route.hpp.

References ASSERT_ND, foedus::assorted::ConstDiv::div64(), foedus::storage::array::kInteriorFanout, foedus::storage::array::LookupRoute::route, and foedus::storage::array::LookupRoute::word.

157  {
158  LookupRoute ret;
159  ret.word = 0;
160  ArrayOffset old = offset;
161  offset = leaf_fanout_div_.div64(offset);
162  *page_starts = offset * records_in_leaf_;
163  *page_ends = *page_starts + records_in_leaf_;
164  ret.route[0] = old - (*page_starts);
165  for (uint8_t level = 1; level < levels_ - 1; ++level) {
166  old = offset;
167  offset = interior_fanout_div_.div64(offset);
168  ret.route[level] = old - offset * kInteriorFanout;
169  }
170  if (levels_ > 1) {
171  // the last level is done manually because we don't need any division there
172  ASSERT_ND(offset < kInteriorFanout);
173  ret.route[levels_ - 1] = offset;
174  }
175 
176  return ret;
177 }
uint64_t ArrayOffset
The only key type in array storage.
Definition: array_id.hpp:48
const uint16_t kInteriorFanout
Max number of entries in an interior page of array storage.
Definition: array_id.hpp:110
#define ASSERT_ND(x)
A warning-free wrapper macro of assert() that has no performance effect in release mode even when 'x'...
Definition: assert_nd.hpp:72
uint64_t div64(uint64_t n) const
64-bit integer division that outputs both quotient and remainder.
Definition: const_div.hpp:241

Here is the call graph for this function:

uint8_t foedus::storage::array::LookupRouteFinder::get_levels ( ) const
inline

Definition at line 121 of file array_route.hpp.

121 { return levels_; }
uint16_t foedus::storage::array::LookupRouteFinder::get_records_in_leaf ( ) const
inline

The documentation for this class was generated from the following file: