Samchon Framework for CPP  1.0.0
samchon::TreeMap< _Kty, _Ty, _Pr, _Alloc > Class Template Reference

Customized std::map. More...

#include <TreeMap.hpp>

Public Member Functions

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

Detailed Description

template<typename _Kty, typename _Ty, typename _Pr = std::less<_Kty>, typename _Alloc = std::allocator<std::pair<const _Kty, _Ty>>>
class samchon::TreeMap< _Kty, _Ty, _Pr, _Alloc >

Customized std::map.

TreeMap is a std::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]

Maps are associative containers that store elements formed by a combination of a key value and a mapped value, following a specific order.

In a map, the key values are generally used to sort and uniquely identify the elements, while the mapped values store the content associated to this key. The types of key and mapped value may differ, and are grouped together in member type value_type, which is a pair type combining both:

  • typedef pair<const Key, T> value_type;

Internally, the elements in a map are always sorted by its key following a specific strict weak ordering criterion indicated by its internal comparison object (of type Compare).

map containers are generally slower than unordered_map containers to access individual elements by their key, but they allow the direct iteration on subsets based on their order.

Maps are typically implemented as binary search trees.

The mapped values in a map can be accessed directly by their corresponding key using the bracket operator ((operator[]).

Maps are typically implemented as binary search trees.

Referenced comments of std::map

Template Parameters
_Kty

Type of the keys. Each element in a map is uniquely identified by its key value.

Aliased as member type map::key_type.

Template Parameters
_Ty

Type of the mapped value. Each element in a map stores some data as its mapped value.

Aliased as member type map::mapped_type.

Template Parameters
_Pr

A binary predicate that takes two element keys as arguments and returns a bool. The expression comp(a,b), where comp is an object of this type and a and b are key values, shall return true if a is considered to go before b in the strict weak ordering the function defines.

The map object uses this expression to determine both the order the elements follow in the container and whether two element keys are equivalent (by comparing them reflexively: they are equivalent if !comp(a,b) && !comp(b,a)). No two elements in a map container can have equivalent keys.

This can be a function pointer or a function object. This defaults to std::less<T>, which returns the same as applying the less-than operator (a<b).

Aliased as member type map::key_compare.

Template Parameters
_Alloc

Type 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 map::allocator_type.

Author
Jeongho Nam http://samchon.org

Definition at line 87 of file TreeMap.hpp.

Member Function Documentation

template<typename _Kty, typename _Ty, typename _Pr = std::less<_Kty>, typename _Alloc = std::allocator<std::pair<const _Kty, _Ty>>>
auto samchon::TreeMap< _Kty, _Ty, _Pr, _Alloc >::has ( const _Kty &  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 109 of file TreeMap.hpp.

template<typename _Kty, typename _Ty, typename _Pr = std::less<_Kty>, typename _Alloc = std::allocator<std::pair<const _Kty, _Ty>>>
auto samchon::TreeMap< _Kty, _Ty, _Pr, _Alloc >::get ( const _Kty &  key) -> _Ty&
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 (_Ty)

Definition at line 128 of file TreeMap.hpp.

template<typename _Kty, typename _Ty, typename _Pr = std::less<_Kty>, typename _Alloc = std::allocator<std::pair<const _Kty, _Ty>>>
void samchon::TreeMap< _Kty, _Ty, _Pr, _Alloc >::set ( const _Kty &  key,
const _Ty &  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 149 of file TreeMap.hpp.

template<typename _Kty, typename _Ty, typename _Pr = std::less<_Kty>, typename _Alloc = std::allocator<std::pair<const _Kty, _Ty>>>
auto samchon::TreeMap< _Kty, _Ty, _Pr, _Alloc >::pop ( const _Kty &  key) -> _Ty
inline

Pop item.

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

Returns
An item released by pop

Definition at line 172 of file TreeMap.hpp.


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