ROSE 0.11.145.147
|
Unordered set of densely-packed integers.
This set is optimized to store integers from a range whose size is close to the cardinality of the set. For instance, if the set is intended to store integers in the range [100,199] and contains nearly 100 values at least at some point in its lifetime, then this is an appropriate container class to use for the set. Insert, erase, and existence testing are constant time, as are obtaining the beginning and end iterators and incrementing an iterator.
It is traditional to use an array or vector of Booleans to represent dense sets, but that approach results in poor iterator performance when the set happens to be sparse. This container avoids the poor iterator performance by also storing the members as a linked list (although it does so in a way that doesn't actually store the member values explicitly). But the "cost" of constant-time iteration is that the members of the set are not traversed in any particular order.
The combination of constant-time insert/erase/lookup and constant-time iterator increment makes this an ideal container for tree search algorithms where the set initially contains all vertex IDs but for most of the search the set is sparse.
Definition at line 39 of file DenseIntegerSet.h.
#include <Sawyer/DenseIntegerSet.h>
Classes | |
class | ConstIterator |
Bidirectional iterates over members of a set. More... | |
struct | Member |
Public Types | |
typedef T | Value |
Type of values stored in this container. | |
Public Member Functions | |
DenseIntegerSet () | |
Construct an empty set that cannot store any members. | |
DenseIntegerSet (const DenseIntegerSet &other) | |
Copy constructor. | |
DenseIntegerSet & | operator= (const DenseIntegerSet &other) |
Assignment operator. | |
boost::iterator_range< ConstIterator > | values () const |
Iterator range for set members. | |
bool | isEmpty () const |
Whether the set is empty. | |
size_t | size () const |
Number of members present. | |
Interval< Value > | domain () const |
Domain of storable values. | |
bool | isStorable (Value v) const |
Determines if a value is storable. | |
bool | exists (const Value &value) const |
Determines whether a value is stored. | |
template<class SawyerContainer > | |
bool | existsAny (const SawyerContainer &other) const |
Whether any value exists. | |
template<class SawyerContainer > | |
bool | existsAll (const SawyerContainer &other) const |
Whether all values exist. | |
template<class SawyerContainer > | |
bool | operator== (const SawyerContainer &other) const |
Whether two sets contain the same members. | |
template<class SawyerContainer > | |
bool | operator!= (const SawyerContainer &other) const |
Whether two sets do not contain the same members. | |
void | clear () |
Remove all members from this set. | |
bool | insert (Value value) |
Insert a value. | |
void | insertAll () |
Insert all possible members. | |
template<class SawyerContainer > | |
DenseIntegerSet | operator& (const SawyerContainer &other) const |
Compute the intersection of this set with another. | |
template<class SawyerContainer > | |
DenseIntegerSet | operator- (const SawyerContainer &other) const |
Compute the difference of this set with another. | |
Value | deref (const ConstIterator &iter) const |
DenseIntegerSet (const Interval< Value > &domain) | |
Construct an empty set that can hold values from the specified domain. | |
DenseIntegerSet (Value least, Value greatest) | |
Construct an empty set that can hold values from the specified domain. | |
DenseIntegerSet (Value n) | |
Construct an empty set that can hold values from the specified domain. | |
template<class SawyerContainer > | |
void | insertMany (const SawyerContainer &other) |
Insert many values from another set. | |
template<class SawyerContainer > | |
DenseIntegerSet & | operator|= (const SawyerContainer &other) |
Insert many values from another set. | |
template<class SawyerContainer > | |
DenseIntegerSet & | operator+= (const SawyerContainer &other) |
Insert many values from another set. | |
bool | erase (Value value) |
Erase a value. | |
ConstIterator | erase (const ConstIterator &iter) |
Erase a value. | |
template<class SawyerContainer > | |
void | eraseMany (const SawyerContainer &other) |
Erase many values. | |
template<class SawyerContainer > | |
DenseIntegerSet & | operator-= (const SawyerContainer &other) |
Erase many values. | |
template<class SawyerContainer > | |
void | intersect (const SawyerContainer &other) |
Intersect this set with another. | |
template<class SawyerContainer > | |
DenseIntegerSet & | operator&= (const SawyerContainer &other) |
Intersect this set with another. | |
template<class SawyerContainer > | |
DenseIntegerSet | operator| (const SawyerContainer &other) const |
Compute the union of this set with another. | |
template<class SawyerContainer > | |
DenseIntegerSet | operator+ (const SawyerContainer &other) const |
Compute the union of this set with another. | |
typedef T Sawyer::Container::DenseIntegerSet< T >::Value |
Type of values stored in this container.
Definition at line 55 of file DenseIntegerSet.h.
|
inline |
Construct an empty set that cannot store any members.
This object can only represent the empty set, but it's useful to have this default constructor in order to create a set that can be stored in a vector of sets, among other things.
Definition at line 65 of file DenseIntegerSet.h.
|
inlineexplicit |
Construct an empty set that can hold values from the specified domain.
Constructs a set whose members can be chosen from the specified domain. The domain can be specified as an interval, as a least and greated value, or as the number of values. If specified as the number of values, N, then the domain is zero through N-1, inclusive. The set is initially empty.
Definition at line 75 of file DenseIntegerSet.h.
References Sawyer::Container::DenseIntegerSet< T >::domain().
|
inline |
Construct an empty set that can hold values from the specified domain.
Constructs a set whose members can be chosen from the specified domain. The domain can be specified as an interval, as a least and greated value, or as the number of values. If specified as the number of values, N, then the domain is zero through N-1, inclusive. The set is initially empty.
Definition at line 82 of file DenseIntegerSet.h.
References Sawyer::Container::Interval< T >::isEmpty().
|
inlineexplicit |
Construct an empty set that can hold values from the specified domain.
Constructs a set whose members can be chosen from the specified domain. The domain can be specified as an interval, as a least and greated value, or as the number of values. If specified as the number of values, N, then the domain is zero through N-1, inclusive. The set is initially empty.
Definition at line 89 of file DenseIntegerSet.h.
|
inline |
Copy constructor.
Definition at line 97 of file DenseIntegerSet.h.
References Sawyer::Container::Interval< T >::greatest(), Sawyer::Container::DenseIntegerSet< T >::insert(), Sawyer::Container::Interval< T >::isEmpty(), Sawyer::Container::Interval< T >::least(), and Sawyer::Container::DenseIntegerSet< T >::values().
|
inline |
Assignment operator.
Assignment does not change the domain of the destination. If one of the members of other
is outside the domain of this container then an Exception::Domain
error is thrown and this object is not modified.
Definition at line 110 of file DenseIntegerSet.h.
References Sawyer::Container::DenseIntegerSet< T >::domain(), Sawyer::Container::DenseIntegerSet< T >::insert(), and Sawyer::Container::DenseIntegerSet< T >::values().
|
inline |
Iterator range for set members.
Returns an iterator range consiting of the begin and end iterators, in constant time.
Definition at line 255 of file DenseIntegerSet.h.
Referenced by Sawyer::Container::DenseIntegerSet< T >::DenseIntegerSet(), Sawyer::Container::Algorithm::graphFindConnectedComponents(), Sawyer::Container::Algorithm::graphIsConnected(), and Sawyer::Container::DenseIntegerSet< T >::operator=().
|
inline |
Whether the set is empty.
Returns true if the set is empty, false if not empty. This is a constant-time operation.
Definition at line 266 of file DenseIntegerSet.h.
Referenced by Sawyer::Container::DenseIntegerSet< T >::exists(), Sawyer::Container::Algorithm::graphFindConnectedComponents(), and Sawyer::Container::Algorithm::graphIsConnected().
|
inline |
Number of members present.
Returns the number of values currently contained in this set. This is a constant-time operation.
Definition at line 273 of file DenseIntegerSet.h.
Referenced by Sawyer::Container::DenseIntegerSet< T >::operator!=(), and Sawyer::Container::DenseIntegerSet< T >::operator==().
|
inline |
Domain of storable values.
Returns the set's domain, which is an interval describing which values can be possible members of this set.
Definition at line 280 of file DenseIntegerSet.h.
Referenced by Sawyer::Container::DenseIntegerSet< T >::DenseIntegerSet(), Sawyer::Container::DenseIntegerSet< T >::isStorable(), and Sawyer::Container::DenseIntegerSet< T >::operator=().
|
inline |
Determines if a value is storable.
Returns true if the specified value can be stored in this set, and false otherwise. A storable value is a value that falls within this set's domain.
Definition at line 288 of file DenseIntegerSet.h.
References Sawyer::Container::DenseIntegerSet< T >::domain().
Referenced by Sawyer::Container::DenseIntegerSet< T >::exists(), and Sawyer::Container::DenseIntegerSet< T >::insert().
|
inline |
Determines whether a value is stored.
Returns true if the specified value is a member of this set, false if the value is not stored in this set. This method returns false if the value is outside this set's domain.
Definition at line 296 of file DenseIntegerSet.h.
References Sawyer::Container::DenseIntegerSet< T >::isEmpty(), Sawyer::Container::DenseIntegerSet< T >::isStorable(), and Sawyer::Container::Interval< T >::least().
Referenced by Sawyer::Container::DenseIntegerSet< T >::erase(), Sawyer::Container::DenseIntegerSet< T >::existsAll(), Sawyer::Container::DenseIntegerSet< T >::existsAny(), and Sawyer::Container::DenseIntegerSet< T >::intersect().
|
inline |
Whether any value exists.
Returns true if any of the specified values exist in this set. This operation takes time that is linearly proportional to the number of items in the other
container.
Definition at line 308 of file DenseIntegerSet.h.
References Sawyer::Container::DenseIntegerSet< T >::exists().
|
inline |
Whether all values exist.
Returns true if all specified values exist in this set. This operation takes time that is linearly proportaional to teh number of items in the other
container.
Definition at line 321 of file DenseIntegerSet.h.
References Sawyer::Container::DenseIntegerSet< T >::exists().
Referenced by Sawyer::Container::DenseIntegerSet< T >::operator!=(), and Sawyer::Container::DenseIntegerSet< T >::operator==().
|
inline |
Whether two sets contain the same members.
Returns true if this set and other
contain exactly the same members.
Definition at line 333 of file DenseIntegerSet.h.
References Sawyer::Container::DenseIntegerSet< T >::existsAll(), and Sawyer::Container::DenseIntegerSet< T >::size().
|
inline |
Whether two sets do not contain the same members.
Returns true if this set and the other
set are not equal.
Definition at line 341 of file DenseIntegerSet.h.
References Sawyer::Container::DenseIntegerSet< T >::existsAll(), and Sawyer::Container::DenseIntegerSet< T >::size().
|
inline |
Remove all members from this set.
This operation is linear in the number of members currently present in the set.
Definition at line 352 of file DenseIntegerSet.h.
Referenced by Sawyer::Container::DenseIntegerSet< T >::intersect().
|
inline |
Insert a value.
Inserts the specified value in constant time. Returns true if the value was inserted and false if the value already existed. If the value is outside the domain then an Exception::DomainError is thrown.
Definition at line 366 of file DenseIntegerSet.h.
References Sawyer::Container::Interval< T >::greatest(), Sawyer::Container::Interval< T >::isEmpty(), Sawyer::Container::DenseIntegerSet< T >::isStorable(), and Sawyer::Container::Interval< T >::least().
Referenced by Sawyer::Container::DenseIntegerSet< T >::DenseIntegerSet(), Sawyer::Container::Algorithm::graphFindConnectedComponents(), Sawyer::Container::Algorithm::graphIsConnected(), Sawyer::Container::DenseIntegerSet< T >::insertMany(), Sawyer::Container::DenseIntegerSet< T >::intersect(), and Sawyer::Container::DenseIntegerSet< T >::operator=().
|
inline |
Insert all possible members.
Causes the set to contain all elements that are part of its domain.
Definition at line 392 of file DenseIntegerSet.h.
Referenced by Sawyer::Container::Algorithm::CommonSubgraphIsomorphism< GraphA, GraphB, SolutionProcessor, EquivalenceP >::reset().
|
inline |
Insert many values from another set.
Inserts all values of the other
container into this set.
Definition at line 418 of file DenseIntegerSet.h.
References Sawyer::Container::DenseIntegerSet< T >::insert().
Referenced by Sawyer::Container::DenseIntegerSet< T >::operator+=(), and Sawyer::Container::DenseIntegerSet< T >::operator|=().
|
inline |
Insert many values from another set.
Inserts all values of the other
container into this set.
Definition at line 424 of file DenseIntegerSet.h.
References Sawyer::Container::DenseIntegerSet< T >::insertMany().
|
inline |
Insert many values from another set.
Inserts all values of the other
container into this set.
Definition at line 430 of file DenseIntegerSet.h.
References Sawyer::Container::DenseIntegerSet< T >::insertMany().
|
inline |
Erase a value.
If a value is specified, then the value is erased and this method returns true if the value existed and false if it didn't exist (in which case this is a no-op). If a non-end iterator is specified, then the pointed to value is erased and the next iterator is returned.
Erasing is a constant-time operation.
Definition at line 445 of file DenseIntegerSet.h.
References Sawyer::Container::DenseIntegerSet< T >::exists(), and Sawyer::Container::Interval< T >::least().
Referenced by Sawyer::Container::DenseIntegerSet< T >::eraseMany(), Sawyer::Container::Algorithm::graphFindConnectedComponents(), and Sawyer::Container::Algorithm::graphIsConnected().
|
inline |
Erase a value.
If a value is specified, then the value is erased and this method returns true if the value existed and false if it didn't exist (in which case this is a no-op). If a non-end iterator is specified, then the pointed to value is erased and the next iterator is returned.
Erasing is a constant-time operation.
Definition at line 457 of file DenseIntegerSet.h.
|
inline |
Erase many values.
Erase those values from this set that are members of the other
container.
Definition at line 479 of file DenseIntegerSet.h.
References Sawyer::Container::DenseIntegerSet< T >::erase().
Referenced by Sawyer::Container::DenseIntegerSet< T >::operator-=().
|
inline |
Erase many values.
Erase those values from this set that are members of the other
container.
Definition at line 485 of file DenseIntegerSet.h.
References Sawyer::Container::DenseIntegerSet< T >::eraseMany().
|
inline |
Intersect this set with another.
Replaces this set with members that are only in this set and the other
set.
Definition at line 497 of file DenseIntegerSet.h.
References Sawyer::Container::DenseIntegerSet< T >::clear(), Sawyer::Container::DenseIntegerSet< T >::exists(), and Sawyer::Container::DenseIntegerSet< T >::insert().
Referenced by Sawyer::Container::DenseIntegerSet< T >::operator&=().
|
inline |
Intersect this set with another.
Replaces this set with members that are only in this set and the other
set.
Definition at line 507 of file DenseIntegerSet.h.
References Sawyer::Container::DenseIntegerSet< T >::intersect().
|
inline |
Compute the intersection of this set with another.
Returns a new set which has only those members that are common to this set and the other
set.
Definition at line 521 of file DenseIntegerSet.h.
|
inline |
Compute the union of this set with another.
Returns a new set containing the union of all members of this set and the other
set.
Definition at line 533 of file DenseIntegerSet.h.
|
inline |
Compute the union of this set with another.
Returns a new set containing the union of all members of this set and the other
set.
Definition at line 539 of file DenseIntegerSet.h.
|
inline |
Compute the difference of this set with another.
Returns a new set containing those elements of this
set that are not members of the other
set.
Definition at line 548 of file DenseIntegerSet.h.
|
inline |
Definition at line 559 of file DenseIntegerSet.h.