RLib  5.7
RLib - an opensource, lightweight and multi-platform framework for cpp programming
System::Collections::Generic::HashMap< K, V, hasher, allocator, kdisposer, vdisposer > Class Template Reference

Represents a collection of key/value pairs that are organized based on the hash code of the key More...

Classes

struct  BUCKET
 
struct  ENTRY
 
class  ENTRY_REF
 

Public Types

typedef hasher::Type H
 

Public Member Functions

 HashMap (long initialCapacity=RLIB_DEFAULT_CAPACITY, float loadFactor=0.75f)
 Constructs an empty HashMap with the specified initial capacity and the default load factor (0.75) More...
 
 HashMap (const HashMap &hashmap)
 
HashMapoperator= (const HashMap &hashmap)
 
ENTRY_REFAdd (const K &key, const V &val, bool update=true)
 
ENTRY_REFAddEntry (const K &key, const V &val, bool update=true)
 Associates the specified value with the specified key. If the container previously contained a mapping for the key and update == true, the old value is replaced. More...
 
template<class... P>
RLIB_INLINE ENTRY_REFAddInPlace (const K &key, P &&..._args)
 
template<class... P>
ENTRY_REFEmplace (const K &key, P &&..._args)
 Associates the specified value with the specified key. If the container previously contained a mapping for the key, the old value is replaced. More...
 
ENTRY_REFGetEntry (const K &key) const
 Returns the entry pointer to which the specified key is mapped, or nullptr if there is no mapping for the key. More...
 
bool Remove (const K &key)
 Removes the mapping for the specified key if present. More...
 
void RemoveEntry (ENTRY *lpentry)
 Removes the specified entry. More...
 
void Clear ()
 Removes all entries More...
 
bool ContainsKey (const K &key) const
 Returns true if this container contains a mapping for the specified key. More...
 
ENTRY_REFoperator[] (const K &key)
 
const ENTRY_REFoperator[] (const K &key) const
 
ENTRY_REFbegin ()
 Returns an iterator to the first element of the container. If the container is empty or nothing, the returned iterator will be equal to end() More...
 
const ENTRY_REFbegin () const
 
ENTRY_REFend ()
 Returns an iterator to the element following the last element of the container. This element acts as a placeholder; attempting to access it results in undefined behavior. More...
 
const ENTRY_REFend () const
 
template<typename T >
void forEach (bool(*callback)(ENTRY_REF &, long, T), T lpuserdata)
 Performs the given action for each entry in this map until all entries have been processed or the action return false. More...
 
void forEach (bool(*callback)(ENTRY_REF &, long))
 Performs the given action for each entry in this map until all entries have been processed or the action return false. More...
 

Public Attributes

long Capacity
 
long Length
 
 RLIB_DECLARE_DYNCREATE
 

Protected Types

enum  BUCKET_STATE : long { BUCKET_FREE = 0, BUCKET_BASE = 1 }
 
enum  ENTRY_STATE : long { ENTRY_FREE = -1, ENTRY_USED, ENTRY_INTERNAL_INIT }
 
enum  ENTRY_INDEX : long { ENTRY_LAST = -1, ENTRY_BASE = 0 }
 

Protected Member Functions

long indexFor (const H &h) const
 
long indexForKey (const K &key) const
 
void moveEntry (ENTRY *lpsrc, ENTRY *lpdst)
 
void rehash (BUCKET *lpbuckets, long bk_count, ENTRY *lpentries)
 
void resize ()
 
ENTRY_INDEX allocEntry ()
 
ENTRYaddEntry (const K &key, const H &hash, _Out_ bool &isnew)
 
ENTRYaddEntry (const K &key)
 

Protected Attributes

ENTRYm_entries
 
BUCKETm_buckets
 
long m_index
 
long m_bk_count
 

Detailed Description

template<typename K, typename V, class hasher = IHash<K, __int64>, class allocator = IO::IAllocator, typename kdisposer = IDisposable<K>, typename vdisposer = IDisposable<V>>
class System::Collections::Generic::HashMap< K, V, hasher, allocator, kdisposer, vdisposer >

Represents a collection of key/value pairs that are organized based on the hash code of the key

Constructor & Destructor Documentation

template<typename K, typename V, class hasher = IHash<K, __int64>, class allocator = IO::IAllocator, typename kdisposer = IDisposable<K>, typename vdisposer = IDisposable<V>>
System::Collections::Generic::HashMap< K, V, hasher, allocator, kdisposer, vdisposer >::HashMap ( long  initialCapacity = RLIB_DEFAULT_CAPACITY,
float  loadFactor = 0.75f 
)
inline

Constructs an empty HashMap with the specified initial capacity and the default load factor (0.75)

Member Function Documentation

template<typename K, typename V, class hasher = IHash<K, __int64>, class allocator = IO::IAllocator, typename kdisposer = IDisposable<K>, typename vdisposer = IDisposable<V>>
ENTRY_REF* System::Collections::Generic::HashMap< K, V, hasher, allocator, kdisposer, vdisposer >::Add ( const K &  key,
const V &  val,
bool  update = true 
)
inline

See also
AddEntry
template<typename K, typename V, class hasher = IHash<K, __int64>, class allocator = IO::IAllocator, typename kdisposer = IDisposable<K>, typename vdisposer = IDisposable<V>>
ENTRY_REF* System::Collections::Generic::HashMap< K, V, hasher, allocator, kdisposer, vdisposer >::AddEntry ( const K &  key,
const V &  val,
bool  update = true 
)
inline

Associates the specified value with the specified key. If the container previously contained a mapping for the key and update == true, the old value is replaced.

template<typename K, typename V, class hasher = IHash<K, __int64>, class allocator = IO::IAllocator, typename kdisposer = IDisposable<K>, typename vdisposer = IDisposable<V>>
template<class... P>
RLIB_INLINE ENTRY_REF* System::Collections::Generic::HashMap< K, V, hasher, allocator, kdisposer, vdisposer >::AddInPlace ( const K &  key,
P &&...  _args 
)
inline

See also
Emplace
template<typename K, typename V, class hasher = IHash<K, __int64>, class allocator = IO::IAllocator, typename kdisposer = IDisposable<K>, typename vdisposer = IDisposable<V>>
ENTRY_REF* System::Collections::Generic::HashMap< K, V, hasher, allocator, kdisposer, vdisposer >::begin ( )
inline

Returns an iterator to the first element of the container. If the container is empty or nothing, the returned iterator will be equal to end()

template<typename K, typename V, class hasher = IHash<K, __int64>, class allocator = IO::IAllocator, typename kdisposer = IDisposable<K>, typename vdisposer = IDisposable<V>>
void System::Collections::Generic::HashMap< K, V, hasher, allocator, kdisposer, vdisposer >::Clear ( )
inline

Removes all entries

template<typename K, typename V, class hasher = IHash<K, __int64>, class allocator = IO::IAllocator, typename kdisposer = IDisposable<K>, typename vdisposer = IDisposable<V>>
bool System::Collections::Generic::HashMap< K, V, hasher, allocator, kdisposer, vdisposer >::ContainsKey ( const K &  key) const
inline

Returns true if this container contains a mapping for the specified key.

template<typename K, typename V, class hasher = IHash<K, __int64>, class allocator = IO::IAllocator, typename kdisposer = IDisposable<K>, typename vdisposer = IDisposable<V>>
template<class... P>
ENTRY_REF* System::Collections::Generic::HashMap< K, V, hasher, allocator, kdisposer, vdisposer >::Emplace ( const K &  key,
P &&...  _args 
)
inline

Associates the specified value with the specified key. If the container previously contained a mapping for the key, the old value is replaced.

template<typename K, typename V, class hasher = IHash<K, __int64>, class allocator = IO::IAllocator, typename kdisposer = IDisposable<K>, typename vdisposer = IDisposable<V>>
ENTRY_REF* System::Collections::Generic::HashMap< K, V, hasher, allocator, kdisposer, vdisposer >::end ( )
inline

Returns an iterator to the element following the last element of the container. This element acts as a placeholder; attempting to access it results in undefined behavior.

template<typename K, typename V, class hasher = IHash<K, __int64>, class allocator = IO::IAllocator, typename kdisposer = IDisposable<K>, typename vdisposer = IDisposable<V>>
template<typename T >
void System::Collections::Generic::HashMap< K, V, hasher, allocator, kdisposer, vdisposer >::forEach ( bool(*)(ENTRY_REF &, long, T)  callback,
lpuserdata 
)
inline

Performs the given action for each entry in this map until all entries have been processed or the action return false.

template<typename K, typename V, class hasher = IHash<K, __int64>, class allocator = IO::IAllocator, typename kdisposer = IDisposable<K>, typename vdisposer = IDisposable<V>>
void System::Collections::Generic::HashMap< K, V, hasher, allocator, kdisposer, vdisposer >::forEach ( bool(*)(ENTRY_REF &, long)  callback)
inline

Performs the given action for each entry in this map until all entries have been processed or the action return false.

template<typename K, typename V, class hasher = IHash<K, __int64>, class allocator = IO::IAllocator, typename kdisposer = IDisposable<K>, typename vdisposer = IDisposable<V>>
ENTRY_REF* System::Collections::Generic::HashMap< K, V, hasher, allocator, kdisposer, vdisposer >::GetEntry ( const K &  key) const
inline

Returns the entry pointer to which the specified key is mapped, or nullptr if there is no mapping for the key.

template<typename K, typename V, class hasher = IHash<K, __int64>, class allocator = IO::IAllocator, typename kdisposer = IDisposable<K>, typename vdisposer = IDisposable<V>>
bool System::Collections::Generic::HashMap< K, V, hasher, allocator, kdisposer, vdisposer >::Remove ( const K &  key)
inline

Removes the mapping for the specified key if present.

template<typename K, typename V, class hasher = IHash<K, __int64>, class allocator = IO::IAllocator, typename kdisposer = IDisposable<K>, typename vdisposer = IDisposable<V>>
void System::Collections::Generic::HashMap< K, V, hasher, allocator, kdisposer, vdisposer >::RemoveEntry ( ENTRY lpentry)
inline

Removes the specified entry.


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