Samchon Framework for CPP  1.0.0
samchon::HashMap< Key, T, Hash, Pred, Alloc > Class Template Reference

Customized std::unordered_map. More...

#include <HashMap.hpp>

Public Member Functions

auto has (const Key &key) const -> bool
 Whether have the item or not. More...
 
auto get (const Key &key) -> T &
 Get element. More...
 
void set (const Key &key, const T &val)
 Set element. More...
 
auto pop (const Key &key) -> T
 Pop item. More...
 

Detailed Description

template<typename Key, typename T, typename Hash = std::hash<Key>, typename Pred = std::equal_to<Key>, typename Alloc = std::allocator<std::pair<const Key, T>>>
class samchon::HashMap< Key, T, Hash, Pred, Alloc >

Customized std::unordered_map.

HashMap is a std::unordered_map some methods are modified.

  • Addicted methods
    • has(find(key) != end()) method is addicted
    • at method is addicted
    • set method is addicted
    • pop method is addicted
  • Modified methods
    • at was deprecated (get is different with at)
[Inherited]

Unordered maps are associative containers that store elements formed by the combination of a key value and a mapped value, and which allows for fast retrieval of individual elements based on their keys.

In an unordered_map, the key value is generally used to uniquely identify the element, while the mapped value is an object with the content associated to this key. Types of key and mapped value may differ.

Internally, the elements in the unordered_map are not sorted in any particular order with respect to either their key or mapped values, but organized into buckets depending on their hash values to allow for fast access to individual elements directly by their key values (with a constant average time complexity on average).

unordered_map containers are faster than map containers to access individual elements by their key, although they are generally less efficient for range iteration through a subset of their elements.

Unordered maps implement the direct access operator (operator[]) which allows for direct access of the mapped value using its key value as argument.

In the reference for the unordered_map member functions, these same names (Key, T, Hash, Pred and Alloc) are assumed for the template parameters.

Iterators to elements of unordered_map containers access to both the key and the mapped value. For this, the class defines what is called its value_type, which is a pair class with its first value corresponding to the const version of the key type (template parameter Key) and its second value corresponding to the mapped value (template parameter T):

typedef pair<const Key, T> value_type;

Iterators of a unordered_map container point to elements of this value_type. Thus, for an iterator called it that points to an element of a map, its key and mapped value can be accessed respectively with:

unordered_map<Key,T>::iterator it;
(*it).first; // the key value (of type Key)
(*it).second; // the mapped value (of type T)
(*it); // the "element value" (of type pair<const Key,T>)

Naturally, any other direct access operator, such as -> or [] can be used, for example:

it->first; // same as (*it).first (the key value)
it->second; // same as (*it).second (the mapped value)
Template Parameters
KeyType of the key values. Each element in an unordered_map is uniquely identified by its key value. Aliased as member type unordered_map::key_type.
TType of the mapped value. Each element in an unordered_map is used to store some data as its mapped value. Aliased as member type unordered_map::mapped_type. Note that this is not the same as unordered_map::value_type.
HashA unary function object type that takes an object of type key type as argument and returns a unique value of type size_t based on it. This can either be a class implementing a function call operator or a pointer to a function (see constructor for an example). This defaults to hash<Key>, which returns a hash value with a probability of collision approaching 1.0/std::numeric_limits<size_t>::max(). The unordered_map object uses the hash values returned by this function to organize its elements internally, speeding up the process of locating individual elements. Aliased as member type unordered_map::hasher.
AllocType of the allocator object used to define the storage allocation model. By default, the allocator class template is used, which defines the simplest memory allocation model and is value-independent. Aliased as member type unordered_map::allocator_type.
Author
Jeongho Nam http://samchon.org

Definition at line 103 of file HashMap.hpp.

Member Function Documentation

template<typename Key, typename T, typename Hash = std::hash<Key>, typename Pred = std::equal_to<Key>, typename Alloc = std::allocator<std::pair<const Key, T>>>
auto samchon::HashMap< Key, T, Hash, Pred, Alloc >::has ( const Key &  key) const -> bool
inline

Whether have the item or not.

Indicates whether a map has an item having the specified identifier.

Parameters
keyKey value of the element whose mapped value is accessed.
Returns
Whether the map has an item having the specified identifier

Definition at line 125 of file HashMap.hpp.

Referenced by samchon::templates::parallel::MediatorSystem::getSystemArray(), samchon::templates::service::Server::has(), samchon::library::XML::hasProperty(), and samchon::library::HTTPLoader::load().

Here is the caller graph for this function:

template<typename Key, typename T, typename Hash = std::hash<Key>, typename Pred = std::equal_to<Key>, typename Alloc = std::allocator<std::pair<const Key, T>>>
auto samchon::HashMap< Key, T, Hash, Pred, Alloc >::get ( const Key &  key) -> T&
inline

Get element.

Returns a reference to the mapped value of the element identified with key

Warning
get is different with std::map's at. get does not create object but throws excention if the matched key doesn't exist.
Parameters
keyKey value of the element whose mapped value is accessed.
Exceptions
exceptionout of range
Returns
A reference object of the mapped value (T)

Definition at line 144 of file HashMap.hpp.

Referenced by samchon::library::SQLStatement::bindParameter(), samchon::templates::service::Server::get(), samchon::library::XML::getProperty(), samchon::templates::parallel::MediatorSystem::getSystemArray(), and samchon::library::HTTPLoader::load().

Here is the caller graph for this function:

template<typename Key, typename T, typename Hash = std::hash<Key>, typename Pred = std::equal_to<Key>, typename Alloc = std::allocator<std::pair<const Key, T>>>
void samchon::HashMap< Key, T, Hash, Pred, Alloc >::set ( const Key &  key,
const T &  val 
)
inline

Set element.

Set an item as the specified identifier.

If the identifier is already in map, change value of the identifier.
If not, then insert the object with the identifier.

Parameters
keyKey value of the element whose mapped value is accessed.
valValue, the item.

Definition at line 165 of file HashMap.hpp.

Referenced by samchon::library::SQLStatement::bindParameter(), samchon::library::HTTPLoader::load(), samchon::library::XML::setProperty(), and samchon::library::XML::XML().

Here is the caller graph for this function:

template<typename Key, typename T, typename Hash = std::hash<Key>, typename Pred = std::equal_to<Key>, typename Alloc = std::allocator<std::pair<const Key, T>>>
auto samchon::HashMap< Key, T, Hash, Pred, Alloc >::pop ( const Key &  key) -> T
inline

Pop item.

Removes an item having specified key and returns the removed element.

Returns
An item released by pop

Definition at line 188 of file HashMap.hpp.


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