Evo C++ Library v0.5.1
|
#include <evo/maphash.h>
Map implemented as a hash table.
TKey | Map key type |
TValue | Map value type |
THash | Hash type to use – default: CompareHash |
TSize | Size type to use for size values (must be unsigned integer) – default: SizeT |
unordered_map
, implemented with a hash tableC++11:
This type is used for both hashing and comparing keys. You can leave the default comparison/hash type (CompareHash) or specify an alternative.
Caution: Modifying or resizing a map will shift or invalidate existing iterators using it.
This example works with any Map type.
Example using a map of numbers
Output:
Note: Item ordering will vary
Public Types | |
typedef void | EvoContainerType |
typedef THash | Hash |
Hashing type – default: CompareHash. More... | |
typedef Pair< Key, Value > | Item |
Item type (key/value pair) More... | |
typedef IteratorBi< ThisType >::Const | Iter |
Iterator (const) - IteratorBi. More... | |
typedef IteratorBi< ThisType > | IterM |
Iterator (mutable) - IteratorBi. More... | |
typedef TKey | Key |
Key type. More... | |
using | KeyPass = typename DataCopy< TKey >::PassType |
Key type for passing through InitPair (C++11) More... | |
typedef Map< TKey, TValue, TSize > | MapBaseType |
Map base type More... | |
typedef TSize | Size |
Size type for size values (must be unsigned integer) – default: SizeT. More... | |
typedef MapHash< TKey, TValue, THash, TSize > | ThisType |
This type. More... | |
typedef TValue | Value |
Value type. More... | |
using | ValuePass = typename DataCopy< TValue >::PassType |
Value type for passing through InitPair (C++11) More... | |
Public Member Functions | |
MapHash () | |
Constructor. More... | |
MapHash (const MapBaseType &src) | |
Copy constructor. More... | |
MapHash (const ThisType &src) | |
Copy constructor. More... | |
MapHash (const std::initializer_list< InitPair > &init) | |
< Used with initializer_list constructor (C++11) More... | |
MapHash (ThisType &&src) | |
Move constructor (C++11). More... | |
virtual MapBaseType & | add (const MapBaseType &map, bool update=true)=0 |
Add items from given map. More... | |
Item & | add (const Key &key, const Value &value, bool update=true) |
Add or update using given key and value. More... | |
Item & | add (const Item &item, bool update=true) |
Add or update using given item. More... | |
ThisType & | add (const MapBaseType &map, bool update=true) |
template<class T > | |
Size | addsplit (const T &str, char delim=',', char kvdelim='=') |
Split delimited string into map key/value items. More... | |
const ThisType & | asconst () const |
Explicitly use a const reference to this. More... | |
IterM | begin () |
Get iterator at first item (mutable). More... | |
Iter | begin () const |
Get iterator at first item (const). More... | |
Size | capacity () const |
Get map capacity. More... | |
ThisType & | capacity (Size size) |
Set hash map size (capacity). More... | |
ThisType & | capacitymin (Size min) |
Set map capacity to at least given minimum. More... | |
Iter | cbegin () const |
Get iterator at first item (const). More... | |
Iter | cend () const |
Get iterator at end (const). More... | |
ThisType & | clear () |
Clear by removing all items. More... | |
virtual MapBaseType & | compact () |
Reduce capacity to fit current size (modifier). More... | |
bool | contains (const Key &key) const |
Get whether map contains the given key. More... | |
bool | empty () const |
Get whether map is empty (size is 0). More... | |
IterM | end () |
Get iterator at end. More... | |
Iter | end () const |
Get iterator at end (const). More... | |
const Value * | find (const Key &key) const |
Find (lookup) value for given key (const). More... | |
Value * | findM (const Key &key) |
Find (lookup) value for given key (mutable). More... | |
Value & | get (const Key &key, bool *created=NULL) |
Get item value for key (mutable). More... | |
Item & | getitem (const Key &key, bool *created=NULL) |
Get map item for key (mutable). More... | |
Iter | iter (const Key &key) const |
Find (lookup) iterator for given key (const). More... | |
IterM | iterM (const Key &key) |
Find (lookup) iterator for given key (mutable). More... | |
bool | null () const |
Get whether map is null. More... | |
bool | operator!= (const MapBaseType &map) const |
Inequality operator. More... | |
ThisType & | operator= (ThisType &&src) |
Move assignment operator (C++11). More... | |
ThisType & | operator= (const MapBaseType &src) |
Assignment operator. More... | |
ThisType & | operator= (const ThisType &src) |
Assignment operator. More... | |
bool | operator== (const MapBaseType &map) const |
Equality operator. More... | |
Value & | operator[] (const Key &key) |
Get item value for key (mutable). More... | |
bool | ordered () const |
Get whether map is ordered. More... | |
bool | remove (const Key &key) |
Find and remove item with given key. More... | |
bool | remove (typename MapBaseType::IterM &iter, IteratorDir dir=iterNONE) |
Remove item using given iterator. More... | |
bool | remove (IterM &iter, IteratorDir dir=iterNONE) |
Remove item using given iterator. More... | |
ThisType & | reserve (Size size) |
Reserve space for new items. More... | |
void | resize (Size size) |
Set hash map size (capacity) directly. More... | |
ThisType & | set () |
Set as null and empty. More... | |
ThisType & | set (const MapBaseType &src) |
ThisType & | set (const ThisType &src) |
Set as copy of given map. More... | |
ThisType & | setempty () |
Set as empty but not null. More... | |
bool | shared () const |
Get whether shared. More... | |
Size | size () const |
Get map size (number of items). More... | |
ThisType & | unshare () |
Make data unique by allocating new buffer, if needed (modifier). More... | |
Protected Member Functions | |
const Item * | getiter (IterKey &iterkey, const Key &key) const |
Used by base class to get data to initialize iterator. More... | |
Protected Attributes | |
bool | ordered_ |
Whether map is ordered (items are kept in order by key) More... | |
Size | size_ |
Map size (number of items, automatically updated by concrete set members) More... | |
typedef void EvoContainerType |
typedef THash Hash |
Hashing type – default: CompareHash.
typedef IteratorBi<ThisType>::Const Iter |
Iterator (const) - IteratorBi.
typedef IteratorBi<ThisType> IterM |
Iterator (mutable) - IteratorBi.
|
inherited |
Key type.
Key type for passing through InitPair (C++11)
|
inherited |
Map base type
|
inherited |
Size type for size values (must be unsigned integer) – default: SizeT.
|
inherited |
Value type.
Value type for passing through InitPair (C++11)
|
inline |
Constructor.
|
inline |
Copy constructor.
src | Source to copy |
< Used with initializer_list constructor (C++11)
Sequence constructor (C++11).
init | Initializer list, passed as comma-separated values in braces { } |
|
pure virtualinherited |
Add items from given map.
map | Map to add items from |
update | Whether to update value for existing items |
Implemented in MapList< TKey, TValue, TCompare, TSize >, MapList< String, CommandInfo >, MapList< SigNumType, Handler >, and MapList< String, OptionInfoShPtr >.
Add or update using given key and value.
key | Key to find/add (copied) |
value | Value to add/update (copied) |
update | Whether to update value for existing item |
Implements Map< TKey, TValue, TSize >.
Add or update using given item.
item | Item to use for add/update (copied) |
update | Whether to update value for existing item |
Implements Map< TKey, TValue, TSize >.
|
inline |
|
inlineinherited |
Split delimited string into map key/value items.
T | String type to parse – inferred from str parameter |
str | String to parse |
delim | Item delimiter to use |
kvdelim | Key/Value delimiter to use |
|
inline |
Explicitly use a const reference to this.
|
inline |
|
inline |
Get iterator at first item (const).
|
inlinevirtual |
Set hash map size (capacity).
size | New suggested capacity |
Implements Map< TKey, TValue, TSize >.
Set map capacity to at least given minimum.
min | Minimum capacity |
Implements Map< TKey, TValue, TSize >.
|
inline |
|
inline |
|
inlinevirtual |
Clear by removing all items.
Implements Map< TKey, TValue, TSize >.
|
inlinevirtualinherited |
Reduce capacity to fit current size (modifier).
Reimplemented in MapList< TKey, TValue, TCompare, TSize >, MapList< String, CommandInfo >, MapList< SigNumType, Handler >, and MapList< String, OptionInfoShPtr >.
|
inlinevirtual |
Get whether map contains the given key.
key | Key to look for |
Implements Map< TKey, TValue, TSize >.
|
inlineinherited |
Get whether map is empty (size is 0).
|
inline |
|
inline |
Get iterator at end (const).
Find (lookup) value for given key (const).
key | Key to find |
Implements Map< TKey, TValue, TSize >.
Find (lookup) value for given key (mutable).
key | Key to find |
Implements Map< TKey, TValue, TSize >.
Get item value for key (mutable).
key | Key to use |
created | Stores whether new item was created, if not NULL |
Get map item for key (mutable).
key | Key to use |
created | Stores whether new item was created, if not NULL |
Implements Map< TKey, TValue, TSize >.
Used by base class to get data to initialize iterator.
iterkey | Set to iterator data, if item found |
key | Key to find |
Implements Map< TKey, TValue, TSize >.
Find (lookup) iterator for given key (const).
key | Key to find |
Find (lookup) iterator for given key (mutable).
key | Key to find |
|
inlinevirtual |
|
inlineinherited |
Inequality operator.
map | Map to compre |
Move assignment operator (C++11).
src | Source to move |
|
inline |
Assignment operator.
src | Source to copy |
Assignment operator.
src | Source to copy |
|
inlineinherited |
Equality operator.
map | Map to compre |
Get item value for key (mutable).
key | Key to use |
|
inlineinherited |
Get whether map is ordered.
|
inlinevirtual |
Find and remove item with given key.
key | Key to use |
Implements Map< TKey, TValue, TSize >.
|
inlinevirtual |
Remove item using given iterator.
iter | Iterator position |
dir | Direction to move iterator to next item, iterNONE for end position |
Implements Map< TKey, TValue, TSize >.
|
inlinevirtual |
Remove item using given iterator.
iter | Iterator position |
dir | Direction to move iterator to next item, iterNONE for end position |
Implements Map< TKey, TValue, TSize >.
Reserve space for new items.
size | Size to reserve |
|
inline |
Set hash map size (capacity) directly.
size | New size/capacity, minimum size of 8 is used if lower |
|
inlinevirtual |
|
inline |
Set as copy of given map.
src | Source map |
Implements Map< TKey, TValue, TSize >.
|
inlinevirtual |
|
inlinevirtual |
Get whether shared.
Implements Map< TKey, TValue, TSize >.
|
inlinevirtual |
Make data unique by allocating new buffer, if needed (modifier).
Implements Map< TKey, TValue, TSize >.
|
protectedinherited |
Whether map is ordered (items are kept in order by key)
|
protectedinherited |
Map size (number of items, automatically updated by concrete set members)