|
| UnorderedSetByBlock (size_type bucket_count=23, const Splitter &splitter=Splitter(), const Hash &hash=Hash(), const key_equal &equal=key_equal(), const UnorderedMapAllocator &alloc=UnorderedMapAllocator()) |
| ~UnorderedSetByBlock ()=default |
| Default destructor.
|
| UnorderedSetByBlock (const Self &other) |
| UnorderedSetByBlock (Self &&other) |
Self & | operator= (const Self &other) |
Self & | operator= (Self &&other) |
iterator | begin () |
iterator | end () |
const_iterator | begin () const |
const_iterator | end () const |
const_iterator | cbegin () const |
const_iterator | cend () const |
bool | empty () const noexcept |
size_type | size () const noexcept |
size_type | max_size () const noexcept |
size_type | blocks () const noexcept |
size_type | memory_usage () const noexcept |
size_type | memory_usage_unordered_set () const noexcept |
void | clear () noexcept |
| Clears the container.
|
void | swap (Self &other) noexcept |
std::pair< iterator, bool > | insert (const value_type &value) |
| Attempts to insert an element into the set.
|
template<typename InputIterator> |
void | insert (InputIterator first, InputIterator last) |
| Inserts a range of element into the set.
|
template<typename... _Args> |
std::pair< iterator, bool > | emplace (_Args &&... __args) |
| Attempts to build and insert an element into the set.
|
iterator | erase (const_iterator pos) noexcept |
iterator | erase (const_iterator first, const_iterator last) noexcept |
size_type | erase (const key_type &key) |
iterator | find (const Key &key) |
const_iterator | find (const Key &key) const |
size_type | count (const Key &key) const |
std::pair< iterator, iterator > | equal_range (const Key &key) |
std::pair< const_iterator, const_iterator > | equal_range (const Key &key) const |
void | reserve (size_type block_count) |
template<typename Key, typename TSplitter = Splitter< Key >, class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>, class UnorderedMapAllocator = std::allocator< std::pair<const Key, typename TSplitter::Word > >>
struct DGtal::UnorderedSetByBlock< Key, TSplitter, Hash, KeyEqual, UnorderedMapAllocator >
This data structure represents a set of elements that must be integral arrays (i.e. digital points). It is similar to an unordered_set, but much more compact in general. The container used is a unordered_map from point to a 32-bit word. The idea is to group consecutive elements/points along x axis by blocks of 32 bits. If any point in a block is present, the corresponding element is present in the unordered_map and bits set to 1 in the word correspond to points present in the set. On average, memory occupancy is divided by four, the structure is four times faster for traversal and approximately same speed for queries/insertion/erase.
Almost all standard operations of unordered_set in c++11 are implemented.
- Template Parameters
-
Key | the type of integral array. |
TSplitter | the type for splitting a key into a block and a bit (see Splitter). |
Hash | the type that provides a hasher for Key. |
KeyEqual | the type that provides an equality comparator for Key. |
UnorderedMapAllocator | the type that provides an allocator for the underlying unordered_map container. |
Specialized versions of Splitter are written for usual digital points of Z2i or Z3i.
#include "DGtal/kernel/UnorderedSetByBlock.h"
...
std::unordered_set< Point3i > aSet;
Definition at line 163 of file UnorderedSetByBlock.h.
template<typename Key, typename TSplitter = Splitter< Key >, class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>, class UnorderedMapAllocator = std::allocator< std::pair<const Key, typename TSplitter::Word > >>
template<typename... _Args>
Attempts to build and insert an element into the set.
- Parameters
-
__args | Arguments used to generate an element. |
- Returns
- A pair, of which the first element is an iterator that points to the possibly inserted element, and the second is a bool that is true if the element was actually inserted.
This function attempts to build and insert an element into the set. A set relies on unique keys and thus an element is only inserted if it is not already present in the set.
Insertion takes amortized constant time.
Definition at line 714 of file UnorderedSetByBlock.h.
715 {
719 {
722 static_cast<Word>(1) <<
se.second ) );
725 }
726 else
727 {
728 bool exist =
it->second & (
static_cast<Word>(1) <<
se.second );
730 {
731 it->second |=
static_cast<Word>(1) <<
se.second;
733 }
735 }
736 }
template<typename Key, typename TSplitter = Splitter< Key >, class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>, class UnorderedMapAllocator = std::allocator< std::pair<const Key, typename TSplitter::Word > >>
- Returns
- an iterator past the last stored element
Definition at line 539 of file UnorderedSetByBlock.h.
Referenced by DGtal::UnorderedSetByBlock< Key, TSplitter, Hash, KeyEqual >::equal_range(), DGtal::UnorderedSetByBlock< Key, TSplitter, Hash, KeyEqual >::equal_range(), DGtal::UnorderedSetByBlock< Key, TSplitter, Hash, KeyEqual >::erase(), DGtal::UnorderedSetByBlock< Key, TSplitter, Hash, KeyEqual >::erase(), and DGtal::UnorderedSetByBlock< Key, TSplitter, Hash, KeyEqual >::find().
template<typename Key, typename TSplitter = Splitter< Key >, class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>, class UnorderedMapAllocator = std::allocator< std::pair<const Key, typename TSplitter::Word > >>
Removes specified element from the container.
- Parameters
-
pos | a valid iterator in this data structure |
- Returns
- the iterator following the last removed element.
- Note
- References and iterators to the erased elements are invalidated. Other iterators and references are not invalidated.
- Precondition
- The iterator pos must be valid and dereferenceable. Thus the end() iterator (which is valid, but is not dereferenceable) cannot be used as a value for pos.
Definition at line 749 of file UnorderedSetByBlock.h.
750 {
754 !=
static_cast<Word>(0) );
757 if ( (
w &= ~(
static_cast<Word>(1) <<
pos.bit ) )
758 ==
static_cast<Word>(0) )
760 else
762 }
Referenced by DGtal::UnorderedSetByBlock< Key, TSplitter, Hash, KeyEqual >::erase().
template<typename Key, typename TSplitter = Splitter< Key >, class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>, class UnorderedMapAllocator = std::allocator< std::pair<const Key, typename TSplitter::Word > >>
Finds an element with key equivalent to key.
- Parameters
-
- Returns
- an iterator pointing to key or end() if the key is not the set.
Definition at line 867 of file UnorderedSetByBlock.h.
868 {
872 const bool exist =
it->second & (
static_cast<Word>(1) <<
se.second );
875 }
Referenced by DGtal::UnorderedSetByBlock< Key, TSplitter, Hash, KeyEqual >::equal_range(), DGtal::UnorderedSetByBlock< Key, TSplitter, Hash, KeyEqual >::equal_range(), DGtal::UnorderedSetByBlock< Key, TSplitter, Hash, KeyEqual >::erase(), DGtal::UnorderedSetByBlock< Key, TSplitter, Hash, KeyEqual >::internal_includes_by_iterator(), and DGtal::UnorderedSetByBlock< Key, TSplitter, Hash, KeyEqual >::internal_trace_includes_by_iterator().
template<typename Key, typename TSplitter = Splitter< Key >, class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>, class UnorderedMapAllocator = std::allocator< std::pair<const Key, typename TSplitter::Word > >>
Attempts to insert an element into the set.
- Parameters
-
value | Element to be inserted. |
- Returns
- A pair, of which the first element is an iterator that points to the possibly inserted element, and the second is a bool that is true if the element was actually inserted.
This function attempts to insert an element into the set. A set relies on unique keys and thus an element is only inserted if it is not already present in the set.
Insertion requires amortized constant time.
Definition at line 656 of file UnorderedSetByBlock.h.
657 {
661 {
664 static_cast<Word>(1) <<
se.second ) );
667 }
668 else
669 {
670 bool exist =
it->second & (
static_cast<Word>(1) <<
se.second );
672 {
673 it->second |=
static_cast<Word>(1) <<
se.second;
675 }
677 }
678 }
Referenced by DGtal::UnorderedSetByBlock< Key, TSplitter, Hash, KeyEqual >::insert().
template<typename Key, typename TSplitter = Splitter< Key >, class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>, class UnorderedMapAllocator = std::allocator< std::pair<const Key, typename TSplitter::Word > >>
template<typename InputIterator>
void DGtal::UnorderedSetByBlock< Key, TSplitter, Hash, KeyEqual, UnorderedMapAllocator >::insert |
( |
InputIterator | first, |
|
|
InputIterator | last ) |
|
inline |
Inserts a range of element into the set.
- Template Parameters
-
InputIterator | any model of input iterator |
- Parameters
-
[in] | first | an iterator pointing on the first element of the range |
[in] | last | an iterator pointing after the last element of the range |
This function inserts a range of elements into the set. A set relies on unique keys and thus an element is only inserted if it is not already present in the set.
Each insertion requires amortized constant time.
Definition at line 694 of file UnorderedSetByBlock.h.
695 {
697 }
std::pair< iterator, bool > insert(const value_type &value)
Attempts to insert an element into the set.
template<typename Key, typename TSplitter = Splitter< Key >, class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>, class UnorderedMapAllocator = std::allocator< std::pair<const Key, typename TSplitter::Word > >>
Sets the number of buckets to the number needed to accomodate at least count elements without exceeding maximum load factor and rehashes the container, i.e. puts the elements into appropriate buckets considering that total number of buckets has changed. Effectively calls rehash(std::ceil(count /
max_load_factor())).
- Parameters
-
block_count | new capacity of the container (should be thought in terms of number of expected blocks). |
Definition at line 1087 of file UnorderedSetByBlock.h.
template<typename Key, typename TSplitter = Splitter< Key >, class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>, class UnorderedMapAllocator = std::allocator< std::pair<const Key, typename TSplitter::Word > >>
Exchanges the contents of the container with those of other. Does not invoke any move, copy, or swap operations on individual elements.
- Parameters
-
other | the other set to exchange with. |
- Note
- All iterators and references remain valid. The past-the-end iterator is invalidated. The Hash and KeyEqual objects must be Swappable, and they are exchanged using unqualified calls to non-member swap.
Definition at line 636 of file UnorderedSetByBlock.h.