File sparse-set.hh¶
-
namespace mata
Main namespace including structs and algorithms for all automata.
In particular, this includes:
Alphabets,
Formula graphs and nodes,
Closed sets.
-
namespace utils
SparseSet.h Implements a class template of a sparse set of unsigned integers.
Non-automata-related structures and algorithms.
In particular, this includes:
Predicates,
Ordered Vectors,
Iterators,
Printers,
Other helper functions.
- Author
Sam Griffiths www.computist.xyz https://gist.github.com/sjgriffiths/06732c6076b9db8a7cf4dfe3a7aed43a
-
template<typename Number>
class SparseSet - #include <sparse-set.hh>
Implementation of a set of non-negative numbers using sparse-set.
This class implements the interface of a set (similar to std::set) using sparse-set date structure, that is, a pair of vectors dense and sparse (… google it). Importantly
Insertion and removal are constant time.
Iteration is linear in the number of stored elements.
It takes a lot of space, the sparse and dense vectors allocate as many indexes as the maximal stored number.
- Template Parameters:
Number – Number type: type of numbers contained in the container.
Public Types
Public Functions
-
inline const_iterator begin() const¶
-
inline const_iterator end() const¶
-
inline size_t size() const¶
-
inline size_t domain_size() const¶
-
inline bool empty() const¶
-
inline void clear()¶
-
inline void reserve(size_t u)¶
-
inline void erase_nocheck(const Number number)
Erase
numberfrom the set without checking for its existence.- Parameters:
number – Number to be erased.
- Pre:
numberexists in the set.
-
SparseSet() = default
New Mata code.
-
inline explicit SparseSet(Number domain_size)
Basic constructor where you may reserve a domain size.
-
template<class InputIterator>
inline explicit SparseSet(InputIterator first, InputIterator last)¶
-
inline explicit SparseSet(const BoolVector &bv)¶
-
inline bool consistent()¶
-
inline bool operator[](Number q) const
- Returns:
True if predicate for
qis set. False otherwise (even if q is out of range of the predicate).
-
template<class InputIterator>
inline void insert(InputIterator first, InputIterator last)¶
-
template<class InputIterator>
inline void erase(InputIterator first, InputIterator last)¶
-
inline void sort()¶
-
inline Number max()
Maximal Number in set.
Expensive operation as it has to compute the maximal Number in linear time.
-
inline void truncate()¶
Private Members
-
size_t size_ = 0¶
Number of elements which are in the set (current size).
-
size_t domain_size_ = 0¶
Over-approximation of Number in sparse set. It represents the Numbers which were in the set throughout the life of the set until now.
truncate()will update the domain size to the current maximal Number + 1. Constructor can preallocate the sparse set and set domain size to the requested value. The structures are preallocated to at leastdomain_size_size (can be more when maximal Number is removed).