libfoedus-core
FOEDUS Core Library
foedus::storage::hash::HashMetadata Struct Referencefinal

Metadata of an hash storage. More...

Detailed Description

Metadata of an hash storage.

Definition at line 40 of file hash_metadata.hpp.

#include <hash_metadata.hpp>

Inheritance diagram for foedus::storage::hash::HashMetadata:
Collaboration diagram for foedus::storage::hash::HashMetadata:

Public Member Functions

 HashMetadata ()
 
 HashMetadata (StorageId id, const StorageName &name, uint8_t bin_bits)
 
 HashMetadata (const StorageName &name, uint8_t bin_bits=kHashMinBinBits)
 This one is for newly creating a storage. More...
 
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_. More...
 
uint64_t get_bin_count () const
 Number of bins in this hash storage. More...
 
uint8_t get_bin_shifts () const
 
HashBin extract_bin (HashValue hash) const
 
std::string describe () const
 

Public Attributes

uint8_t bin_bits_
 Number of bins in exponent of two. More...
 
uint8_t pad1_
 
uint16_t pad2_
 
uint32_t pad3_
 

Friends

std::ostream & operator<< (std::ostream &o, const HashMetadata &v)
 

Additional Inherited Members

Constructor & Destructor Documentation

foedus::storage::hash::HashMetadata::HashMetadata ( )
inline

Definition at line 41 of file hash_metadata.hpp.

uint8_t bin_bits_
Number of bins in exponent of two.
const uint8_t kHashMinBinBits
Minimum number allowed for bin-bits.
Definition: hash_id.hpp:150
foedus::storage::hash::HashMetadata::HashMetadata ( StorageId  id,
const StorageName name,
uint8_t  bin_bits 
)
inline

Definition at line 43 of file hash_metadata.hpp.

foedus::storage::hash::HashMetadata::HashMetadata ( const StorageName name,
uint8_t  bin_bits = kHashMinBinBits 
)
inline

This one is for newly creating a storage.

Definition at line 47 of file hash_metadata.hpp.

Member Function Documentation

std::string foedus::storage::hash::HashMetadata::describe ( ) const

Definition at line 29 of file hash_metadata.cpp.

29  {
30  std::stringstream o;
31  o << HashMetadataSerializer(const_cast<HashMetadata*>(this));
32  return o.str();
33 }
HashBin foedus::storage::hash::HashMetadata::extract_bin ( HashValue  hash) const
inline

Definition at line 65 of file hash_metadata.hpp.

References get_bin_shifts().

65 { return hash >> get_bin_shifts(); }

Here is the call graph for this function:

uint64_t foedus::storage::hash::HashMetadata::get_bin_count ( ) const
inline

Number of bins in this hash storage.

Always power of two.

Definition at line 62 of file hash_metadata.hpp.

References bin_bits_.

Referenced by foedus::storage::hash::HashStoragePimpl::create(), and foedus::storage::hash::HashStoragePimpl::get_bin_count().

62 { return 1ULL << bin_bits_; }
uint8_t bin_bits_
Number of bins in exponent of two.

Here is the caller graph for this function:

uint8_t foedus::storage::hash::HashMetadata::get_bin_shifts ( ) const
inline
Returns
how many bits we should shift down to extract bins from hashes

Definition at line 64 of file hash_metadata.hpp.

References bin_bits_.

Referenced by extract_bin(), foedus::storage::hash::HashStoragePimpl::get_bin_shifts(), and foedus::storage::hash::HashCombo::HashCombo().

64 { return 64U - bin_bits_; }
uint8_t bin_bits_
Number of bins in exponent of two.

Here is the caller graph for this function:

void foedus::storage::hash::HashMetadata::set_capacity ( uint64_t  expected_records,
double  preferred_records_per_bin = 5.0 
)

Use this method to set an appropriate value for bin_bits_.

Parameters
[in]expected_recordshow many records do you expect to store in this storage
[in]preferred_records_per_binaverage records per a hash bin. 5-30 are recommended. If this number is too large, many bins have a linked-list rather than just one page.

Definition at line 51 of file hash_metadata.cpp.

References ASSERT_ND, bin_bits_, foedus::storage::hash::kHashMaxBinBits, and foedus::storage::hash::kHashMinBinBits.

51  {
52  if (expected_records == 0) {
53  expected_records = 1;
54  }
55  if (preferred_records_per_bin < 1) {
56  preferred_records_per_bin = 1;
57  }
58  uint64_t bin_count = expected_records / preferred_records_per_bin;
59  uint8_t bits;
60  for (bits = 0; bits < kHashMaxBinBits && ((1ULL << bits) < bin_count); ++bits) {
61  continue;
62  }
63  if (bits < kHashMinBinBits) {
64  bits = kHashMinBinBits;
65  }
66  bin_bits_ = bits;
69 }
uint8_t bin_bits_
Number of bins in exponent of two.
const uint8_t kHashMinBinBits
Minimum number allowed for bin-bits.
Definition: hash_id.hpp:150
const uint8_t kHashMaxBinBits
Maximum number allowed for bin-bits.
Definition: hash_id.hpp:159
#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

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  o,
const HashMetadata v 
)
friend

Definition at line 34 of file hash_metadata.cpp.

34  {
35  o << HashMetadataSerializer(const_cast<HashMetadata*>(&v));
36  return o;
37 }

Member Data Documentation

uint8_t foedus::storage::hash::HashMetadata::bin_bits_

Number of bins in exponent of two.

Recommended to use set_capacity() to set this value.

Invariant
kHashMinBinBits <= bin_bits_ <= kHashMaxBinBits

Definition at line 75 of file hash_metadata.hpp.

Referenced by foedus::storage::hash::HashStoragePimpl::get_bin_bits(), get_bin_count(), get_bin_shifts(), foedus::storage::hash::HashMetadataSerializer::load(), foedus::storage::hash::operator<<(), foedus::storage::hash::HashMetadataSerializer::save(), and set_capacity().

uint8_t foedus::storage::hash::HashMetadata::pad1_

Definition at line 78 of file hash_metadata.hpp.

uint16_t foedus::storage::hash::HashMetadata::pad2_

Definition at line 79 of file hash_metadata.hpp.

uint32_t foedus::storage::hash::HashMetadata::pad3_

Definition at line 80 of file hash_metadata.hpp.


The documentation for this struct was generated from the following files: