18 #ifndef FOEDUS_STORAGE_MASSTREE_MASSTREE_ID_HPP_
19 #define FOEDUS_STORAGE_MASSTREE_MASSTREE_ID_HPP_
164 / (kBorderPageSlotSize +
sizeof(KeySlice));
172 - kCommonPageHeaderSize
173 - kBorderPageAdditionalHeaderSize
178 = kCommonPageHeaderSize
195 if (std::numeric_limits<T>::is_signed) {
196 return static_cast<uint64_t
>(value) - (1ULL << 63);
198 return static_cast<uint64_t
>(value);
209 if (std::numeric_limits<T>::is_signed) {
210 return static_cast<T
>(value - (1ULL << 63));
212 return static_cast<T
>(value);
224 return assorted::read_bigendian<uint64_t>(be_bytes);
236 std::memcpy(&tmp, be_bytes, 8);
237 return assorted::read_bigendian<uint64_t>(&tmp);
252 std::memcpy(&tmp, be_bytes, length);
253 return assorted::read_bigendian<uint64_t>(&tmp);
263 inline KeySlice
slice_key(
const void* be_bytes, KeyLength slice_length) {
264 if (slice_length >=
sizeof(KeySlice)) {
279 inline KeySlice
slice_layer(
const void* be_bytes, KeyLength key_length, Layer current_layer) {
280 const KeyLength skipped = current_layer *
sizeof(
KeySlice);
281 const KeyLength remainder_length = key_length - skipped;
282 const char* casted =
reinterpret_cast<const char*
>(be_bytes);
283 if (remainder_length >=
sizeof(KeySlice)) {
299 const uint64_t* left_casted =
reinterpret_cast<const uint64_t*
>(
ASSUME_ALIGNED(left, 8));
300 const uint64_t* right_casted =
reinterpret_cast<const uint64_t*
>(
ASSUME_ALIGNED(right, 8));
301 for (uint16_t slices = 0; slices < max_slices; ++slices) {
302 if (left_casted[slices] != right_casted[slices]) {
315 uintptr_t int_address =
reinterpret_cast<uintptr_t
>(key);
316 if (int_address % 8 != 0) {
319 if (key_length % 8 != 0) {
320 uint16_t paddings = 8 - (key_length % 8);
321 for (uint16_t i = 0; i < paddings; ++i) {
322 if (key[key_length + i] != 0) {
333 #endif // FOEDUS_STORAGE_MASSTREE_MASSTREE_ID_HPP_
const KeySlice kInfimumSlice
const uint32_t kCommonPageHeaderSize
Size of the base page class (MasstreePage), which is the common header for intermediate and border pa...
const uint64_t kSliceLen
Shorthand for sizeof(KeySlice).
uint16_t PayloadLength
Represents a byte-length of a payload in this package.
Definitions of IDs in this package and a few related constant values.
uint16_t SlotIndex
Index of a record in a (border) page.
const KeyLength kMaxKeyLength
Max length of a key.
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
const uint32_t kBorderPageSlotSize
Byte size of one slot in MasstreeBorderPage excluding slice information.
uint16_t DataOffset
Byte-offset in a page.
const Layer kMaxLayer
Maximum value for Layer.
const DataOffset kBorderPageDataPartOffset
Offset of data_ member in MasstreeBorderPage.
uint64_t KeySlice
Each key slice is an 8-byte integer.
uint16_t KeyLength
Represents a byte-length of a key in this package.
#define ASSUME_ALIGNED(x, y)
Wraps GCC's __builtin_assume_aligned.
A few macros and helper methods related to byte endian-ness.
KeySlice normalize_be_bytes_full(const void *be_bytes)
Convert a big-endian byte array of at least 8-bytes-length to KeySlice.
const InLayerLevel kMaxSaneInLayerLevel
If InLayerLevel exceeds this value, there must be something wrong.
KeySlice slice_key(const void *be_bytes, KeyLength slice_length)
Extract a part of a big-endian byte array of given length as KeySlice.
uint8_t Layer
Represents the depth of a B-trie layer.
const KeyLength kInitiallyNextLayer
A special key length value that denotes the record in a border page was initially a next-layer pointe...
KeySlice normalize_primitive(T value)
Order-preserving normalization for primitive key types.
const SlotIndex kBorderPageMaxSlots
Maximum number of slots in one MasstreeBorderPage.
const uint32_t kBorderPageDataPartSize
Byte size of the record data part (data_) in MasstreeBorderPage.
const uint32_t kBorderPageAdditionalHeaderSize
Misc header attributes specific to MasstreeBorderPage placed after the common header.
const PayloadLength kMaxPayloadLength
Max length of a payload.
uint8_t InLayerLevel
Represents the depth of a B-tree node in a B-trie layer.
bool is_key_aligned_and_zero_padded(const char *key, KeyLength key_length)
Returns if the given key is 8-bytes aligned and also zero-padded to 8-bytes for easier slicing (which...
KeySlice normalize_be_bytes_fragment(const void *be_bytes, uint32_t length)
Convert a big-endian byte array of given length to KeySlice.
T denormalize_primitive(KeySlice value)
Opposite of normalize_primitive().
const KeySlice kSupremumSlice
uint16_t count_common_slices(const void *left, const void *right, uint16_t max_slices)
Returns the number of 8-byte slices that the two strings share as prefix.
KeySlice slice_layer(const void *be_bytes, KeyLength key_length, Layer current_layer)
Extract a part of a big-endian byte array of given length as KeySlice.
const uint16_t kPageSize
A constant defining the page size (in bytes) of both snapshot pages and volatile pages.
KeySlice normalize_be_bytes_full_aligned(const void *be_bytes)
Convert an aligned big-endian byte array of at least 8-bytes-length to KeySlice.