Molassembler  1.0.0
Molecule graph and conformer library
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Scine::Molassembler::Temple::TinyUnorderedSet< T > Struct Template Reference

An adapter class for std::vector that acts like an unordered set and stores its data in the underlying vector in an unordered fashion. More...

#include <TinySet.h>

Public Types

Types
using UnderlyingContainer = std::vector< T >
 The type of the underlying container with linear memory.
 
using value_type = T
 What types this container stores.
 
using reference = T &
 Reference to a value_type.
 
using const_reference = const T &
 Const reference to a value type.
 
using iterator = typename std::vector< T >::iterator
 Iterator type.
 
using const_iterator = typename std::vector< T >::const_iterator
 Const iterator type.
 

Public Member Functions

Constructors
 TinyUnorderedSet ()
 Default constructor.
 
 TinyUnorderedSet (std::initializer_list< T > list)
 Initializer-list constructor.
 
Modification
void clear ()
 Empties the set.
 
void insert (T a)
 Inserts an element into the set. More...
 
template<typename... Args>
void emplace (Args &&...args)
 Emplaces an element into the set. More...
 
template<typename It >
void erase (It a)
 Erases a position in the set.
 
template<typename It >
void insert (It a, const It &b)
 Inserts all elements contained in a range.
 
void reserve (std::size_t size)
 Reserves space in memory.
 
Information
unsigned count (T a) const
 Counts the number of occurrences of an element.
 
std::size_t size () const
 Returns the number of elements in the set.
 
bool empty () const
 Returns whether the set is empty.
 
Iterators
iterator begin ()
 Yields a begin iterator.
 
iterator end ()
 Yields an end iterator.
 
const_iterator begin () const
 Yields a begin const iterator.
 
const_iterator end () const
 Yields an end const iterator.
 
const_iterator cbegin () const
 Yields a begin const iterator.
 
const_iterator cend () const
 Yields an end const iterator.
 

Static Public Member Functions

Static functions
static bool checked_insert (std::vector< T > &set, T a)
 Inserts an element only if the element is not already in the set. More...
 
template<typename... Args>
static void checked_emplace (std::vector< T > &set, Args &&...args)
 Checked emplace of an element into a set. More...
 
static bool linear_search (std::vector< T > &set, const T &value)
 Linear search for a value. More...
 

Data Fields

State
UnderlyingContainer data
 The owned underlying linear memory container.
 

Detailed Description

template<typename T>
struct Scine::Molassembler::Temple::TinyUnorderedSet< T >

An adapter class for std::vector that acts like an unordered set and stores its data in the underlying vector in an unordered fashion.

Why? It's a lot simpler / smaller than unordered_set and seems to be faster for very small amounts of data. Break-even with an unordered_set for finding a value is at around N = 80 for numeric types, although I certainly do not trust the benchmark much.

Template Parameters
Theset value type

Member Function Documentation

template<typename T >
template<typename... Args>
static void Scine::Molassembler::Temple::TinyUnorderedSet< T >::checked_emplace ( std::vector< T > &  set,
Args &&...  args 
)
inlinestatic

Checked emplace of an element into a set.

In-place constructs a T, then checks if it already exists in the set. If it does, it is removed again.

Template Parameters
ArgsParameter pack to forward to T's constructor
Parameters
setSet to insert the element into
argsArguments to forward to T's constructor
template<typename T >
static bool Scine::Molassembler::Temple::TinyUnorderedSet< T >::checked_insert ( std::vector< T > &  set,
a 
)
inlinestatic

Inserts an element only if the element is not already in the set.

Parameters
setSet to insert the element into
aElement to insert
Returns
Whether the element was already in the set
template<typename T >
template<typename... Args>
void Scine::Molassembler::Temple::TinyUnorderedSet< T >::emplace ( Args &&...  args)
inline

Emplaces an element into the set.

Note
You can use this just like std::vector::emplace_back
Warning
This does not check if the element already exists
template<typename T >
void Scine::Molassembler::Temple::TinyUnorderedSet< T >::insert ( a)
inline

Inserts an element into the set.

Warning
This does not check if the element already exists.
template<typename T >
static bool Scine::Molassembler::Temple::TinyUnorderedSet< T >::linear_search ( std::vector< T > &  set,
const T &  value 
)
inlinestatic

Linear search for a value.

Parameters
setSet to search
valueValue to look for
Returns
Whether the value was found

The documentation for this struct was generated from the following file: