NDEVR
API Documentation
Set.h
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Base
28File: Dictionary
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include <NDEVR/BaseValues.h>
34#include <NDEVR/LibAssert.h>
35#include <NDEVR/Buffer.h>
36#define NDEVR_USE_ROBIN_MAP 1
37#if NDEVR_USE_ROBIN_MAP
38#include "tsl/robin_set.h"
39#define SET_BASE tsl::robin_set
40#else
41#include <set>
42#define SET_BASE std::set
43#endif
44namespace NDEVR
45{
49 class SetBase
50 {};
51
57 template<class t_value>
58 class Set : public SET_BASE<t_value>, public SetBase
59 {
60 public:
65 : SET_BASE<t_value>()
66 {}
67
72 template<class t_iter>
73 Set(const t_iter& begin, const t_iter& end)
74 : SET_BASE<t_value>(begin, end)
75 {}
76
80 template<class t_type, class t_memory_manager>
82 : SET_BASE<t_value>(values.begin(), values.end())
83 {}
84
87 template<class t_type>
88 Set(std::initializer_list<t_type> l)
89 : SET_BASE<t_value>(l)
90 {}
91
96 [[nodiscard]] bool hasValue(const t_value& key) const
97 {
98 return SET_BASE<t_value>::find(key) != SET_BASE<t_value>::end();
99 }
100
104 void add(const t_value& key)
105 {
106 SET_BASE<t_value>::insert(key);
107 }
108
112 void add(t_value&& key)
113 {
114 SET_BASE<t_value>::insert(std::move(key));
115 }
116
120 template<class t_add_type>
121 void addAll(const Buffer<t_add_type>& key)
122 {
123 for (uint04 i = 0; i < key.size(); i++)
124 add(key[i]);
125 }
126
130 template<class t_index_type = uint04, class t_memory_manager = BufferAllocator<t_value, DetermineAlignment<sizeof(t_value)>(), ObjectInfo<t_value>::Primitive, t_index_type, false>>
132 {
134 for (const auto& kv : (*this))
135 values.add(kv);
136 return values;
137 }
138
143 [[nodiscard]] uint04 indexOf(const t_value& key) const
144 {
145 uint04 i = 0;
146 for (const auto& location : *this)
147 {
148 if (location.first == key)
149 return i;
150 i++;
151 }
152 return Constant<uint04>::Invalid;
153 }
154
158 [[nodiscard]] uint04 size() const
159 {
160 return cast<uint04>(SET_BASE<t_value>::size());
161 }
162 };
163}
164
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
A dummy base class for all Set templates.
Definition Set.h:50
void addAll(const Buffer< t_add_type > &key)
Inserts all elements from the given Buffer into the Set.
Definition Set.h:121
uint04 size() const
Returns the number of elements in the Set.
Definition Set.h:158
Set(const Buffer< t_type, t_memory_manager > &values)
Constructs a Set from a Buffer, inserting all Buffer elements.
Definition Set.h:81
Buffer< HyperGraphAction *, t_memory_manager > values() const
Definition Set.h:131
void add(const t_value &key)
Inserts a value into the Set by const reference.
Definition Set.h:104
Set()
Default constructor.
Definition Set.h:64
uint04 indexOf(const t_value &key) const
Finds the iteration index of a value within the Set.
Definition Set.h:143
bool hasValue(const t_value &key) const
Checks whether the Set contains the given value.
Definition Set.h:96
void add(t_value &&key)
Inserts a value into the Set by move.
Definition Set.h:112
Set(const t_iter &begin, const t_iter &end)
Constructs a Set from an iterator range.
Definition Set.h:73
Set(std::initializer_list< t_type > l)
Constructor that allows for an initializer list, allowing { and } to be used.
Definition Set.h:88
The primary namespace for the NDEVR SDK.
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
constexpr t_to cast(const Angle< t_from > &value)
Casts an Angle from one backing type to another.
Definition Angle.h:408
Information about the object.
Definition ObjectInfo.h:55