acme
Foundational cross-platform layer of the ca2 framework
Toggle main menu visibility
Loading...
Searching...
No Matches
unique_array.h
1
#pragma once
2
3
template
<
class
TYPE,
class
ARG_TYPE = const TYPE &,
class
BASE_ARRAY = array < TYPE, ARG_TYPE >,
class
COMPARE = ::comparison::less < TYPE, ARG_TYPE > >
4
class
unique_sort_array :
5
protected
BASE_ARRAY
6
{
7
public
:
8
unique_sort_array(
::particle
* pparticle =
nullptr
);
9
unique_sort_array(
const
unique_sort_array & array);
10
11
virtual ::collection::index add(ARG_TYPE newElement)
12
{
13
auto
pFind = 0;
14
if
(find(newElement, iFind))
15
{
16
return
-1;
17
}
18
else
19
{
20
this->insert_at(iFind, newElement);
21
return
iFind;
22
}
23
}
24
25
bool
find(ARG_TYPE t, index & find)
const
26
{
27
::collection::index iL = find;
28
::collection::index iU = this->get_upper_bound();
29
while
(iU - iL > 5)
30
{
31
find = (iL + iU) / 2;
32
if
(COMPARE::compare(t, this->element_at(find)))
33
{
34
iU = find - 1;
35
}
36
else
if
(COMPARE::compare(this->element_at(find), t))
37
{
38
iL = find + 1;
39
}
40
else
41
{
42
return
true
;
43
}
44
}
45
for
(; find >= 0; find--)
46
{
47
if
(COMPARE::compare(this->element_at(find), t))
48
{
49
break
;
50
}
51
}
52
for
(; find < this->get_size(); find++)
53
{
54
if
(COMPARE::compare(t, this->element_at(find)))
55
{
56
return
false
;
57
}
58
else
if
(COMPARE::compare(this->element_at(find), t))
59
{
60
}
61
else
62
{
63
return
true
;
64
}
65
}
66
return
false
;
67
}
68
69
void
clear()
70
{
71
BASE_ARRAY::clear();
72
}
73
74
void
erase_all()
75
{
76
BASE_ARRAY::erase_all();
77
}
78
79
};
80
81
82
template
<
typename
TYPE >
83
class
unique_array :
84
protected
array < TYPE >
85
{
86
public
:
87
unique_array(::particle * pparticle =
nullptr
);
88
unique_array(
const
unique_array & array);
89
90
virtual ::collection::index add(TYPE newElement)
91
{
92
auto
pFind = 0;
93
if
(find(newElement, iFind))
94
{
95
return
-1;
96
}
97
else
98
{
99
insert_at(iFind, newElement);
100
return
iFind;
101
}
102
}
103
104
bool
find(
const
TYPE &t, index & find)
const
105
{
106
for
(; find < this->get_size(); find++)
107
{
108
if
(this->element_at(find) == t)
109
break
;
110
}
111
return
find;
112
}
113
114
};
particle
Definition
particle.h:95
prototype
collection
unique_array.h
Generated by
1.17.0