Containers

Storage containers of objects that serve a broad range of purposes.

Reservation-based Containers

Container types that store objects on a reservation-based system. Users must reserve spots before objects are requested to be stored in these containers.

class sneaker::container::reservation_map<T>

Header file: sneaker/container/reservation_map.h

Note: The internal implementation is based on std::map<token_t, T>, hence elements of type T must have their comparators defined for comparison.

type token_t

The token type used by the reservation container.

type generator_type

The type that is used to generate reservation tokens internally.

reservation_map()

Constructor.

~reservation_map()

Destructor.

size_t size() const

Gets the number of elements that are currently reserved.

token_t reserve()

Reserve a spot in the container. Returns a token that can be used later for storage. The user must call this method before attempts to store an object in the container.

bool member(token_t) const

Determines if an object is a member of the container by using a token. Returns true if a spot has been reserved for the token specified, false otherwise.

bool put(token_t, T)

Attempts to store an object into the container by using a token. The storage fails if the token specified is invalid. Returns true if the storage is successful, false otherwise.

bool get(token_t, T *)

Attempts to retrieve an object from the container by using a token. The retrieval fails if the token specified is invalid. Returns true if the retrieval is successful, false otherwise.

bool unreserve(token_t)

Attempts to unreserve a previously reserved spot by using a token. The un-reservation fails if no previously reservation has been made by the token specified. Returns true if the un-reservation is successful, false otherwise.

void clear()

Removes all the reserved elements. After invoked, all tokens previously obtained are no longer valid.

Assorted-values Map Containers

Key-value(s) based map containers where each key can be mapped to an assortment of multiple values of different statically defined types.

class sneaker::container::assorted_value_map<K, ... ValueTypes>

An implementation of assorted-values map container based on std::map.

Header file: sneaker/container/assorted_value_map.h

type core_type

The core mapping type used internally. This type is std::map<K, boost::tuple<ValueTypes ...>>.

type key_type

The type of the keys in the mapping.

type mapped_type

The type of the assortment of values in the mapping.

type value_type

The type of the key-value(s) pairs in the mapping.

type key_compare

Key comparison type.

type value_compare

Value comparison type.

type reference

Reference type of the values in the mapping.

type const_reference

Constant reference type of the values in the mapping.

type pointer

Pointer type of the values in the mapping.

type const_pointer

Constant pointer type of the values in the mapping.

type iterator

Forward iterator type.

type const_iterator

Constant forward iterator type.

type reverse_iterator

Reverse iterator type.

type const_reverse_type

Constant reverse iterator type.

type difference_type

The type that indicates the difference of number of elements between two iterators of the mapping.

type size_type

The type that indicates the number of elements in the mapping.

explicit assorted_value_map()

Constructor.

explicit assorted_value_map(const assorted_value_map&)

Copy constructor. The mapping is copied over.

explicit assorted_value_map(const core_type&)

Constructor that takes a reference of core mapping type. The mapping is copied over.

~assorted_value_map()

Destructor. All elements in the mapping are freed.

static template<class Compare, class Alloc>
sneaker::container::assorted_value_map<K, ... ValueTypes> create()

Static factory method that creates an instance with the specified Compare key comparator type, and Alloc value allocation type.

static template<class Compare, class Alloc>
sneaker::container::assorted_value_map<K, ... ValueTypes> create(const Compare&, const Alloc&)

Static factory method that creates an instance with the specified Compare key comparator type and Alloc value allocation type, and a reference of each type respectively.

bool empty() const

Determines whether the mapping is empty. Returns true if there are no key-value(s) pairs in the mapping, false otherwise.

size_type size() const

Determines the number of key-value(s) pairs in the mapping.

size_type max_size() const

Determines the maximum number of key-value(s) pairs that can be in the mapping.

void insert(K, ValueTypes)

Inserts a key-value(s) pair into mapping. If the specified key already exists in the mapping, its value(s) will be overwritten.

void erase(iterator)

Erases a particular key-value(s) pair in the mapping by an iterator. The iterator must point to a valid pair in the mapping to be effective.

size_type erase(const K&)

Erases a particular key-value(s) pair in the mapping by a key. Returns the number of elements erased. Note if the specified key does not exist in the mapping, then the number of elements returned is 0.

void erase(iterator, iterator)

Erases a range of key-value(s) in the mapping in between in the two specified iterators, inclusively.

void swap(assorted_value_map&)

Swaps the mapping with another instance of assorted_value_map with the same types for the key and values.

void clear() noexcept

Clears the content in the mapping.

mapped_type &at(K)

Retrieves the value(s) associated with the specified key by reference. Note if the key specified doees not exist in the mapping, std::out_of_range is raised.

const mapped_type &at(K) const

Retrieves the value(s) associated with the specified key by constant reference. Note if the key specified doees not exist in the mapping, std::out_of_range is raised.

template<class A, size_t Index>
A &get(K)

Gets the Index th element associated with the specified key in the container by reference. Note if the key specified doees not exist in the mapping, std::out_of_range is raised.

template<class A, size_t Index>
const A &get(K) const

Gets the Index th element associated with the specified key in the container by reference. Note if the key specified doees not exist in the mapping, std::out_of_range is raised.

mapped_type &operator[](const K&)

Retrieves the value(s) associated with the specified key by reference. Note if the key does not match the key of any element in the container, the function inserts a new element with that key and returns a reference to its mapped value

iterator begin()

Gets a forward iterator that marks the beginning of the mapping.

const_iterator begin() const

Gets a constant forward iterator that marks the beginning of the mapping.

iterator end()

Gets a forward iterator that marks the end of the mapping.

const_iterator end() const

Gets a constant forward iterator that marks the end of the mapping.

reverse_iterator rbegin()

Gets a reverse iterator that marks the beginning of the mapping in reverse order.

const_reverse_iterator rbegin()

Gets a constant reverse iterator that marks the beginning of the mapping in reverse order.

reverse_iterator rend()

Gets a reverse iterator that marks the end of the mapping in reverse order.

const_reverse_order rend() const

Gets a constant reverse iterator that marks the end of the mapping in reverse order.

iterator find(K)

Attempts to find the value(s) associated in the specified key. Returns an instance of forward iterator that points to the key-value(s) pair. If the key does not exist in the mapping, then the iterator returned points to end().

const_iterator find(K) const

Attempts to find the value(s) associated in the specified key. Returns an instance of constant forward iterator that points to the key-value(s) pair. If the key does not exist in the mapping, then the iterator returned points to cend().

class sneaker::container::unordered_assorted_value_map<K, ... ValueTypes>

An implementation of assorted-values map container based on std::unordered_map.

Header file: sneaker/container/unordered_assorted_value_map.h

type core_type

The core mapping type used internally. This type is std::unordered_map<K, boost::tuple<ValueTypes ...>>.

type key_type

The type of the keys in the mapping.

type mapped_type

The type of the assortment of values in the mapping.

type value_type

The type of the key-value(s) pairs in the mapping.

type hasher

The type used to hash the keys.

type key_equal

The type used to evaluate equality between two keys.

type allocator_type

The type of allocator used to allocate memory.

type reference

The reference type for a key-value(s) pair.

type const_reference

The constant reference type for a key-value(s) pair.

type iterator

A bidirectional iterator to value_type.

type const_iterator

A bidirectional iterator to const value_type.

type reverse_iterator

A reverse order iterator to value_type.

type const_reverse_iterator

A reverse order iterator to const value_type.

type size_type

The type that indicates the number of elements in the mapping.

type difference_type

A type that represents the difference between two iterators.

unordered_assorted_value_map()

Constructor.

unordered_assorted_value_map(const core_type&)

Constructor that takes a reference of core mapping type. The mapping is copied over.

unordered_assorted_value_map(const unordered_assorted_value_map&)

Copy constructor. The mapping from the argument is copied over.

~unordered_assorted_value_map()

Destructor. All elements in the mapping are freed.

static template<size_type N, class Hash, class Pred, class Alloc>
sneaker::container::unordered_assorted_value_map<K, ... ValueTypes> create()

Static factory method that creates an instance with the specified initial capacity N, key hash object of type Hash, value comparison object of type Pred and value allocation object of type Alloc.

static template<size_type N, class Hash, class Pred, class Alloc>
sneaker::container::unordered_assorted_value_map<K, ... ValueTypes> create(const Hash&, const Pred&, const Alloc&)

Static factory method that creates an instance with the specified initial capacity N, key hash object of type Hash, value comparison object of type Pred and value allocation object of type Alloc, and a reference of each type respectively except for N.

bool empty() const

Determines whether the mapping is empty. Returns true if there are no key-value(s) pairs in the mapping, false otherwise.

size_type size() const

Determines the number of key-value(s) pairs in the mapping.

size_type max_size() const

Determines the maximum number of key-value(s) pairs that can be in the mapping.

void insert(K, ValueTypes)

Inserts a key-value(s) pair into mapping. If the specified key already exists in the mapping, its value(s) will be overwritten.

void erase(iterator)

Erases a particular key-value(s) pair in the mapping by an iterator. The iterator must point to a valid pair in the mapping to be effective.

size_type erase(const K&)

Erases a particular key-value(s) pair in the mapping by a key. Returns the number of elements erased. Note if the specified key does not exist in the mapping, then the number of elements returned is 0.

void erase(iterator, iterator)

Erases a range of key-value(s) in the mapping in between in the two specified iterators, inclusively.

void swap(assorted_value_map&)

Swaps the mapping with another instance of assorted_value_map with the same types for the key and values.

void clear() noexcept

Clears the content in the mapping.

const mapped_type &at(K) const

Retrieves the value(s) associated with the specified key by constant reference. Note if the key specified does not exist in the mapping, std::out_of_range is raised.

template<class A, size_t Index>
A get(K)

Retrieves a particular value among the assortment of values associated with the specified key. Type A is the type of the value, and Index is a zero-based index that specifies the position of the value to be retrieved, among the list of values. Note if the key specified does not exist in the mapping, std::out_of_range is raised.

template<class A, size_t Index>
const A &get(K) const

Retrieves a particular value by constant reference among the assortment of values associated with the specified key. Type A is the type of the value, and Index is a zero-based index that specifies the position of the value to be retrieved, among the list of values. Note if the key specified does not exist in the mapping, std::out_of_range is raised.

mapped_type &operator[](const K&)

Retrieves the value(s) associated with the specified key by reference. Note if the key does not match the key of any element in the container, the function inserts a new element with that key and returns a reference to its mapped value

iterator begin()

Gets a forward iterator that marks the beginning of the mapping.

const_iterator begin() const

Gets a constant forward iterator that marks the beginning of the mapping.

iterator end()

Gets a forward iterator that marks the end of the mapping.

const_iterator end() const

Gets a constant forward iterator that marks the end of the mapping.

iterator find(K)

Attempts to find the value(s) associated in the specified key. Returns an instance of forward iterator that points to the key-value(s) pair. If the key does not exist in the mapping, then the iterator returned points to end().

const_iterator find(K) const

Attempts to find the value(s) associated in the specified key. Returns an instance of constant forward iterator that points to the key-value(s) pair. If the key does not exist in the mapping, then the iterator returned points to cend().

float load_factor() const noexcept

Gets the current load factor of the mapping, which is the ratio between the number of key-value(s) pair in the mapping and the number of buckets.

float max_load_factor() const noexcept

Get the maximum load factor the mapping can have.

void rehash(size_type)

Sets the number of buckets in the mapping to n or more by enforcing a rehash on all the keys in the mapping.

If n is greater than the current number of buckets in the mapping (bucket_count), a rehash is forced. The new bucket count can either be equal or greater than n.

If n is lower than the current number of buckets in the mapping (bucket_count), the function may have no effect on the bucket count and may not force a rehash.

Rehashes are automatically performed by the container whenever its load factor is going to surpass its max_load_factor in an operation.

void reserve(size_type)

Request a capacity change on the mapping by setting the number of buckets in the mapping to the most appropriate to contain at least the number of key-value(s) pairs specified by the first argument.

If n is greater than the current bucket_count multiplied by the max_load_factor, the container’s bucket_count is increased and a rehash is forced.

If n is lower than that, the function may have no effect.

hasher hash_function() const

Returns the hash function object used by the mapping.