NDEVR
API Documentation
BufferFunctions.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: BufferFunctions
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include <NDEVR/Buffer.h>
34#include <algorithm>
35namespace NDEVR
36{
43 {};
44
47 template <class t_type, class t_buffer>
49 {
50 protected:
51 t_buffer* m_container;
53 public:
54 using iterator_category = std::random_access_iterator_tag;
55 using value_type = t_type;
56 using difference_type = ptrdiff_t;
57 using pointer = t_type*;
58 using reference = t_type&;
59
65 explicit BufferInsertIterator(t_buffer& container, int i)
66 : m_container(&container)
67 , m_location(i)
68 {}
69
76 {
77 m_container->add(m_location, value);
78 ++m_location;
79 return *this;
80 }
81
87 {
88 m_container->add(m_location, std::move(value));
89 ++m_location;
90 return *this;
91 }
92
97 {
98 m_location++;
100 lib_assert(m_location <= m_container->size(), "iterator going off edge");
101 return *this;
102 }
103
109 {
110 m_location += cast<uint04>(val);
112 lib_assert(m_location <= m_container->size(), "iterator going off edge");
113 return *this;
114 }
115
120 {
121 return *this;
122 }
123
128 {
129 return *this;
130 }
131 };
132
138 template<class t_type, class t_memory_manager>
140 {
141 Buffer<t_type, t_memory_manager> intersect_buf = a;
143 auto final_iter = std::set_intersection(a.begin(), a.end(), b.begin(), b.end(), iter);
144 intersect_buf.setSize(cast<uint04>(final_iter - intersect_buf.begin()));
145 return intersect_buf;
146 }
147
153 template<class t_type, class t_memory_manager>
155 {
156 lib_assert(a.isSorted(), "A is not sorted");
157 lib_assert(b.isSorted(), "B is not sorted");
158 if (b.size() == 0)
159 return a;
160 if (a.size() == 0)
164 std::set_difference(a.begin(), a.end(), b.begin(), b.end(), iter);
165 return intersect_buf;
166 }
167
174 template<class t_type, class t_memory_manager>
176 {
177 Buffer<t_type, t_memory_manager> union_buf(a.size() + b.size());
178 union_buf.addAll(a);
179 union_buf.addAll(b);
180 union_buf.makeUnique();
181 return union_buf;
182 }
183
190 template<class t_type, class t_memory_manager>
192 {
195 a_sorted.sort();
196 b_sorted.sort();
197 a_sorted.setUniquePresorted();
198 b_sorted.setUniquePresorted();
199 return IntersectSorted(a_sorted, b_sorted);
200 }
201
207 template<class t_type, class t_memory_manager>
209 {
210 Buffer<t_type, t_memory_manager> intersect_buf = a;
211 for (uint04 i = a.size() - 1; IsValid(i); i--)
212 {
213 if (!b.contains(a[i]))
214 intersect_buf.removeIndex(i);
215 }
216 return intersect_buf;
217 }
218
224 template<class t_type, class t_memory_manager>
226 {
229 a_sorted.sort();
230 b_sorted.sort();
231 a_sorted.setUniquePresorted();
232 b_sorted.setUniquePresorted();
233 return ExceptSorted(a_sorted, b_sorted);
234 }
235
236
237
238}
239
A dummy class to include complex Buffer insert and sort functions Functions that enhance the function...
Used by stl library to insert objects into the buffer.
ptrdiff_t difference_type
Type used for iterator difference calculations.
BufferInsertIterator< t_type, t_buffer > & operator++()
Pre-increment operator.
t_type & reference
Reference type for the value type.
BufferInsertIterator(t_buffer &container, int i)
Constructs a BufferInsertIterator at a given position.
BufferInsertIterator< t_type, t_buffer > & operator++(int val)
Post-increment operator.
const BufferInsertIterator< t_type, t_buffer > & operator*() const
Const dereference operator.
uint04 m_location
Current insertion index within the buffer.
std::random_access_iterator_tag iterator_category
STL iterator category tag.
t_buffer * m_container
Pointer to the buffer being inserted into.
BufferInsertIterator< t_type, t_buffer > & operator*()
Dereference operator.
t_type * pointer
Pointer type for the value type.
BufferInsertIterator< t_type, t_buffer > & operator=(t_type &&value)
Moves the given value into the buffer at the current location and advances the iterator.
t_type value_type
The type of elements being inserted.
BufferInsertIterator< t_type, t_buffer > & operator=(const t_type &value)
Inserts a copy of the given value at the current location and advances the iterator.
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
The primary namespace for the NDEVR SDK.
constexpr t_type getMin(const t_type &left, const t_type &right)
Finds the minimum of the given arguments based on the < operator Author: Tyler Parke Date: 2017-11-05...
static constexpr bool IsValid(const Angle< t_type > &value)
Checks whether the given Angle holds a valid value.
Definition Angle.h:398
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Buffer< t_type, t_memory_manager > Except(const Buffer< t_type, t_memory_manager > &a, const Buffer< t_type, t_memory_manager > &b)
Returns elements in buffer a that are not in buffer b, sorting both buffers first.
Buffer< t_type, t_memory_manager > IntersectPreserveOrderA(const Buffer< t_type, t_memory_manager > &a, const Buffer< t_type, t_memory_manager > &b)
Computes the intersection of two buffers while preserving the order of elements from buffer a.
Buffer< t_type, t_memory_manager > Union(const Buffer< t_type, t_memory_manager > &a, const Buffer< t_type, t_memory_manager > &b)
Computes the union of two buffers, removing duplicate elements.
Buffer< t_type, t_memory_manager > Intersect(const Buffer< t_type, t_memory_manager > &a, const Buffer< t_type, t_memory_manager > &b)
Computes the intersection of two unsorted buffers by sorting them first.
Buffer< t_type, t_memory_manager > IntersectSorted(const Buffer< t_type, t_memory_manager > &a, const Buffer< t_type, t_memory_manager > &b)
Computes the intersection of two pre-sorted buffers using std::set_intersection.
Buffer< t_type, t_memory_manager > ExceptSorted(const Buffer< t_type, t_memory_manager > &a, const Buffer< t_type, t_memory_manager > &b)
Returns the elements from sorted buffer a which are not found in sorted buffer b.
constexpr t_to cast(const Angle< t_from > &value)
Casts an Angle from one backing type to another.
Definition Angle.h:408