Template Class set_t

Inheritance Relationships

Base Type

  • public std::unordered_set< type >

Class Documentation

template<typename type>
class set_t : public std::unordered_set<type>

This simple class is used to store unordered sets of data. It is a simple wrapper for the std::unordered_set class, but it uses a shared mutex to lock the access to the set among other useful functions.

Public Types

using shared_ptr = std::shared_ptr<set_t<type>>

Shared pointer type.

Public Functions

inline set_t()

Empty constructor for the Visualization Set object.

inline set_t(type data_)

Construct a new set safe object from a single data point

Parameters:

data_ – Initial element inserted into the set during construction.

inline set_t(const set_t<type> &other_)

Copy constructor

Parameters:

other_ – Source set to copy from while holding a shared read lock.

inline ~set_t()

Destroy the Visualization Set object.

inline set_t<type> &operator=(const set_t<type> &other_)

Equal operator

Parameters:

other_ – Source set whose contents replace the current set.

Returns:

Reference to this set after the synchronized assignment.

inline void insert_(type id_)

Safe add a point to the set.

Parameters:

id_ – Element to insert while holding the write lock.

inline void erase_(type id_)

Safe remove a point from the set.

Parameters:

id_ – Element to remove while holding the write lock.

inline void clear_(const vector_t<type> &itemsToRemove_ = vector_t<type>())

Safe erase multiple points from the set. [all if empty]

Parameters:

itemsToRemove_ – Elements to erase; when empty, the whole set is cleared.

inline bool contains_(const type &value_) const

Safe check if the set contains a specific value.

Parameters:

value_ – Element to search for in the set.

Returns:

True when value_ is present, otherwise false.

inline void lock_read() const

This function is used to lock the entire set for reading purposes.

inline void unlock_read() const

To unlock the set after it was locked for reading.

inline void lock() const

This function is used to lock the entire set for writing purposes.

inline void unlock() const

To unlock the set after it was locked for writing.

inline int get_size_safe() const

Get the size of the set in a thread-safe manner.

Returns:

Number of elements currently stored in the set.

inline std::unordered_set<type> get_all() const

Get all elements in a thread-safe manner.

Returns:

Copy of the full unordered set at the time of the call.

inline vector_t<type> to_vector(const size_t size_ = 0) const

Convert to vector in a thread-safe manner.

Parameters:

size_ – Maximum number of elements to copy; 0 means copy al elements.

Returns:

Vector with up to size_ elements copied from the set.

inline operator vector_t<type>() const

Conversion operator to vector.

Public Static Functions

static inline set_t<type>::shared_ptr make_shared()

Make shared pointer function

Returns:

Shared pointer owning a new empty thread-safe unordered set.

Private Members

mutable std::shared_mutex _mutex

Mutex that is used to lock the set for reading and writing.