cds  2.3.2
cds::container::feldman_hashmap::make_traits< Options > Struct Template Reference

Metafunction converting option list to feldman_hashmap::traits. More...

#include <cds/container/details/feldman_hashmap_base.h>

Public Types

typedef implementation_defined type
 Metafunction result.
 

Detailed Description

template<typename... Options>
struct cds::container::feldman_hashmap::make_traits< Options >

Metafunction converting option list to feldman_hashmap::traits.

Supported Options are:

If you use a fixed-sized key you can use it directly instead of a hash. In such case traits::hash should be specified as opt::none. However, if you want to use the hash values or if your key type is not fixed-sized you must specify a proper hash functor in your traits. For example: fixed-sized key - IP4 address map

// Key - IP address
struct ip4_address {
uint8_t ip[4];
};
// IP compare
struct ip4_cmp {
int operator()( ip4_address const& lhs, ip4_address const& rhs ) const
{
return memcmp( &lhs, &rhs, sizeof(lhs));
}
};
// Value - statistics for the IP address
struct statistics {
// ...
};
// Traits
// Key type (ip4_addr) is fixed-sized so we may use the map without any hash functor
struct ip4_map_traits: public cds::container::multilevl_hashmap::traits
{
typedef ip4_cmp compare;
};
// IP4 address - statistics map

variable-size key requires a hash functor: URL map

// Value - statistics for the URL
struct statistics {
// ...
};
// Traits
// Key type (std::string) is variable-sized so we must provide a hash functor in our traits
// We do not specify any comparing predicate (less or compare) so <tt> std::less<std::string> </tt> will be used by default
struct url_map_traits: public cds::container::multilevl_hashmap::traits
{
typedef std::hash<std::string> hash;
};
// URL statistics map
  • feldman_hashmap::hash_size - the size of hash value in bytes. By default, the size of hash value is sizeof( hash_type ) where hash_type is type of hash() result or sizeof( key ) if you use fixed-sized key.

Sometimes that size is wrong, for example, for that 6-byte key:

struct key_type {
uint32_t key;
uint16_t subkey;
};
static_assert( sizeof( key_type ) == 6, "Key type size mismatch" );

Here sizeof( key_type ) == 8 so static_assert will be thrown.

For that case you can specify hash_size explicitly.

Value 0 means auto-calculated sizeof( key_type ).

Default is atomicity::item_counter. To avoid false sharing you can aldo use atomicity::cache_friendly_item_counter


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

cds 2.3.2 Developed by Maxim Khizhinsky aka khizmax and other contributors 2007 - 2017
Autogenerated Sun Dec 31 2017 12:10:32 by Doxygen 1.8.13