PeriDyno 1.0.0
Loading...
Searching...
No Matches
Map.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 MKey, typename T>
10 {
11 }
12
13 template <typename MKey, typename T>
15 {
16 int ind=leftBound(Pair<MKey,T> (key,T()), m_pairs, m_size);
17 return (ind >= m_size || m_pairs[ind] != Pair<MKey, T>(key, T())) ? nullptr : (m_pairs + ind);
18 }
19
20
21 template <typename MKey, typename T>
23 {
24 //return nullptr if the data buffer is full
25 if (m_size >= m_maxSize) return nullptr;
26
27 //return the index of the first element that is equel to or biger than val
28 int t = leftBound(pair, m_pairs, m_size);
29
30 //if the key is equel, do not insert
31 if (m_pairs[t] == pair)
32 return m_pairs + t;
33
34 //insert val to t location
35 for (int j = m_size; j > t; j--)
36 {
37 m_pairs[j] = m_pairs[j - 1];
38 }
39 m_pairs[t] = pair;
40 m_size++;
41
42 return m_pairs + t;
43 }
44
45 template <typename MKey, typename T>
46 DYN_FUNC void Map<MKey, T>::clear()
47 {
48 m_size = 0;
49 }
50
51 template <typename MKey, typename T>
53 {
54 return m_size;
55 }
56
57 template <typename MKey, typename T>
58 DYN_FUNC bool Map<MKey, T>::empty()
59 {
60 return m_pairs == nullptr;
61 }
62}
63
DYN_FUNC iterator find(MKey key)
Definition Map.inl:14
uint m_maxSize
Definition Map.h:63
DYN_FUNC void clear()
Definition Map.inl:46
DYN_FUNC Map()
Definition Map.inl:9
DYN_FUNC iterator insert(Pair< MKey, T > pair)
Definition Map.inl:22
Pair< MKey, T > * m_pairs
Definition Map.h:62
DYN_FUNC bool empty()
Definition Map.inl:58
uint m_size
Definition Map.h:60
DYN_FUNC uint size()
Definition Map.inl:52
#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