libfoedus-core
FOEDUS Core Library
hash_id.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2015, Hewlett-Packard Development Company, LP.
3  * This program is free software; you can redistribute it and/or modify it
4  * under the terms of the GNU General Public License as published by the Free
5  * Software Foundation; either version 2 of the License, or (at your option)
6  * any later version.
7  *
8  * This program is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11  * more details. You should have received a copy of the GNU General Public
12  * License along with this program; if not, write to the Free Software
13  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14  *
15  * HP designates this particular file as subject to the "Classpath" exception
16  * as provided by HP in the LICENSE.txt file that accompanied this code.
17  */
18 #ifndef FOEDUS_STORAGE_HASH_HASH_ID_HPP_
19 #define FOEDUS_STORAGE_HASH_HASH_ID_HPP_
20 #include <stdint.h>
21 
22 #include <iosfwd>
23 
24 #include "foedus/cxx11.hpp"
26 
32 namespace foedus {
33 namespace storage {
34 namespace hash {
35 
40 const uint16_t kHashIntermediatePageHeaderSize = 64;
41 
51 
56 inline uint64_t fanout_power(uint8_t exponent) {
57  uint64_t ret = 1U;
58  for (uint8_t i = 0; i < exponent; ++i) {
60  }
61  return ret;
62 }
63 
74 const uint64_t kHashMaxBins[] = {
75  1ULL,
76  kFanout64,
77  kFanout64 * kFanout64,
78  kFanout64 * kFanout64 * kFanout64,
79  kFanout64 * kFanout64 * kFanout64 * kFanout64,
80  kFanout64 * kFanout64 * kFanout64 * kFanout64 * kFanout64,
81  kFanout64 * kFanout64 * kFanout64 * kFanout64 * kFanout64 * kFanout64,
82  kFanout64 * kFanout64 * kFanout64 * kFanout64 * kFanout64 * kFanout64 * kFanout64,
83  kFanout64 * kFanout64 * kFanout64 * kFanout64 * kFanout64 * kFanout64 * kFanout64 * kFanout64,
84 };
85 
90 inline uint8_t bins_to_level(uint64_t bins) {
91  uint8_t level;
92  for (level = 1U; kHashMaxBins[level] < bins; ++level) {
93  continue;
94  }
95  return level;
96 }
97 
104 const uint8_t kHashMaxLevels = 8;
105 
110 const uint16_t kHashDataPageHeaderSize = 128;
111 
117 
129 typedef uint64_t HashValue;
130 
142 typedef uint64_t HashBin;
143 
150 const uint8_t kHashMinBinBits = 7U;
151 
159 const uint8_t kHashMaxBinBits = 48U;
160 
162 const HashBin kInvalidHashBin = 1ULL << kHashMaxBinBits;
163 
172 struct HashBinRange {
173  HashBinRange() : begin_(0), end_(0) {}
174  HashBinRange(HashBin begin, HashBin end) : begin_(begin), end_(end) {}
175 
176  bool contains(HashBin hash) const { return hash >= begin_ && hash < end_; }
177  bool contains(const HashBinRange& other) const {
178  return begin_ <= other.begin_ && end_ >= other.end_;
179  }
180  bool operator==(const HashBinRange& other) const {
181  return begin_ == other.begin_ && end_ == other.end_;
182  }
183  bool operator!=(const HashBinRange& other) const { return !(this->operator==(other)); }
184 
185  uint64_t length() const { return end_ - begin_; }
186 
188  friend std::ostream& operator<<(std::ostream& o, const HashBinRange& v);
189 
191  HashBin begin_;
193  HashBin end_;
194 };
195 
196 typedef uint16_t DataPageSlotIndex;
197 const DataPageSlotIndex kSlotNotFound = 0xFFFFU;
198 
203 typedef uint16_t KeyLength;
204 
209 typedef uint16_t PayloadLength;
210 
211 } // namespace hash
212 } // namespace storage
213 } // namespace foedus
214 #endif // FOEDUS_STORAGE_HASH_HASH_ID_HPP_
Represents a pointer to another page (usually a child page).
Definition: storage_id.hpp:271
Definitions of IDs in this package and a few related constant values.
bool contains(const HashBinRange &other) const
Definition: hash_id.hpp:177
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
Definition: assert_nd.hpp:44
const DataPageSlotIndex kSlotNotFound
Definition: hash_id.hpp:197
uint8_t bins_to_level(uint64_t bins)
Definition: hash_id.hpp:90
uint16_t PayloadLength
Represents a byte-length of a payload in this package.
Definition: hash_id.hpp:209
bool contains(HashBin hash) const
Definition: hash_id.hpp:176
const uint8_t kHashMaxLevels
Max level of intermediate pages.
Definition: hash_id.hpp:104
uint64_t fanout_power(uint8_t exponent)
Definition: hash_id.hpp:56
Represents a range of hash bins in a hash storage, such as what an intermediate page is responsible f...
Definition: hash_id.hpp:172
HashBin begin_
Inclusive beginning of the range.
Definition: hash_id.hpp:191
friend std::ostream & operator<<(std::ostream &o, const HashBinRange &v)
this one is NOT header-only.
Definition: hash_id.cpp:28
const uint16_t kHashIntermediatePageHeaderSize
Byte size of header in an intermediate page of hash storage.
Definition: hash_id.hpp:40
uint16_t DataPageSlotIndex
Definition: hash_id.hpp:196
HashBin end_
Exclusive end of the range.
Definition: hash_id.hpp:193
const uint8_t kHashMinBinBits
Minimum number allowed for bin-bits.
Definition: hash_id.hpp:150
uint64_t HashBin
Represents a bin of a hash value.
Definition: hash_id.hpp:142
bool operator==(const HashBinRange &other) const
Definition: hash_id.hpp:180
uint16_t KeyLength
Represents a byte-length of a key in this package.
Definition: hash_id.hpp:203
const uint16_t kHashDataPageHeaderSize
Byte size of header in data page of hash storage.
Definition: hash_id.hpp:110
const uint64_t kFanout64
just to write the following concisely
Definition: hash_id.hpp:65
const HashBin kInvalidHashBin
This value or larger never appears as a valid HashBin.
Definition: hash_id.hpp:162
const uint8_t kHashIntermediatePageFanout
Number of pointers in an intermediate page of hash storage.
Definition: hash_id.hpp:49
const uint64_t kHashMaxBins[]
kHashTotalBins[n] gives the maximum number of hash bins n-level hash can hold.
Definition: hash_id.hpp:74
bool operator!=(const HashBinRange &other) const
Definition: hash_id.hpp:183
const uint8_t kHashMaxBinBits
Maximum number allowed for bin-bits.
Definition: hash_id.hpp:159
HashBinRange(HashBin begin, HashBin end)
Definition: hash_id.hpp:174
const uint16_t kHashDataPageDataSize
Body data byte size in data page of hash storage.
Definition: hash_id.hpp:116
const uint16_t kPageSize
A constant defining the page size (in bytes) of both snapshot pages and volatile pages.
Definition: storage_id.hpp:45
uint64_t HashValue
Represents a full 64-bit hash value calculated from a key.
Definition: hash_id.hpp:129