PIP 5.9.0
Platform-Independent Primitives
Loading...
Searching...
No Matches
PISet< T > Class Template Reference

Set of unique values. More...

#include <piset.h>

Inheritance diagram for PISet< T >:

Classes

class  const_iterator
 Constant iterator over PISet elements. More...

Public Member Functions

 PISet ()
 Constructs an empty set.
 PISet (const T &value)
 Constructs a set containing value.
 PISet (const T &v0, const T &v1)
 Constructs a set containing v0 and v1.
 PISet (const T &v0, const T &v1, const T &v2)
 Constructs a set containing v0, v1 and v2.
 PISet (const T &v0, const T &v1, const T &v2, const T &v3)
 Constructs a set containing v0, v1, v2 and v3.
const_iterator begin () const
 Returns iterator to the first element.
const_iterator end () const
 Returns iterator following the last element.
 PISet (const PIVector< T > &values)
 Constructs a set from vector values.
 PISet (const PIDeque< T > &values)
 Constructs a set from deque values.
PISet< T > & operator<< (const T &t)
 Inserts t into the set.
PISet< T > & operator<< (T &&t)
 Moves t into the set.
PISet< T > & operator<< (const PISet< T > &other)
 Inserts all elements from other.
bool contains (const T &t) const
 Tests whether element t exists in the set.
bool operator[] (const T &t) const
 Checks whether element t exists in the set.
PISet< T > & remove (const T &t)
 Removes element t from the set.
PISet< T > & unite (const PISet< T > &v)
 Unites the set with v.
PISet< T > & subtract (const PISet< T > &v)
 Removes all elements present in v.
PISet< T > & intersect (const PISet< T > &v)
 Leaves only elements also present in v.
PISet< T > & operator+= (const PISet< T > &v)
 Same as unite().
PISet< T > & operator|= (const PISet< T > &v)
 Same as unite().
PISet< T > & operator-= (const PISet< T > &v)
 Same as subtract().
PISet< T > & operator&= (const PISet< T > &v)
 Same as intersect().
PIVector< T > toVector () const
 Returns set contents as PIVector.
PIDeque< T > toDeque () const
 Returns set contents as PIDeque.
Public Member Functions inherited from PIMap< T, uchar >
 PIMap ()
 Constructs an empty map.
 PIMap (const PIMap< T, uchar > &other)
 Copy constructor.
 PIMap (PIMap< T, uchar > &&other)
 Move constructor.
 PIMap (std::initializer_list< std::pair< T, uchar > > init_list)
 Contructs map from C++11 initializer list.
PIMap< T, uchar > & operator= (const PIMap< T, uchar > &other)
 Assign operator.
PIMap< T, uchar > & operator= (PIMap< T, uchar > &&other)
 Assign move operator.
iterator begin ()
 Iterator to the first element.
iterator end ()
 Iterator to the element following the last element.
reverse_iterator rbegin ()
 Returns a reverse iterator to the last map entry.
reverse_iterator rend ()
 Returns a reverse iterator to the position before the first map entry.
size_t size () const
 Number of entries in the map.
int size_s () const
 Number of entries in the map as a signed value.
size_t length () const
 Same as size().
bool isEmpty () const
 Checks whether the map is empty.
bool isNotEmpty () const
 Checks whether the map contains entries.
uchar & operator[] (const T &key)
 Full access to element key key.
const uchar & at (const T &key) const
 Read only access to element by key.
uchar take (const T &key, const uchar &default_=uchar())
 Removes entry with key key and returns its value.
PIMap< T, uchar > & operator<< (const PIMap< T, uchar > &other)
 Inserts all entries from other, overwriting existing keys.
bool operator== (const PIMap< T, uchar > &m) const
 Compares this map with m.
bool operator!= (const PIMap< T, uchar > &m) const
 Compares this map with m.
bool contains (const T &key) const
 Checks whether the map contains key key.
bool containsValue (const uchar &value) const
 Checks whether the map contains value value.
PIMap< T, uchar > & reserve (size_t new_size)
 Attempts to allocate memory for at least new_size elements.
PIMap< T, uchar > & remove (const T &key)
 Removes entry with key key.
PIMap< T, uchar > & removeWhere (std::function< bool(const T &key, const uchar &value)> test)
 Removes all entries passes the test implemented by the provided function test.
PIMap< T, uchar > & erase (const T &key)
 Same as remove().
PIMap< T, uchar > & clear ()
 Clears the map.
void swap (PIMap< T, uchar > &other)
 Swaps this map with other.
PIMap< T, uchar > & insert (const T &key, const uchar &value)
 Inserts value value for key key.
PIMap< T, uchar > & insert (const PIPair< T, uchar > &pair)
 Inserts entry pair.
uchar value (const T &key, const uchar &default_=uchar()) const
 Returns the value of the element by the key key or default_ if there is no such element.
PIVector< uchar > values () const
 Returns values of all map entries.
T key (const uchar &value, const T &default_=T()) const
 Returns the key of the first element whose value matches value or default_ if there is no such element.
PIVector< T > keys () const
 Returns keys of all map entries.
void forEach (std::function< void(const T &key, const uchar &value)> f) const
 Calls f for every map entry.
PIMap< Key2, T2 > map (std::function< PIPair< Key2, T2 >(const T &key, const uchar &value)> f) const
 Creates a new PIMap from results of applying f to each map entry.
PIVector< ST > map (std::function< ST(const T &key, const uchar &value)> f) const
 Creates a new PIVector from results of applying f to each map entry.
PIMap< T, uchar > filter (std::function< bool(const T &key, const uchar &value)> test) const
 Returns a new map with all entries that pass the test implemented by the provided function bool test(const Key & key, const T & value).

(Note that these are not member symbols.)

template<typename T>
PISet< T > operator+ (const PISet< T > &v0, const PISet< T > &v1)
 Returns union of two sets.
template<typename T>
PISet< T > operator- (const PISet< T > &v0, const PISet< T > &v1)
 Returns difference of two sets.
template<typename T>
PISet< T > operator| (const PISet< T > &v0, const PISet< T > &v1)
 Returns union of two sets.
template<typename T>
PISet< T > operator& (const PISet< T > &v0, const PISet< T > &v1)
 Returns intersection of two sets.
template<typename Type>
PICout operator<< (PICout s, const PISet< Type > &v)
 Output operator to PICout.

Detailed Description

template<typename T>
class PISet< T >

Set of unique values.

This class is used to store a collection of unique elements of any type. You can add values to the set using operator<< or the insert() function. You can check if a value already exists in the set using operator[] or the contains() function. These operations have logarithmic complexity. To iterate over all elements, use STL-style iterators begin() and end().

The set is implemented as a wrapper around PIMap, where keys are the elements and values are dummy byte values (used only for storage).

See also
PIMap, PIVector