ra_set.hpp

This file defines a Random Access Set template.

Note

Status: ALPHA

template<typename T>
class ra_set
#include <ra_set.hpp>

This class uses a combination of a hashtable (std::unordered_map) and vector to lookup insert, lookup, and delete values in constant time, while still being able to step through all values (albeit in an arbitrary order).

Note

The arbitrary order of values may change if any values are deleted.

Public Types

using value_type = T

Public Functions

ra_set() = default
ra_set(const ra_set&) = default
ra_set(ra_set&&) = default
ra_set<T> &operator=(const ra_set&) = default
ra_set<T> &operator=(ra_set&&) = default
inline bool empty() const

Are there any values in this ra_set?

inline size_t size() const

How many elements are in this set?

inline const T &operator[](size_t pos) const

Index into the ra_set, similar to a vector.

inline void clear()

Remove all values from this container.

inline void insert(const T &v)

Insert a new value into container.

inline bool erase(const T &v)

Erase a specific value from the container.

inline size_t count(const T &v) const

Count the number of times a particular value in in the container (0 or 1).

Private Members

map<T, size_t> id_map

A map of where to find values in vector.

vector<T> vals

A vector of all values contained.