![]() |
Gorgon Game Engine
|
This class is a reference based hashmap. More...
Classes | |
class | ConstIterator |
Const iterator allows iteration of const collections. More... | |
Public Types | |
typedef Iterator_< typename std::map< K_, T_ * >::iterator, Hashmap > | Iterator |
Regular iterator. More... | |
typedef K_ | KeyType |
typedef T_ | ValueType |
Public Member Functions | |
Hashmap () | |
Default constructor. More... | |
Hashmap (const Hashmap &)=delete | |
Copy constructor is disabled. More... | |
Hashmap (Hashmap &&other) | |
Move constructor. More... | |
Hashmap (std::initializer_list< std::pair< const K_, T_ & >> list) | |
Filling constructor. This constructor uses initializer list of std::pair<K_, T_&> More... | |
Hashmap (std::initializer_list< std::pair< const K_, T_ * >> list) | |
Filling constructor. More... | |
Hashmap (std::initializer_list< T_ * > list) | |
Filling constructor that takes the keys using KeyFn function. More... | |
void | Add (const K_ &key, T_ &obj, bool deleteprev=false) |
Adds the given item with the related key. More... | |
void | Add (const K_ &key, T_ *obj, bool deleteprev=false) |
Adds the given item with the related key. More... | |
void | Add (T_ &obj, bool deleteprev=false) |
Adds the given item by retrieving the related key. More... | |
void | Add (T_ *obj, bool deleteprev=false) |
Adds the given item by retrieving the related key. More... | |
void | Collapse () |
Clears the contents of the map and releases the memory used for the list. More... | |
void | Delete (const K_ &key) |
Removes the item with the given key from the mapping and deletes it. More... | |
void | DeleteAll () |
Deletes and removes all the elements of this map. More... | |
void | Destroy () |
Deletes and removes all the elements of this map, in addition to destroying data used. More... | |
Hashmap | Duplicate () const |
bool | Exists (const K_ &key) const |
Checks if an element with the given key exists. More... | |
Iterator | Find (const K_ &key) |
Finds the given key in the hashmap and returns iterator for it. More... | |
ConstIterator | Find (const K_ &key) const |
Finds the given key in the hashmap and returns iterator for it. More... | |
long | GetCount () const |
Returns the number of elements in the map. More... | |
long | GetSize () const |
Returns the number of elements in the map. More... | |
Hashmap & | operator= (const Hashmap &other)=delete |
Copy constructor is disabled. More... | |
Hashmap & | operator= (Hashmap &&other) |
Move constructor, does not delete elements. More... | |
T_ & | operator[] (const K_ &key) const |
If not found throws. More... | |
void | Remove (const K_ &key) |
Removes the item with the given key from the mapping. More... | |
void | RemoveAll () |
Removes all elements from this mapping without deleting them. More... | |
void | Swap (Hashmap &other) |
Swaps two hashmaps. More... | |
Iterator related | |
Iterator | begin () |
Iterator | end () |
end iterator More... | |
Iterator | First () |
returns the iterator to the first item More... | |
Iterator | Last () |
returns the iterator to the last item More... | |
ConstIterator | begin () const |
begin iterator More... | |
ConstIterator | end () const |
end iterator More... | |
ConstIterator | First () const |
returns the iterator to the first item More... | |
ConstIterator | Last () const |
returns the iterator to the last item More... | |
This class is a reference based hashmap.
It uses std::map as underlying mechanism and provides necessary services to manage a reference based container. Like other Gorgon containers, Hashmap also disallows copy construction to reduce expensive mistakes. If a copy of the container is required, Duplicate function can be used to create a copy. Hashmap uses move semantics and can be returned from functions by value even though copy construction is disabled. Last template parameter can be replaced by unsorted_map. Currently Hashmap does not allow the use of multi-maps.
Regular iterator.
typedef K_ KeyType |
typedef T_ ValueType |
Hashmap | ( | ) |
Default constructor.
Hashmap | ( | std::initializer_list< std::pair< const K_, T_ * >> | list | ) |
Filling constructor.
This constructor uses initializer list of std::pair<K_, T_*>. This function works faster by forwarding the lsit to underlying storage. However, it cannot deal with nullptr entries, thus can leave the container in undefined state. A test agains this case is performed for debug builds.
Hashmap | ( | std::initializer_list< std::pair< const K_, T_ & >> | list | ) |
Filling constructor. This constructor uses initializer list of std::pair<K_, T_&>
Hashmap | ( | std::initializer_list< T_ * > | list | ) |
Filling constructor that takes the keys using KeyFn function.
This constructor handles nullptr entries by ignoring them.
void Add | ( | const K_ & | key, |
T_ & | obj, | ||
bool | deleteprev = false |
||
) |
Adds the given item with the related key.
If the key already exists, the object it points to is changed. If deleteprev is set, previous object at the key is deleted.
void Add | ( | const K_ & | key, |
T_ * | obj, | ||
bool | deleteprev = false |
||
) |
Adds the given item with the related key.
If the key already exists, the object it points to is changed. If deleteprev is set, previous object at the key is deleted. If obj is nullptr and the key exists in the map, it is removed.
void Add | ( | T_ & | obj, |
bool | deleteprev = false |
||
) |
Adds the given item by retrieving the related key.
If the key already exists, the object it points to is changed. If deleteprev is set, previous object at the key is deleted.
void Add | ( | T_ * | obj, |
bool | deleteprev = false |
||
) |
Adds the given item by retrieving the related key.
If the key already exists, the object it points to is changed. If deleteprev is set, previous object at the key is deleted. If obj is nullptr and the key exists in the map, it is removed.
Iterator begin | ( | ) |
ConstIterator begin | ( | ) | const |
begin iterator
void Collapse | ( | ) |
Clears the contents of the map and releases the memory used for the list.
Items are not freed.
void Delete | ( | const K_ & | key | ) |
Removes the item with the given key from the mapping and deletes it.
If the item does not exists, this request is simply ignored
void DeleteAll | ( | ) |
Deletes and removes all the elements of this map.
void Destroy | ( | ) |
Deletes and removes all the elements of this map, in addition to destroying data used.
Hashmap Duplicate | ( | ) | const |
Iterator end | ( | ) |
end iterator
ConstIterator end | ( | ) | const |
end iterator
bool Exists | ( | const K_ & | key | ) | const |
Checks if an element with the given key exists.
Iterator Find | ( | const K_ & | key | ) |
Finds the given key in the hashmap and returns iterator for it.
An !IsValid() iterator is returned if item is not found
ConstIterator Find | ( | const K_ & | key | ) | const |
Finds the given key in the hashmap and returns iterator for it.
An !IsValid() iterator is returned if item is not found
Iterator First | ( | ) |
returns the iterator to the first item
ConstIterator First | ( | ) | const |
returns the iterator to the first item
long GetCount | ( | ) | const |
Returns the number of elements in the map.
long GetSize | ( | ) | const |
Returns the number of elements in the map.
Iterator Last | ( | ) |
returns the iterator to the last item
ConstIterator Last | ( | ) | const |
returns the iterator to the last item
Copy constructor is disabled.
Move constructor, does not delete elements.
T_& operator[] | ( | const K_ & | key | ) | const |
If not found throws.
void Remove | ( | const K_ & | key | ) |
Removes the item with the given key from the mapping.
If the item does not exists, this request is simply ignored. This function does not delete the item.
void RemoveAll | ( | ) |
Removes all elements from this mapping without deleting them.
Additonally, any memory that is being used by std::map is not freed.
void Swap | ( | Hashmap< K_, T_, KeyFn, M_, C_ > & | other | ) |
Swaps two hashmaps.