libfoedus-core
FOEDUS Core Library
hash_hashinate.cpp
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  */
19 
20 #include <xxhash.h>
21 
22 #include <ostream>
23 #include <string>
24 
26 
27 namespace foedus {
28 namespace storage {
29 namespace hash {
30 
31 HashValue hashinate(const void *key, uint16_t key_length) {
32  return ::XXH64(key, key_length, kXxhashKeySeed);
33 }
34 
41 template <typename T>
43  return ::XXH64(&key, sizeof(T), kXxhashKeySeed);
44 }
45 
46 // @cond DOXYGEN_IGNORE
47 // explicit instantiation of primitive version of hashinate()
48 #define EXP_HASHINATE(x) template HashValue hashinate< x >(x key)
49 INSTANTIATE_ALL_NUMERIC_TYPES(EXP_HASHINATE);
50 // also 128bit types. we might use it...
51 template HashValue hashinate< __uint128_t >(__uint128_t key);
52 template HashValue hashinate< __int128_t >(__int128_t key);
53 // @endcond
54 
55 std::ostream& operator<<(std::ostream& o, const BloomFilterFingerprint& v) {
56  o << "<Fingerprint indexes=\"";
57  for (uint8_t i = 0; i < kHashDataPageBloomFilterHashes; ++i) {
58  o << v.indexes_[i] << ",";
59  }
60  o << "\" />";
61  return o;
62 }
63 
64 std::ostream& operator<<(std::ostream& o, const IntermediateRoute& v) {
65  o << "<Route>";
66  for (uint8_t i = 0; i < 8U; ++i) {
67  o << assorted::Hex(v.route[i], 2) << " ";
68  }
69  o << "</Route>";
70  return o;
71 }
72 
73 std::ostream& operator<<(std::ostream& o, const DataPageBloomFilter& v) {
74  o << "<DataPageBloomFilter>" << std::endl;
75  // one line for 8 bytes
76  for (uint16_t i = 0; i * 8U < kHashDataPageBloomFilterBytes; ++i) {
77  o << " <Bytes row=\"" << i << "\">";
78  for (uint16_t j = i * 8U; j < (i + 1U) * 8U && j < kHashDataPageBloomFilterBytes; ++j) {
79  o << assorted::Hex(v.values_[j], 2) << " ";
80  }
81  o << "</Bytes>" << std::endl;
82  }
83  o << "</DataPageBloomFilter>";
84  return o;
85 }
86 
87 } // namespace hash
88 } // namespace storage
89 } // namespace foedus
uint16_t indexes_[kHashDataPageBloomFilterHashes]
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
Definition: assert_nd.hpp:44
const uint64_t kXxhashKeySeed
Default seed value used for xxhash's xxh32/64 to hashinate keys.
const uint8_t kHashDataPageBloomFilterHashes
Number of hash functions (k) of bloom filter in each HashDataPage.
Compactly represents the route of intermediate pages to reach the given hash bin. ...
Independent utility methods/classes for hashination, or hash functions.
HashValue hashinate(const void *key, uint16_t key_length)
Calculates hash value for general input.
std::ostream & operator<<(std::ostream &o, const HashCombo &v)
Definition: hash_combo.cpp:37
const uint16_t kHashDataPageBloomFilterBytes
Byte size of bloom filter in each HashDataPage.
uint8_t route[8]
[0] means ordinal in level-0 intermediate page, [1] in its parent page, [2]...
uint8_t values_[kHashDataPageBloomFilterBytes]
A fingerprint for bloom filter in each HashDataPage.
Convenient way of writing hex integers to stream.
To quickly check whether a HashDataPage might contain a specific hash value, we maintain a non-counti...
#define INSTANTIATE_ALL_NUMERIC_TYPES(M)
INSTANTIATE_ALL_TYPES minus std::string.
uint64_t HashValue
Represents a full 64-bit hash value calculated from a key.
Definition: hash_id.hpp:129