Skip to content

Commit d601ad2

Browse files
authored
bug fix and file division
1 parent af06f9a commit d601ad2

15 files changed

+178404
-177942
lines changed

_simdjson.cpp

+56,457-56,457
Large diffs are not rendered by default.

_simdjson.h

+117,318-117,318
Large diffs are not rendered by default.

claujson.cpp

+1,016-2,742
Large diffs are not rendered by default.

claujson.h

+160-1,227
Large diffs are not rendered by default.

claujson_array.cpp

+337
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,337 @@
1+
2+
#include "claujson.h"
3+
4+
namespace claujson {
5+
6+
extern Log log;
7+
_Value Array::data_null{ nullptr, false }; // valid is false..
8+
const uint64_t Array::npos = -1; //
9+
10+
Array* Array::clone() const {
11+
Array* result = new (std::nothrow) Array();
12+
13+
if (result == nullptr) {
14+
return nullptr;
15+
}
16+
17+
uint64_t sz = this->get_data_size();
18+
for (uint64_t i = 0; i < sz; ++i) {
19+
auto x = this->get_value_list(i).clone();
20+
result->add_element(std::move(x));
21+
}
22+
23+
return result;
24+
}
25+
26+
27+
void Array::set_parent(StructuredPtr p) {
28+
parent = p;
29+
}
30+
31+
_Value Array::Make() {
32+
Array* temp = (new (std::nothrow) Array());
33+
34+
if (temp == nullptr) {
35+
_Value v;
36+
v._type = _ValueType::ERROR;
37+
return v;
38+
}
39+
40+
return _Value(temp);
41+
}
42+
43+
_Value Array::MakeVirtual() {
44+
Array* temp = (new (std::nothrow) Array());
45+
46+
if (temp == nullptr) {
47+
_Value v;
48+
v._type = _ValueType::ERROR;
49+
return v;
50+
}
51+
temp->_is_virtual = true;
52+
return _Value(temp);
53+
}
54+
55+
Array::Array() {}
56+
57+
#ifdef USE_PMR
58+
Array::Array(std::pmr::memory_resource* res) : arr_vec(res) {
59+
//
60+
}
61+
#endif
62+
63+
Array::~Array() {
64+
for (auto& x : arr_vec) {
65+
if (x.is_array()) {
66+
delete x.as_array();
67+
}
68+
else if (x.is_object()) {
69+
delete x.as_object();
70+
}
71+
}
72+
}
73+
74+
bool Array::is_object() const {
75+
return false;
76+
}
77+
bool Array::is_array() const {
78+
return true;
79+
}
80+
81+
uint64_t Array::find(const _Value& value, uint64_t start) const {
82+
uint64_t sz = size();
83+
for (uint64_t i = start; i < sz; ++i) {
84+
if (get_value_list(i) == value) {
85+
return i;
86+
}
87+
}
88+
return npos;
89+
}
90+
91+
_Value& Array::operator[](uint64_t idx) {
92+
return this->get_value_list(idx);
93+
}
94+
95+
const _Value& Array::operator[](uint64_t idx) const {
96+
return this->get_value_list(idx);
97+
}
98+
99+
const StructuredPtr Array::get_parent() const {
100+
return this->parent;
101+
}
102+
103+
uint64_t Array::get_data_size() const {
104+
return arr_vec.size();
105+
}
106+
107+
_Value& Array::get_value_list(uint64_t idx) {
108+
return arr_vec[idx];
109+
}
110+
111+
_Value& Array::get_key_list(uint64_t idx) {
112+
return data_null;
113+
}
114+
115+
const _Value& Array::get_const_key_list(uint64_t idx) {
116+
return data_null;
117+
}
118+
119+
const _Value& Array::get_const_key_list(uint64_t idx) const {
120+
return data_null;
121+
}
122+
123+
124+
const _Value& Array::get_value_list(uint64_t idx) const {
125+
return arr_vec[idx];
126+
}
127+
128+
const _Value& Array::get_key_list(uint64_t idx) const {
129+
return data_null;
130+
}
131+
132+
void Array::clear(uint64_t idx) {
133+
arr_vec[idx].clear(false);
134+
}
135+
136+
bool Array::is_virtual() const {
137+
return _is_virtual;
138+
}
139+
void Array::clear() {
140+
arr_vec.clear();
141+
}
142+
143+
void Array::reserve_data_list(uint64_t len) {
144+
arr_vec.reserve(len);
145+
}
146+
147+
148+
Array::_ValueIterator Array::begin() {
149+
return arr_vec.begin();
150+
}
151+
152+
Array::_ValueIterator Array::end() {
153+
return arr_vec.end();
154+
}
155+
156+
157+
Array::_ConstValueIterator Array::begin() const {
158+
return arr_vec.begin();
159+
}
160+
161+
Array::_ConstValueIterator Array::end() const {
162+
return arr_vec.end();
163+
}
164+
165+
bool Array::add_element(Value val) {
166+
167+
if (val.Get().is_array()) {
168+
val.Get().as_array()->set_parent(this);
169+
}
170+
else if (val.Get().is_object()) {
171+
val.Get().as_object()->set_parent(this);
172+
}
173+
174+
arr_vec.push_back(std::move(val.Get()));
175+
176+
return true;
177+
}
178+
179+
bool Array::assign_element(uint64_t idx, Value val) {
180+
if (val.Get().is_array()) {
181+
val.Get().as_array()->set_parent(this);
182+
}
183+
else if (val.Get().is_object()) {
184+
val.Get().as_object()->set_parent(this);
185+
}
186+
187+
arr_vec[idx] = (std::move(val.Get()));
188+
189+
return true;
190+
}
191+
192+
193+
void Array::erase(const _Value& key, bool real) {
194+
uint64_t idx = this->find(key);
195+
erase(idx, real);
196+
}
197+
198+
void Array::erase(uint64_t idx, bool real) {
199+
200+
if (real) {
201+
clean(arr_vec[idx]);
202+
}
203+
204+
arr_vec.erase(arr_vec.begin() + idx);
205+
}
206+
207+
208+
void Array::MergeWith(Array* j, int start_offset) {
209+
auto* x = j;
210+
211+
uint64_t len = j->get_data_size();
212+
for (uint64_t i = 0; i < len; ++i) {
213+
if (j->get_value_list(i).is_array()) {
214+
j->get_value_list(i).as_array()->set_parent(this);
215+
}
216+
else if (j->get_value_list(i).is_object()) {
217+
j->get_value_list(i).as_object()->set_parent(this);
218+
}
219+
}
220+
221+
if (x->arr_vec.empty() == false) {
222+
arr_vec.insert(arr_vec.end(), std::make_move_iterator(x->arr_vec.begin()) + start_offset,
223+
std::make_move_iterator(x->arr_vec.end()));
224+
}
225+
else {
226+
227+
log << info << "test3";
228+
}
229+
}
230+
void Array::MergeWith(Object* j, int start_offset) {
231+
ERROR("Array::MergeWith Error");
232+
}
233+
void Array::MergeWith(PartialJson* j, int start_offset) {
234+
auto* x = j;
235+
236+
if (x->obj_data.empty() == false) { // not object?
237+
ERROR("partial json is not array");
238+
}
239+
240+
uint64_t len = j->get_data_size();
241+
for (uint64_t i = 0; i < len; ++i) {
242+
if (j->get_value_list(i).is_array()) {
243+
j->get_value_list(i).as_array()->set_parent(this);
244+
}
245+
else if (j->get_value_list(i).is_object()) {
246+
j->get_value_list(i).as_object()->set_parent(this);
247+
}
248+
}
249+
250+
if (x->virtualJson.is_structured()) {
251+
start_offset = 0;
252+
}
253+
254+
if (x->arr_vec.empty() == false) {
255+
arr_vec.insert(arr_vec.end(), std::make_move_iterator(x->arr_vec.begin()) + start_offset,
256+
std::make_move_iterator(x->arr_vec.end()));
257+
}
258+
else {
259+
260+
log << info << "test4";
261+
}
262+
}
263+
264+
265+
void Array::add_item_type(int64_t key_buf_idx, int64_t key_next_buf_idx, int64_t val_buf_idx, int64_t val_next_buf_idx,
266+
char* buf, uint64_t key_token_idx, uint64_t val_token_idx) {
267+
268+
// error
269+
log << warn << "error..";
270+
ERROR("Error Array::add_item_type");
271+
}
272+
273+
void Array::add_item_type(int64_t val_buf_idx, int64_t val_next_buf_idx,
274+
char* buf, uint64_t val_token_idx) {
275+
276+
{
277+
_Value temp2;
278+
bool e = false;
279+
claujson::Convert(temp2, val_buf_idx, val_next_buf_idx, false, buf, val_token_idx, e);
280+
if (e) {
281+
282+
ERROR("Error in add_item_type");
283+
}
284+
arr_vec.emplace_back(std::move(temp2));
285+
}
286+
}
287+
288+
void Array::add_user_type(int64_t key_buf_idx, int64_t key_next_buf_idx, char* buf,
289+
_ValueType type, uint64_t key_token_idx
290+
#ifdef USE_PMR
291+
, std::pmr::monotonic_buffer_resource* res
292+
#endif
293+
) {
294+
log << warn << "error";
295+
ERROR("Array::add_user_type1");
296+
}
297+
298+
void Array::add_user_type(_ValueType type
299+
#ifdef USE_PMR
300+
, std::pmr::monotonic_buffer_resource* res
301+
#endif
302+
) {
303+
304+
if (type == _ValueType::OBJECT) {
305+
Object* json = new (std::nothrow) Object(
306+
#ifdef USE_PMR
307+
res
308+
#endif
309+
);
310+
311+
if (json == nullptr) {
312+
log << warn << "new error";
313+
return;
314+
}
315+
316+
arr_vec.push_back(_Value(json));
317+
json->set_parent(this);
318+
319+
}
320+
else if (type == _ValueType::ARRAY) {
321+
Array* json = new (std::nothrow) Array(
322+
#ifdef USE_PMR
323+
res
324+
#endif
325+
);
326+
327+
if (json == nullptr) {
328+
log << warn << "new error";
329+
return;
330+
}
331+
332+
arr_vec.push_back(_Value(json));
333+
json->set_parent(this);
334+
}
335+
}
336+
337+
}

0 commit comments

Comments
 (0)