PeriDyno 1.0.0
Loading...
Searching...
No Matches
MultiSet.inl
Go to the documentation of this file.
1#include "Math/SimpleMath.h"
2#include <glm/glm.hpp>
3
4#include "STLMacro.h"
5
6namespace dyno
7{
8 template <typename T>
10 : STLBuffer()
11 {
12 }
13
14 template <typename T>
15 DYN_FUNC T* MultiSet<T>::find(T val)
16 {
17 int ind = leftBound(val, m_startLoc, m_size);
18
19 return ind >= m_size || m_startLoc[ind] != val ? nullptr : m_startLoc + ind;
20 }
21
22 template <typename T>
23 DYN_FUNC T* MultiSet<T>::insert(T val)
24 {
25 //return nullptr if the data buffer is full
26 if (m_size >= m_maxSize) return nullptr;
27
28 //return the index of the last element that is equal to or smaller than val
29 int ind = rightBound(val, m_startLoc, m_size);
30
31 int ind_plus = ind + 1;
32
33 //move all element backward
34 for (int j = m_size; j > ind_plus; j--)
35 {
36 m_startLoc[j] = m_startLoc[j - 1];
37 }
38
39 //insert val to ind-th location.
40 m_startLoc[ind_plus] = val;
41 m_size++;
42
43 return m_startLoc + ind_plus;
44 }
45
46 template <typename T>
47 DYN_FUNC void MultiSet<T>::clear()
48 {
49 m_size = 0;
50 }
51
52 template <typename T>
54 {
55 return m_size;
56 }
57
58 template <typename T>
60 {
61 int ind = leftBound(val, m_startLoc, m_size);
62 if (ind >= m_size) return 0;
63
64 size_t num = 0;
65 while (m_startLoc[ind] == val && ind < m_size)
66 {
67 num++;
68 ind++;
69 }
70
71 return num;
72 }
73
74 template <typename T>
75 DYN_FUNC bool MultiSet<T>::empty()
76 {
77 return m_startLoc == nullptr;
78 }
79}
80
DYN_FUNC iterator insert(T val)
Definition MultiSet.inl:23
DYN_FUNC bool empty()
Definition MultiSet.inl:75
DYN_FUNC iterator find(T val)
Definition MultiSet.inl:15
DYN_FUNC uint count(T val)
Definition MultiSet.inl:59
DYN_FUNC MultiSet()
Definition MultiSet.inl:9
DYN_FUNC uint size()
Definition MultiSet.inl:53
DYN_FUNC void clear()
Definition MultiSet.inl:47
DYN_FUNC STLBuffer()
Definition STLBuffer.h:19
#define T(t)
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
DYN_FUNC int leftBound(T target, T *startLoc, uint maxSize)
Find the left bound of a target with a binary search algorithm.
Definition STLMacro.h:22
unsigned int uint
Definition VkProgram.h:14
DYN_FUNC int rightBound(T target, T *startLoc, uint maxSize)
Find the right bound of a target with a binary search algorithm.
Definition STLMacro.h:54