Similar to std::unordered_map, but it will manage reference count automatically internally.
More...
#include <Map.h>
|
typedef RefMap::iterator | iterator |
| Iterator, can be used to loop the Map.
|
|
typedef RefMap::const_iterator | const_iterator |
| Const iterator, can be used to loop the Map.
|
|
|
iterator | begin () |
| Return iterator to beginning.
|
|
const_iterator | begin () const |
| Return const_iterator to beginning.
|
|
iterator | end () |
| Return iterator to end.
|
|
const_iterator | end () const |
| Return const_iterator to end.
|
|
const_iterator | cbegin () const |
| Return const_iterator to beginning.
|
|
const_iterator | cend () const |
| Return const_iterator to end.
|
|
| Map () |
| Default constructor.
|
|
| Map (ssize_t capacity) |
| Constructor with capacity.
|
|
| Map (const Map &other) |
| Copy constructor.
|
|
| Map (Map &&other) |
| Move constructor.
|
|
| ~Map () |
| Destructor.
|
|
void | reserve (ssize_t capacity) |
| Sets capacity of the map.
|
|
ssize_t | bucketCount () const |
| Returns the number of buckets in the Map container.
|
|
ssize_t | bucketSize (ssize_t n) const |
| Returns the number of elements in bucket n.
|
|
ssize_t | bucket (const K &k) const |
| Returns the bucket number where the element with key k is located.
|
|
ssize_t | size () const |
| The number of elements in the map.
|
|
bool | empty () const |
| Returns a bool value indicating whether the map container is empty, i.e.
|
|
std::vector< K > | keys () const |
| Returns all keys in the map.
|
|
std::vector< K > | keys (V object) const |
| Returns all keys that matches the object.
|
|
template<typename K2> |
const V | at (const K2 &key) const |
| Returns a reference to the mapped value of the element with key k in the map.
|
|
template<typename K2> |
const_iterator | find (const K2 &key) const |
| Searches the container for an element with 'key' as key and returns an iterator to it if found, otherwise it returns an iterator to Map<K, V>::end (the element past the end of the container).
|
|
template<typename K2> |
void | insert (const K2 &key, V object) |
| Inserts new elements in the map.
|
|
iterator | erase (const_iterator position) |
| Removes an element with an iterator from the Map<K, V> container.
|
|
template<typename _K2> |
size_t | erase (const _K2 &k) |
| Removes an element with an iterator from the Map<K, V> container.
|
|
template<typename _K2> |
void | erase (const std::vector< _K2 > &keys) |
| Removes some elements with a vector which contains keys in the map.
|
|
void | clear () |
| All the elements in the Map<K,V> container are dropped: their reference count will be decreased, and they are removed from the container, leaving it with a size of 0.
|
|
V | getRandomObject () const |
| Gets a random object in the map.
|
|
Map & | operator= (const Map &other) |
| Copy assignment operator.
|
|
Map & | operator= (Map &&other) |
| Move assignment operator.
|
|
template<class K, class V, typename H = std::hash<K>, typename E = std::equal_to<K>>
class ax::Map< K, V, H, E >
Similar to std::unordered_map, but it will manage reference count automatically internally.
Which means it will invoke Object::retain() when adding an element, and invoke Object::release() when removing an element.
- Warning
- The element should be
Object
or its sub-class. @js NA @lua NA
◆ ~Map()
template<class K, class V, typename H = std::hash<K>, typename E = std::equal_to<K>>
Destructor.
It will release all objects in map.
◆ empty()
template<class K, class V, typename H = std::hash<K>, typename E = std::equal_to<K>>
Returns a bool value indicating whether the map container is empty, i.e.
whether its size is 0.
- Note
- This function does not modify the content of the container in any way. To clear the content of an array object, member function unordered_map::clear exists.
◆ at()
template<class K, class V, typename H = std::hash<K>, typename E = std::equal_to<K>>
template<typename K2>
const V at |
( |
const K2 & | key | ) |
const |
|
inline |
Returns a reference to the mapped value of the element with key k in the map.
- Note
- If key does not match the key of any element in the container, the function return nullptr.
- Parameters
-
key | Key value of the element whose mapped value is accessed. Member type K is the keys for the elements in the container. defined in Map<K, V> as an alias of its first template parameter (Key). |
◆ find()
template<class K, class V, typename H = std::hash<K>, typename E = std::equal_to<K>>
template<typename K2>
Searches the container for an element with 'key' as key and returns an iterator to it if found, otherwise it returns an iterator to Map<K, V>::end (the element past the end of the container).
- Parameters
-
key | Key to be searched for. Member type 'K' is the type of the keys for the elements in the container, defined in Map<K, V> as an alias of its first template parameter (Key). |
◆ insert()
template<class K, class V, typename H = std::hash<K>, typename E = std::equal_to<K>>
template<typename K2>
void insert |
( |
const K2 & | key, |
|
|
V | object ) |
|
inline |
Inserts new elements in the map.
- Note
- If the container has already contained the key, this function will erase the old pair(key, object) and insert the new pair.
- Parameters
-
key | The key to be inserted. |
object | The object to be inserted. |
◆ erase() [1/3]
template<class K, class V, typename H = std::hash<K>, typename E = std::equal_to<K>>
Removes an element with an iterator from the Map<K, V> container.
- Parameters
-
position | Iterator pointing to a single element to be removed from the Map<K, V>. Member type const_iterator is a forward iterator type. |
◆ erase() [2/3]
template<class K, class V, typename H = std::hash<K>, typename E = std::equal_to<K>>
template<typename _K2>
size_t erase |
( |
const _K2 & | k | ) |
|
|
inline |
Removes an element with an iterator from the Map<K, V> container.
- Parameters
-
k | Key of the element to be erased. Member type 'K' is the type of the keys for the elements in the container, defined in Map<K, V> as an alias of its first template parameter (Key). |
◆ erase() [3/3]
template<class K, class V, typename H = std::hash<K>, typename E = std::equal_to<K>>
template<typename _K2>
void erase |
( |
const std::vector< _K2 > & | keys | ) |
|
|
inline |
Removes some elements with a vector which contains keys in the map.
- Parameters
-
keys | Keys of elements to be erased. |
◆ getRandomObject()
template<class K, class V, typename H = std::hash<K>, typename E = std::equal_to<K>>
V getRandomObject |
( |
| ) |
const |
|
inline |
Gets a random object in the map.
- Returns
- Returns the random object if the map isn't empty, otherwise it returns nullptr.
The documentation for this class was generated from the following file: