Click
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
HashContainerMP< K, V, Item, MT > Class Template Reference

Intrusive hash table template, MT safe version. More...

#include <hashtablemp.hh>

Public Types

enum  { max_bucket_count = 4194303 , initial_bucket_count = 63 }
 
typedef Item::ptr ptr
 
typedef Item::write_ptr write_ptr
 
typedef uint32_t size_type
 

Public Member Functions

 HashContainerMP ()
 Construct an empty HashContainer.
 
 HashContainerMP (size_type n)
 Construct an empty HashContainer with at least n buckets.
 
 ~HashContainerMP ()
 Destroy the HashContainer.
 
size_type size ()
 Return the number of elements stored.
 
size_type buckets ()
 Return the number of buckets.
 
bool empty ()
 Return true iff size() == 0.
 
bool unbalanced ()
 Return true if this HashContainer should be rebalanced.
 
iterator begin ()
 
write_iterator write_begin ()
 
bool contains (const K &key)
 Test if an element with key key exists in the table.
 
ptr find (const K &key)
 Return a read pointer for the element with key, if any.
 
write_ptr find_write (const K &key)
 Return a write pointer for the element with key, if any.
 
bool find_clean (const K &key, std::function< void(V &storage)> store, std::function< bool(V &storage)> shouldremove)
 Find a key K and call store if found. Calls clean on colliding entries upon the way.
 
bool find_erase (const K &key, V &storage)
 Copy the value of V for K in storage if K is found, delete it from the table and return true. If nonfound, nothing is deleted and returns false.
 
bool find_erase_clean (const K &key, std::function< void(V &storage)> store, std::function< bool(V &storage)> shouldremove)
 Find a key, and call store if found before removing it. Calls clean on colliding entries upon the way.
 
ptr find_insert (const K &key, const V &value)
 
write_ptr find_insert_write (const K &key, const V &value)
 
ptr find_create (const K &key, std::function< V(void)> on_create)
 
void insert (const K &key, const V &value, std::function< void(V &value)> on_replace=[](V &){})
 Insert a key. Replace an item if it already exists, insert it if not. Gives the ability to do something (eg free resources) with the previous element. Does not look at use count for you and done under read lock ! The difference with find_insert, is that find_insert will not change the value if the value already existsn while here on_replace() will be called, and then the value will be replaced. on_replace() is NOT called if the value does not exists. This function was called set() before.
 
void insert_clean (const K &key, const V &value, std::function< bool(V &storage)> shouldremove)
 
void erase (const K &key)
 
void clear ()
 
void rehash (size_type n)
 
bool alone (bool atomic=false)
 
uint32_t refcnt ()
 
void disable_mt ()
 
bool mt ()
 
void resize_clear (uint32_t n)
 

Static Public Member Functions

static ListItem *& hashnext (ListItem *e)
 
static const K & hashkey (const ListItem *e)
 
static bool hashkeyeq (const K &a, const K &b)
 

Public Attributes

pool_allocator_mt< ListItem, false, 2048 > _allocator
 

Protected Member Functions

void initialize (size_type n)
 
void deinitialize ()
 
 HashContainerMP (const HashContainerMP< K, V, Item, MT > &)
 
HashContainerMP< K, V, Item, MT > & operator= (const HashContainerMP< K, V, Item, MT > &)
 
size_type bucket (const K &key)
 
void erase_item (ListItem *item)
 
ListItem * allocate (const ListItem &li)
 
void release_pending (bool force=false)
 
template<bool do_remove>
bool _find_clean (const K &key, std::function< void(V &storage)> store, std::function< bool(V &storage)> shouldremove, std::function< void(ListItem *&head)> on_missing=[](ListItem *&head){})
 

Protected Attributes

MT _mt
 
__rwlock< Table > _table
 
per_thread< ListItem * > _pending_release
 

Detailed Description

template<typename K, typename V, typename Item, typename MT = MT_T>
class HashContainerMP< K, V, Item, MT >

Intrusive hash table template, MT safe version.

K is the type of the key V is the type of the value Item is the value type enclosed by a reference counting mechanism based on shared pointers like shared<V> or rw_shared<V>, depending on the level of protection you want.

For convenience HashTableMP is an alias for HashContainerMP<K,V,shared<V>>

Constructor & Destructor Documentation

◆ HashContainerMP() [1/2]

template<typename K , typename V , typename Item , typename MT = MT_T>
HashContainerMP< K, V, Item, MT >::HashContainerMP ( )

Construct an empty HashContainer.

◆ HashContainerMP() [2/2]

template<typename K , typename V , typename Item , typename MT = MT_T>
HashContainerMP< K, V, Item, MT >::HashContainerMP ( size_type  n)
explicit

Construct an empty HashContainer with at least n buckets.

◆ ~HashContainerMP()

template<typename K , typename V , typename Item , typename MT = MT_T>
HashContainerMP< K, V, Item, MT >::~HashContainerMP ( )

Destroy the HashContainer.

Member Function Documentation

◆ size()

template<typename K , typename V , typename Item , typename MT = MT_T>
size_type HashContainerMP< K, V, Item, MT >::size ( )
inline

Return the number of elements stored.

◆ buckets()

template<typename K , typename V , typename Item , typename MT = MT_T>
size_type HashContainerMP< K, V, Item, MT >::buckets ( )
inline

Return the number of buckets.

◆ empty()

template<typename K , typename V , typename Item , typename MT = MT_T>
bool HashContainerMP< K, V, Item, MT >::empty ( )
inline

Return true iff size() == 0.

◆ unbalanced()

template<typename K , typename V , typename Item , typename MT = MT_T>
bool HashContainerMP< K, V, Item, MT >::unbalanced ( )
inline

Return true if this HashContainer should be rebalanced.

◆ contains()

template<typename K , typename V , typename Item , typename MT = MT_T>
bool HashContainerMP< K, V, Item, MT >::contains ( const K &  key)
inline

Test if an element with key key exists in the table.

◆ find()

template<typename K , typename V , typename Item , typename MT = MT_T>
ptr HashContainerMP< K, V, Item, MT >::find ( const K &  key)
inline

Return a read pointer for the element with key, if any.

◆ find_write()

template<typename K , typename V , typename Item , typename MT = MT_T>
write_ptr HashContainerMP< K, V, Item, MT >::find_write ( const K &  key)
inline

Return a write pointer for the element with key, if any.

◆ find_clean()

template<typename K , typename V , typename Item , typename MT = MT_T>
bool HashContainerMP< K, V, Item, MT >::find_clean ( const K &  key,
std::function< void(V &storage)>  store,
std::function< bool(V &storage)>  shouldremove 
)
inline

Find a key K and call store if found. Calls clean on colliding entries upon the way.

◆ find_erase()

template<typename K , typename V , typename Item , typename MT = MT_T>
bool HashContainerMP< K, V, Item, MT >::find_erase ( const K &  key,
V &  storage 
)
inline

Copy the value of V for K in storage if K is found, delete it from the table and return true. If nonfound, nothing is deleted and returns false.

◆ find_erase_clean()

template<typename K , typename V , typename Item , typename MT = MT_T>
bool HashContainerMP< K, V, Item, MT >::find_erase_clean ( const K &  key,
std::function< void(V &storage)>  store,
std::function< bool(V &storage)>  shouldremove 
)
inline

Find a key, and call store if found before removing it. Calls clean on colliding entries upon the way.

◆ insert()

template<typename K , typename V , typename Item , typename MT = MT_T>
void HashContainerMP< K, V, Item, MT >::insert ( const K &  key,
const V &  value,
std::function< void(V &value)>  on_replace = [](V &){} 
)
inline

Insert a key. Replace an item if it already exists, insert it if not. Gives the ability to do something (eg free resources) with the previous element. Does not look at use count for you and done under read lock ! The difference with find_insert, is that find_insert will not change the value if the value already existsn while here on_replace() will be called, and then the value will be replaced. on_replace() is NOT called if the value does not exists. This function was called set() before.


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