Confluent Sets and Maps
|
Public Types | |
typedef Key | key_type |
typedef T | mapped_type |
typedef std::pair< Key, T > | value_type |
typedef set< Key, Compare, Hash, Equal > | key_set_type |
typedef map_provider< Key, T, Compare, Hash, Equal, MappedHash, MappedEqual > | provider_type |
typedef std::shared_ptr< provider_type > | provider_ptr |
typedef confluent::iterator< traits > | iterator |
typedef std::reverse_iterator< iterator > | reverse_iterator |
Public Member Functions | |
map (provider_ptr provider=provider_type::default_provider()) | |
template<class InputIterator > | |
map (InputIterator first, InputIterator last, provider_ptr provider=provider_type::default_provider()) | |
map (std::initializer_list< value_type > ilist, provider_ptr provider=provider_type::default_provider()) | |
map (iterator first, iterator last) | |
map (const map &other) | |
map (map &&other) | |
size_t | insert (const value_type &value) |
template<class InputIterator > | |
size_t | insert (InputIterator first, InputIterator last) |
size_t | insert (std::initializer_list< value_type > ilist) |
size_t | insert (const map &other) |
size_t | insert_or_assign (const value_type &value) |
template<class InputIterator > | |
size_t | insert_or_assign (InputIterator first, InputIterator last) |
size_t | insert_or_assign (std::initializer_list< value_type > ilist) |
size_t | insert_or_assign (const map &other) |
size_t | erase (const key_type &key) |
size_t | erase (const value_type &value) |
size_t | erase (iterator first, iterator last) |
size_t | erase (const key_set_type &other) |
size_t | erase (const map &other) |
size_t | retain (iterator first, iterator last) |
size_t | retain (const key_set_type &other) |
size_t | retain (const map &other) |
void | clear () |
void | swap (map &other) |
map & | operator= (const map &other) |
map & | operator= (map &&other) |
map & | operator= (std::initializer_list< value_type > ilist) |
map | operator| (const map &rhs) const |
map & | operator|= (const map &rhs) |
map | operator& (const map &rhs) const |
map | operator& (const key_set_type &rhs) const |
map & | operator&= (const map &rhs) |
map & | operator&= (const key_set_type &rhs) |
map | operator- (const map &rhs) const |
map | operator- (const key_set_type &rhs) const |
map & | operator-= (const map &rhs) |
map & | operator-= (const key_set_type &rhs) |
iterator | begin () const |
iterator | end () const |
iterator | cbegin () const |
iterator | cend () const |
reverse_iterator | rbegin () const |
reverse_iterator | rend () const |
iterator | find (const key_type &key) const |
iterator | lower_bound (const key_type &key) const |
iterator | upper_bound (const key_type &key) const |
std::pair< iterator, iterator > | equal_range (const key_type &key) const |
const mapped_type & | at (const key_type &key) const |
const value_type & | at_index (size_t k) const |
size_t | count (const key_type &key) const |
size_t | count (const key_type &key, const mapped_type &mapped) const |
bool | includes (const map &other) const |
key_set_type | key_set () const |
const provider_ptr & | provider () const |
bool | empty () const |
size_t | size () const |
size_t | hash () const |
bool | operator== (const map &other) const |
bool | operator!= (const map &other) const |
The class confluent::map is a sorted associative container whose instances share key nodes with other sets and maps using the same set_provider and share assigment nodes with other maps using the same map_proivder.
Cloning maps and testing maps for equal content run in constant time. Merge operations such as set union, set intersection and set difference perform at optimal cost not only when one of the input maps is smaller than the other, but also when the number of elements that differ between the input maps is small. Maps can also be merged with sets at the same cost as maps can be merged with maps in operations that remove elements, such as set intersection and set difference.
Contained elements must be comparable, hashable and copy-constructible and documented complexity is based on that such operations are constant in time and memory and that hash collisions are rare.
|
inline |
Creates a new map.
provider | map_provider to use for this map (optional) |
Complexity: Constant in time and memory.
|
inline |
Creates a new map from a range of elements.
first | range start |
last | range end |
provider | map_provider to use for this map (optional) |
Complexity: O(n log n) expected time on random input. O(n) on presorted input. O(n) in memory.
|
inline |
Creates a new map from an initializer_list.
ilist | the list of elements to include in the created map |
provider | map_provider to use for this map (optional) |
Complexity: O(n log n) expected time on random input. O(n) on presorted input. O(n) in memory.
|
inline |
Creates a new map from a range in another map.
The created map will use the same map_provider as the source map.
first | range start |
last | range end |
Complexity: O(log n * log n) expected time and memory.
|
inline |
Creates a new map as a copy of another map.
The created map will use the same map_provider as the source map.
other | other map |
Complexity: Constant in time and memory.
|
inline |
Creates a new map by moving content from another map.
The created map will use the same map_provider as the source map.
Result is undefined if the other map is used after content has been moved.
other | other map |
Complexity: Constant in time and memory.
|
inline |
Inserts an element into this map.
The new element is inserted if it is not contained before.
value | element to insert |
Complexity: O(log n) expected time and memory.
|
inline |
Inserts a range of elements into this map.
New element are inserted if they are not contained before.
first | range start |
last | range end |
Complexity: Same cost as first creating a map from the given range and then inserting the created map into this map.
|
inline |
Inserts elements from an initializer_list into this map.
New element are inserted if they are not contained before.
ilist | the list of elements to insert |
Complexity: Same cost as first creating a map from the given initializer_list and then inserting the created map into this map.
|
inline |
Inserts elements in another map into this map.
New element are inserted, replacing any contained element with same key.
Result is undefined if not both maps are using the same map_provider.
other | other map to insert elements from |
Let n be the size of the larger map. Let m be the size of the smaller map. Let d be the size of the difference between this map and the other map.
Complexity: O(min(m * log(n/m), d * log(n/d))) expected time and memory.
|
inline |
Inserts an element into this map.
The new element is inserted, replacing any contained element with same key.
value | element to insert |
Complexity: O(log n) expected time and memory.
|
inline |
Inserts a range of elements into this map.
The new element are inserted, replacing any contained elements with same keys.
first | range start |
last | range end |
Complexity: Same cost as first creating a map from the given range and then inserting the created map into this map.
|
inline |
Inserts elements from an initializer_list into this map.
The new element are inserted, replacing any contained elements with same keys.
ilist | the list of elements to insert |
Complexity: Same cost as first creating a map from the given initializer_list and then inserting the created map into this map.
|
inline |
Inserts elements in another map into this map.
The new element are inserted, replacing any contained elements with same keys.
Result is undefined if not both maps are using the same map_provider.
other | other map to insert elements from |
Let n be the size of the larger map. Let m be the size of the smaller map. Let d be the size of the difference between this map and the other map.
Complexity: O(min(m * log(n/m), d * log(n/d))) expected time and memory.
|
inline |
Erases an element from this map.
An element with the given key is erased if contained in the map.
key | element to erase |
Complexity: O(log n) expected time and memory.
|
inline |
Erases an element from this map.
The given element is erased if contained in the map.
value | element to erase |
Complexity: O(log n) expected time and memory.
|
inline |
Erases a range of elements from this map.
The given range must be a range in this map.
first | range start |
last | range end |
Complexity: O(log n * log n) expected time and memory.
Note: This operation might cause destruction of unused nodes, but the cost of destructing nodes is always covered by the cost of creating them.
|
inline |
Erases elements whose keys matches the elements in a given set.
After the operation key set of this map will contain the set difference, i.e. all keys that were present in this map but not in the given set.
Result is undefined if the given set is not using the same set_provider as the key set of this map.
other | other set to erase elements from |
Let n be the size of the larger container. Let m be the size of the smaller container. Let d be the size of the difference between the key set of this map and the given set.
Complexity: O(min(m * log(n/m), d * log(n/d))) expected time and memory.
Note: This operation might cause destruction of unused nodes, but the cost of destructing nodes is always covered by the cost of creating them.
|
inline |
Erases elements in another map from this map.
After the operation this map will contain the map difference, i.e. all elements that were present in this map but not in the other map.
Result is undefined if not both maps are using the same map_provider.
other | other map to erase elements from |
Let n be the size of the larger map. Let m be the size of the smaller map. Let d be the size of the difference between this map and the other map.
Complexity: O(min(m * log(n/m), d * log(n/d))) expected time and memory.
Note: This operation might cause destruction of unused nodes, but the cost of destructing nodes is always covered by the cost of creating them.
|
inline |
Retains a range of elements.
The given range must be a range in this map.
After the operation this map will contain the elements in the range.
first | range start |
last | range end |
Complexity: O(log n * log n) expected time and memory.
Note: This operation might cause destruction of unused nodes, but the cost of destructing nodes is always covered by the cost of creating them.
|
inline |
Retains elements whose keys matches the elements in a given set.
After the operation key set of this map will contain the set intersection, i.e. all keys that were present in this map and also in the given set.
Result is undefined if not the given set is using the same set_provider as the key set of this map.
other | other set to erase elements from |
Let n be the size of the larger container. Let m be the size of the smaller container. Let d be the size of the difference between the key set of this map and the given set.
Complexity: O(min(m * log(n/m), d * log(n/d))) expected time and memory.
Note: This operation might cause destruction of unused nodes, but the cost of destructing nodes is always covered by the cost of creating them.
|
inline |
Retains elements that are contained in another map.
After the operation this map will contain the map intersection, i.e. all elements that were present in this map and also in the other map.
Result is undefined if not both maps are using the same map_provider.
other | other map to erase elements from |
Let n be the size of the larger map. Let m be the size of the smaller map. Let d be the size of the difference between this map and the other map.
Complexity: O(min(m * log(n/m), d * log(n/d))) expected time and memory.
Note: This operation might cause destruction of unused nodes, but the cost of destructing nodes is always covered by the cost of creating them.
|
inline |
Erases all elements in this map.
Complexity: Constant in time and memory.
Note: This operation might cause destruction of unused nodes, but the cost of destructing nodes is always covered by the cost of creating them.
|
inline |
Swaps the content of this map with the content of another map.
Complexity: Constant in time and memory.
|
inline |
Replaces the content of this map with the content of another map.
After the operation this map will use the same provider as the other map.
Complexity: Constant in time and memory.
Note: This operation might cause destruction of unused nodes, but the cost of destructing nodes is always covered by the cost of creating them.
|
inline |
Replaces the content of this map with the content of another map.
After the operation this map will use the same provider as the other map used before the operation.
Result is undefined if the other map is used after content has been moved.
Complexity: Constant in time and memory.
Note: This operation might cause destruction of unused nodes, but the cost of destructing nodes is always covered by the cost of creating them.
|
inline |
Replaces the content of this map with elements from an initializer_list.
ilist | the list of elements to assign |
Complexity: O(n log n) expected time on random input. O(n) on presorted input. O(n) in memory.
Note: This operation might cause destruction of unused nodes, but the cost of destructing nodes is always covered by the cost of creating them.
|
inline |
Returns the union of this map and another map.
Result is undefined if not both maps are using the same map_provider.
rhs | other map to merge with this map |
Let n be the size of the larger map. Let m be the size of the smaller map. Let d be the size of the difference between this map and the other map.
Complexity: O(min(m * log(n/m), d * log(n/d))) expected time and memory.
|
inline |
Replaces the content of this map with the union of this map and another map.
Result is undefined if not both maps are using the same map_provider.
rhs | other map to merge with this map |
Let n be the size of the larger map. Let m be the size of the smaller map. Let d be the size of the difference between this map and the other map.
Complexity: O(min(m * log(n/m), d * log(n/d))) expected time and memory.
|
inline |
Returns the intersection of this map and another map.
Result is undefined if not both maps are using the same map_provider.
rhs | other map to merge with this map |
Let n be the size of the larger map. Let m be the size of the smaller map. Let d be the size of the difference between this map and the other map.
Complexity: O(min(m * log(n/m), d * log(n/d))) expected time and memory.
Note: This operation might cause destruction of unused nodes, but the cost of destructing nodes is always covered by the cost of creating them.
|
inline |
Returns the intersection of this map and a given set.
Result is undefined if not the given set is using the same set_provider as the key set of this map.
rhs | set to merge with this map |
Let n be the size of the larger container. Let m be the size of the smaller container. Let d be the size of the difference between the key set of this map and the given set.
Complexity: O(min(m * log(n/m), d * log(n/d))) expected time and memory.
Note: This operation might cause destruction of unused nodes, but the cost of destructing nodes is always covered by the cost of creating them.
|
inline |
Replaces the content of this map with the intersection of this map and another map.
Result is undefined if not both maps are using the same map_provider.
rhs | other map to merge with this map |
Let n be the size of the larger map. Let m be the size of the smaller map. Let d be the size of the difference between this map and the other map.
Complexity: O(min(m * log(n/m), d * log(n/d))) expected time and memory.
Note: This operation might cause destruction of unused nodes, but the cost of destructing nodes is always covered by the cost of creating them.
|
inline |
Replaces the content of this map with the intersection of this map and a given set.
Result is undefined if not the given set is using the same set_provider as the key set of this map.
rhs | other map to merge with this map |
Let n be the size of the larger map. Let m be the size of the smaller map. Let d be the size of the difference between this map and the other map.
Complexity: O(min(m * log(n/m), d * log(n/d))) expected time and memory.
Note: This operation might cause destruction of unused nodes, but the cost of destructing nodes is always covered by the cost of creating them.
|
inline |
Returns the difference of this map and another map.
Result is undefined if not both maps are using the same map_provider.
rhs | other map to merge with this map |
Let n be the size of the larger map. Let m be the size of the smaller map. Let d be the size of the difference between this map and the other map.
Complexity: O(min(m * log(n/m), d * log(n/d))) expected time and memory.
Note: This operation might cause destruction of unused nodes, but the cost of destructing nodes is always covered by the cost of creating them.
|
inline |
Returns the difference of this map and a given set.
Result is undefined if not the given set is using the same set_provider as the key set of this map.
rhs | set to merge with this map |
Let n be the size of the larger container. Let m be the size of the smaller container. Let d be the size of the difference between the key set of this map and the given set.
Complexity: O(min(m * log(n/m), d * log(n/d))) expected time and memory.
Note: This operation might cause destruction of unused nodes, but the cost of destructing nodes is always covered by the cost of creating them.
|
inline |
Replaces the content of this map with the difference of this map and another map.
Result is undefined if not both maps are using the same map_provider.
rhs | other map to merge with this map |
Let n be the size of the larger map. Let m be the size of the smaller map. Let d be the size of the difference between this map and the other map.
Complexity: O(min(m * log(n/m), d * log(n/d))) expected time and memory.
Note: This operation might cause destruction of unused nodes, but the cost of destructing nodes is always covered by the cost of creating them.
|
inline |
Replaces the content of this map with the intersection of this map and a given set.
Result is undefined if not the given set is using the same set_provider as the key set of this map.
rhs | other map to merge with this map |
Let n be the size of the larger map. Let m be the size of the smaller map. Let d be the size of the difference between this map and the other map.
Complexity: O(min(m * log(n/m), d * log(n/d))) expected time and memory.
Note: This operation might cause destruction of unused nodes, but the cost of destructing nodes is always covered by the cost of creating them.
|
inline |
Returns an iterator to the beginning of this map.
|
inline |
Returns an iterator to the end of this map.
|
inline |
Returns an iterator to the beginning of this map.
|
inline |
Returns an iterator to the end of this map.
|
inline |
Returns a reverse iterator to the beginning of this map.
|
inline |
Returns a reverse iterator to the end of this map.
|
inline |
Finds an element with a given key.
key | key to search for |
Complexity: O(log n) expected time.
|
inline |
Returns an iterator to the first element whose key does not compare less than a given key.
key | key to search for |
Complexity: O(log n) expected time.
|
inline |
Returns an iterator to the first element whose key compares greater than a given key.
key | key to search for |
Complexity: O(log n) expected time.
|
inline |
Returns range of elements matching a given key.
r = s.equal_range(key);
is equivalent to
r = { s.lower_bound(key), s.upper_bound(key)};
Complexity: O(log n) expected time.
|
inline |
Returns a mapped value that matches a given key.
key | key to search for |
std::out_of_range | if the given key was not found |
Complexity: O(log n) expected time.
|
inline |
Finds an element at a given index.
k | the index of the wanted element |
Complexity: O(log n) expected time.
|
inline |
Returns the number of elements whose key match a given key
key | key to search for |
Complexity: O(log n) expected time.
|
inline |
Returns the number of elements matching a given key and mapped value.
key | key to search for |
mapped | mapped value to search for |
Complexity: O(log n) expected time.
|
inline |
Tests if this map includes the elements in another map.
Result is undefined if not both maps are using the same map_provider.
other | map to test if its elements are included in this map |
Let n be the size of this map. Let m be the size of the other. Let d be the size of the difference between this map and the other map.
Complexity: O(min(m * log(n/m), d * log(n/d))) expected time and memory.
Note: The operation will return directly if m > n.
|
inline |
Returns a set containing the keys in this map.
Complexity: Constant in time and memory.
|
inline |
Returns a shared pointer to the map_provider used by this map.
|
inline |
Tests if this map is empty.
Complexity: Constant in time.
|
inline |
|
inline |
Returns the combined hash value of all elements in this map.
Complexity: Constant in time.
|
inline |
Tests if this map contains the same elements as another map.
Result is undefined if not both maps are using the same map_provider.
Complexity: Constant in time.
|
inline |
Tests if this map does not contain the same elements as another map.
Result is undefined if not both maps are using the same map_provider.
Complexity: Constant in time.