libfoedus-core
FOEDUS Core Library
hash_metadata.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_METADATA_HPP_
19 #define FOEDUS_STORAGE_HASH_HASH_METADATA_HPP_
20 #include <stdint.h>
21 
22 #include <iosfwd>
23 #include <string>
24 
25 #include "foedus/cxx11.hpp"
26 #include "foedus/error_stack.hpp"
32 
33 namespace foedus {
34 namespace storage {
35 namespace hash {
43  HashMetadata(StorageId id, const StorageName& name, uint8_t bin_bits)
44  : Metadata(id, kHashStorage, name), bin_bits_(bin_bits), pad1_(0), pad2_(0), pad3_(0) {
45  }
47  HashMetadata(const StorageName& name, uint8_t bin_bits = kHashMinBinBits)
48  : Metadata(0, kHashStorage, name), bin_bits_(bin_bits), pad1_(0), pad2_(0), pad3_(0) {
49  }
50 
57  void set_capacity(uint64_t expected_records, double preferred_records_per_bin = 5.0);
58 
62  uint64_t get_bin_count() const { return 1ULL << bin_bits_; }
64  uint8_t get_bin_shifts() const { return 64U - bin_bits_; }
65  HashBin extract_bin(HashValue hash) const { return hash >> get_bin_shifts(); }
66 
67  std::string describe() const;
68  friend std::ostream& operator<<(std::ostream& o, const HashMetadata& v);
69 
75  uint8_t bin_bits_;
76 
77  // just for valgrind when this metadata is written to file. ggr
78  uint8_t pad1_;
79  uint16_t pad2_;
80  uint32_t pad3_;
81 };
82 
86  : MetadataSerializer(data), data_casted_(data) {}
89 };
90 
91 } // namespace hash
92 } // namespace storage
93 } // namespace foedus
94 #endif // FOEDUS_STORAGE_HASH_HASH_METADATA_HPP_
Definitions of IDs in this package and a few related constant values.
uint32_t StorageId
Unique ID for storage.
Definition: storage_id.hpp:55
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
Definition: assert_nd.hpp:44
#define EXTERNALIZABLE(clazz)
Macro to declare/define essential methods for an externalizable class.
friend std::ostream & operator<<(std::ostream &o, const HashMetadata &v)
void set_capacity(uint64_t expected_records, double preferred_records_per_bin=5.0)
Use this method to set an appropriate value for bin_bits_.
uint8_t bin_bits_
Number of bins in exponent of two.
Metadata of one storage.
Definition: metadata.hpp:58
#define CXX11_FINAL
Used in public headers in place of "final" of C++11.
Definition: cxx11.hpp:131
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
Metadata of an hash storage.
uint64_t get_bin_count() const
Number of bins in this hash storage.
HashMetadata(const StorageName &name, uint8_t bin_bits=kHashMinBinBits)
This one is for newly creating a storage.
HashMetadata(StorageId id, const StorageName &name, uint8_t bin_bits)
Definitions of IDs in this package and a few related constant values.
Forward declarations of classes in hash storage package.
uint64_t HashValue
Represents a full 64-bit hash value calculated from a key.
Definition: hash_id.hpp:129
HashBin extract_bin(HashValue hash) const