@@ -31,46 +31,41 @@ class IndirectionArray;
31
31
32
32
LOCK_FREE_ARRAY_TEMPLATE_ARGUMENTS
33
33
LOCK_FREE_ARRAY_TYPE::LockFreeArray (){
34
- new_lock_free_array. clear ( );
34
+ lock_free_array. reset ( new lock_free_array_t () );
35
35
}
36
36
37
37
LOCK_FREE_ARRAY_TEMPLATE_ARGUMENTS
38
38
LOCK_FREE_ARRAY_TYPE::~LockFreeArray (){
39
- new_lock_free_array.clear ();
40
39
}
41
40
42
41
LOCK_FREE_ARRAY_TEMPLATE_ARGUMENTS
43
42
bool LOCK_FREE_ARRAY_TYPE::Update (const std::size_t &offset, ValueType value){
44
43
PL_ASSERT (offset <= LOCK_FREE_ARRAY_MAX_SIZE);
45
44
LOG_TRACE (" Update at %lu" , lock_free_array_offset.load ());
46
- if (new_lock_free_array.size () < offset + 1 ) {
47
- new_lock_free_array.resize (LOCK_FREE_ARRAY_MAX_SIZE);
48
- }
49
- new_lock_free_array.at (offset) = value;
45
+ lock_free_array->at (offset) = value;
50
46
return true ;
51
47
}
52
48
53
49
LOCK_FREE_ARRAY_TEMPLATE_ARGUMENTS
54
50
bool LOCK_FREE_ARRAY_TYPE::Append (ValueType value){
55
51
LOG_TRACE (" Appended at %lu" , lock_free_array_offset.load ());
56
- new_lock_free_array. push_back (value) ;
52
+ lock_free_array-> at (lock_free_array_offset++) = value ;
57
53
return true ;
58
54
}
59
55
60
56
LOCK_FREE_ARRAY_TEMPLATE_ARGUMENTS
61
57
bool LOCK_FREE_ARRAY_TYPE::Erase (const std::size_t &offset, const ValueType& invalid_value){
62
58
PL_ASSERT (offset <= LOCK_FREE_ARRAY_MAX_SIZE);
63
59
LOG_TRACE (" Erase at %lu" , offset);
64
- new_lock_free_array. at (offset) = invalid_value;
60
+ lock_free_array-> at (offset) = invalid_value;
65
61
return true ;
66
62
}
67
63
68
64
LOCK_FREE_ARRAY_TEMPLATE_ARGUMENTS
69
65
ValueType LOCK_FREE_ARRAY_TYPE::Find (const std::size_t &offset) const {
70
66
PL_ASSERT (offset <= LOCK_FREE_ARRAY_MAX_SIZE);
71
67
LOG_TRACE (" Find at %lu" , offset);
72
- // auto value = lock_free_array->at(offset);
73
- auto value = new_lock_free_array.at (offset);
68
+ auto value = lock_free_array->at (offset);
74
69
return value;
75
70
}
76
71
@@ -82,11 +77,11 @@ ValueType LOCK_FREE_ARRAY_TYPE::FindValid(const std::size_t &offset,
82
77
83
78
std::size_t valid_array_itr = 0 ;
84
79
std::size_t array_itr;
85
- auto new_lock_free_array_offset = new_lock_free_array. size ();
80
+
86
81
for (array_itr = 0 ;
87
- array_itr < new_lock_free_array_offset ;
82
+ array_itr < lock_free_array_offset ;
88
83
array_itr++){
89
- auto value = new_lock_free_array. at (array_itr);
84
+ auto value = lock_free_array-> at (array_itr);
90
85
if (value != invalid_value) {
91
86
// Check offset
92
87
if (valid_array_itr == offset) {
@@ -103,26 +98,22 @@ ValueType LOCK_FREE_ARRAY_TYPE::FindValid(const std::size_t &offset,
103
98
104
99
LOCK_FREE_ARRAY_TEMPLATE_ARGUMENTS
105
100
size_t LOCK_FREE_ARRAY_TYPE::GetSize () const {
106
- return new_lock_free_array.size ();
107
- // return lock_free_array_offset;
101
+ return lock_free_array_offset;
108
102
}
109
103
110
104
LOCK_FREE_ARRAY_TEMPLATE_ARGUMENTS
111
105
bool LOCK_FREE_ARRAY_TYPE::IsEmpty () const {
112
- return new_lock_free_array.empty ();
113
- // return lock_free_array->empty();
106
+ return lock_free_array->empty ();
114
107
}
115
108
116
109
LOCK_FREE_ARRAY_TEMPLATE_ARGUMENTS
117
110
void LOCK_FREE_ARRAY_TYPE::Clear (const ValueType& invalid_value) {
118
111
119
112
// Set invalid value for all elements and reset lock_free_array_offset
120
-
121
113
for (std::size_t array_itr = 0 ;
122
- array_itr < new_lock_free_array. size () ;
114
+ array_itr < lock_free_array_offset ;
123
115
array_itr++){
124
- // lock_free_array->at(array_itr) = invalid_value;
125
- new_lock_free_array.at (array_itr) = invalid_value;
116
+ lock_free_array->at (array_itr) = invalid_value;
126
117
}
127
118
128
119
// Reset sentinel
@@ -136,9 +127,9 @@ bool LOCK_FREE_ARRAY_TYPE::Contains(const ValueType& value) {
136
127
bool exists = false ;
137
128
138
129
for (std::size_t array_itr = 0 ;
139
- array_itr < new_lock_free_array. size () ;
130
+ array_itr < lock_free_array_offset ;
140
131
array_itr++){
141
- auto array_value = new_lock_free_array. at (array_itr);
132
+ auto array_value = lock_free_array-> at (array_itr);
142
133
// Check array value
143
134
if (array_value == value) {
144
135
exists = true ;
0 commit comments