superstudio 0.8.2102

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,246 @@
1
+ #ifndef JSON_BUILDER_
2
+ #define JSON_BUILDER_
3
+
4
+ #include <stdint.h>
5
+
6
+ static const char* const obr = "{";
7
+ static const char* const ob = "[";
8
+ static const char* const oq = "\"";
9
+ static const char* const oqc = "\":";
10
+ static const char* const cm = ",";
11
+ static const char* const cbr = "}";
12
+ static const char* const cb = "]";
13
+ static const char* const end = "\0";
14
+
15
+ typedef struct JSONObject
16
+ {
17
+ struct SingleValueJSON* single_values;
18
+ struct SingleObjectJSON* single_objects;
19
+ struct ArrayValueJSON* array_values;
20
+ struct ArrayObjectJSON* array_objects;
21
+
22
+ struct SingleValueJSON* last_single_value;
23
+ struct SingleObjectJSON* last_single_object;
24
+
25
+ unsigned int value_array_count;
26
+ } JSONObject;
27
+
28
+ typedef struct SingleValueJSON
29
+ {
30
+ char* name;
31
+ char* value;
32
+ unsigned long value_characters;
33
+ unsigned long name_characters;
34
+ unsigned char set_flag;
35
+
36
+ unsigned char quoted;
37
+ struct SingleValueJSON* next_value;
38
+ } SingleValueJSON;
39
+
40
+ typedef struct SingleObjectJSON
41
+ {
42
+ char* name;
43
+ unsigned long name_characters;
44
+ unsigned char set_flag;
45
+ int identifier_int;
46
+ uint64_t associated_hash;
47
+
48
+ JSONObject* value;
49
+ struct SingleObjectJSON* next_item;
50
+ } SingleObjectJSON;
51
+
52
+ typedef struct ArrayObjectJSON
53
+ {
54
+ char* name;
55
+ unsigned long name_characters;
56
+ int identifier_int;
57
+ struct ArrayObjectListItem* value_list;
58
+ struct ArrayObjectListItem* last_list_object;
59
+ struct ArrayObjectJSON* next;
60
+
61
+ unsigned char set_flag;
62
+ } ArrayObjectJSON;
63
+
64
+ typedef struct ArrayObjectListItem
65
+ {
66
+ struct JSONObject* array_object;
67
+ struct ArrayObjectListItem* next_item;
68
+ uint64_t associated_hash;
69
+
70
+ unsigned char set_flag;
71
+ } ArrayObjectListItem;
72
+
73
+ typedef struct ArrayValueJSON
74
+ {
75
+ char* name;
76
+ unsigned long name_characters;
77
+ unsigned char quoted;
78
+ unsigned char set_flag;
79
+ struct ArrayValueListItem* value_list;
80
+ struct ArrayValueListItem* last_list_value;
81
+ struct ArrayValueJSON* next_value;
82
+ } ArrayValueJSON;
83
+
84
+ typedef struct ArrayValueListItem
85
+ {
86
+ char* array_value;
87
+ unsigned long value_characters;
88
+ unsigned char set_flag;
89
+ struct ArrayValueListItem* next_value;
90
+ struct ArrayValueListItem* last_value;
91
+ } ArrayValueListItem;
92
+
93
+ typedef struct JSONDocumentBuilder
94
+ {
95
+ struct SSMemoryStack* memory_stack;
96
+
97
+ unsigned long max_depth;
98
+ unsigned long max_real_depth;
99
+ unsigned long row_count;
100
+ unsigned long json_char_count;
101
+ char* resulting_json; //What's going to end up being returned to ruby
102
+ struct ArrayObjectJSON* root; //Root node of the JSON object, important for building, not for searching
103
+ struct JSONLevelBuilder* root_level;
104
+ unsigned long* single_object_key_lengths;
105
+ unsigned long* array_object_key_lengths;
106
+ char** single_object_key_names;
107
+ char** array_object_key_names;
108
+ } JSONDocumentBuilder;
109
+
110
+ typedef struct JSONLevelStrings
111
+ {
112
+ unsigned long set_strings_count;
113
+ unsigned long* string_lengths;
114
+ char** row_strings;
115
+ } JSONLevelStrings;
116
+
117
+ typedef struct JSONLevelBuilder
118
+ {
119
+ struct HashList* search_list; //How to find nodes and insert stuff
120
+
121
+ char* identifier; // The part from the mapping after the 4. or 2.
122
+ unsigned char identifier_length;
123
+ int identifier_int; // Internal identifier number to go ask the builder for the name of this fork from
124
+ uint64_t parent_hash;
125
+ uint64_t hash;
126
+
127
+ unsigned char set_flag;
128
+ unsigned char defined_flag;
129
+ unsigned char contains_array_value_flag;
130
+ unsigned char level_type; // 2 or 4
131
+ unsigned long assigned_count; // When building a new level, count the number of assigned columns
132
+
133
+ char** mapping_array; //Contents of the internal map from ruby
134
+ unsigned long* mapping_array_lengths;
135
+ unsigned long* quote_array; //Array of 1s and 0s indicating if quotes are to be applied
136
+ unsigned long* do_not_hash; //Array of 1s and 0s indicating if an item should or shouldn't be hashed (pretty much 3s for now)
137
+ unsigned long* depth_array; //Array showing the depth of each mapping
138
+ unsigned long* real_depth_array; //Array showing where calculation splits happen
139
+ unsigned long* repeating_array_columns; //Array showing whether or not type 3s can have repeating values or not
140
+ unsigned long column_count;
141
+ unsigned long* column_name_lengths;
142
+ char** column_names;
143
+
144
+ struct JSONLevelStrings* active_row_strings;
145
+ struct JSONLevelBuilder* next_child;
146
+ struct JSONLevelBuilder* next_child_array;
147
+ struct JSONLevelBuilder* last_child;
148
+ } JSONLevelBuilder;
149
+
150
+ typedef struct SSMemoryStack
151
+ {
152
+ struct SSMemoryStackNode* stack_top;
153
+ } SSMemoryStack;
154
+
155
+ typedef struct SSMemoryStackNode
156
+ {
157
+ void* memory_location;
158
+ struct SSMemoryStackNode* previous_node;
159
+ } SSMemoryStackNode;
160
+
161
+ typedef struct HashList
162
+ {
163
+ int length;
164
+ unsigned long bucket_interval;
165
+ struct HashListNode* next;
166
+ struct HashListNode* last;
167
+ struct HashListNode** buckets;
168
+ } HashList;
169
+
170
+ typedef struct HashListNode
171
+ {
172
+ uint64_t hash;
173
+ struct HashListNode* next;
174
+ struct HashListNode* bucket_next;
175
+ struct HashListNode* bucket_previous;
176
+ struct JSONObject* related_JSON_object;
177
+ struct JSONLevelBuilder* related_parent_level;
178
+
179
+ struct JSONLevelBuilder* single_object_info_list;
180
+ struct JSONLevelBuilder* array_object_info_list;
181
+ } HashListNode;
182
+
183
+ void json_builder_initialize(JSONDocumentBuilder *json_builder_initialize);
184
+ void set_row_count(JSONDocumentBuilder *builder, unsigned long row_count);
185
+ void initialize_search_list(JSONLevelBuilder* level, SSMemoryStack* memory_stack, unsigned long count);
186
+ unsigned long get_row_count(JSONDocumentBuilder *builder);
187
+ void set_column_count(JSONDocumentBuilder *builder, unsigned long count);
188
+ unsigned long get_column_count(JSONDocumentBuilder *builder);
189
+ void set_quote_array(JSONDocumentBuilder *builder, unsigned long* quotes);
190
+ void set_hashing_array(JSONDocumentBuilder *builder, unsigned long* do_not_hashes);
191
+ void set_depth_array(JSONDocumentBuilder *builder, unsigned long* depths, unsigned long max, unsigned long* real_depths, unsigned long max_real);
192
+ void set_mapping_array(JSONDocumentBuilder *builder, char** internal_map, unsigned long* internal_map_sizes);
193
+ void set_column_names_sizes(JSONDocumentBuilder *builder, char** column_names, unsigned long* column_string_sizes);
194
+ void set_repeating_array_columns(JSONDocumentBuilder *builder, unsigned long* repeating);
195
+ void consume_row(JSONDocumentBuilder *builder,
196
+ char** row,
197
+ unsigned long* sizes,
198
+ unsigned long accessing_depth,
199
+ unsigned long visible_depth,
200
+ unsigned long column_count,
201
+ JSONObject* parent_object,
202
+ JSONLevelBuilder* level_definitions,
203
+ unsigned char parent_type,
204
+ int parent_identifier,
205
+ HashList* parent_search_list);
206
+ uint64_t calculate_run_hash(JSONLevelBuilder* level_definitions, unsigned long column_count, unsigned long* string_sizes, char** row_strings, unsigned long accessing_depth, unsigned long hashing_depth);
207
+ uint64_t calculate_identified_hash(
208
+ JSONLevelBuilder* level_definitions,
209
+ unsigned long column_count,
210
+ unsigned long* string_sizes,
211
+ char** row_strings,
212
+ unsigned long accessing_depth,
213
+ unsigned long hashing_depth,
214
+ int test_identifier_length,
215
+ char* test_identifier);
216
+
217
+ char read_type(unsigned long depth_start, char* mapped_value, unsigned long mapped_value_length);
218
+ void read_identifier(char depth_start, char* mapped_value, int* cursor, int* identifier_characters, unsigned long mapped_value_length);
219
+ void set_single_node_key_names(JSONDocumentBuilder *builder, char** key_array, unsigned long* key_sizes);
220
+ void set_array_node_key_names(JSONDocumentBuilder *builder, char** key_array, unsigned long* key_sizes);
221
+ void define_child_levels(
222
+ JSONDocumentBuilder *builder,
223
+ JSONLevelBuilder* level_definitions,
224
+ JSONLevelBuilder* child_levels,
225
+ uint64_t hash,
226
+ unsigned long column_count,
227
+ unsigned long visible_depth
228
+ );
229
+
230
+ void define_child_array_levels(
231
+ JSONDocumentBuilder *builder,
232
+ JSONLevelBuilder* level_definitions,
233
+ JSONLevelBuilder* child_array_start,
234
+ uint64_t hash,
235
+ unsigned long column_count,
236
+ unsigned long accessing_depth,
237
+ unsigned long visible_depth,
238
+ char** row_strings,
239
+ unsigned long* string_sizes);
240
+
241
+ void consume_single_objects(JSONDocumentBuilder* builder, JSONLevelBuilder* child_levels, JSONObject* found_object, HashList* parent_search_list, unsigned long accessing_depth, unsigned long visible_depth);
242
+ void consume_array_objects(JSONDocumentBuilder* builder, JSONLevelBuilder* child_array_levels, JSONObject* found_object, unsigned long accessing_depth, unsigned long visible_depth);
243
+
244
+ char* finalize_json(JSONDocumentBuilder *builder);
245
+
246
+ #endif
@@ -0,0 +1,409 @@
1
+ #include "json_object_array.h"
2
+ #include "hash_linked_list.h"
3
+ #include "ss_alloc.h"
4
+
5
+ void create_array_object(JSONDocumentBuilder* builder,
6
+ uint64_t hash,
7
+ HashList* parent_list,
8
+ JSONLevelBuilder* parent_level_definitions,
9
+ JSONLevelBuilder* empty_child_object,
10
+ JSONLevelBuilder* empty_child_array,
11
+ int identifier_int
12
+ )
13
+ {
14
+ HashListNode* found_node = NULL;
15
+ ArrayObjectJSON* parent_array_object = NULL;
16
+ found_node = hl_find_node(parent_list, hash);
17
+
18
+ if (found_node) {
19
+
20
+ } else {
21
+ parent_array_object = builder->root;
22
+
23
+ if (!parent_array_object->value_list) {
24
+ if (identifier_int > 0) {
25
+ // Dev note:
26
+ // These are all -1 because the array that gets passed starts at 0, but numbering starts at 1
27
+ parent_array_object->name_characters = builder->array_object_key_lengths[identifier_int - 1];
28
+ parent_array_object->name = builder->array_object_key_names[identifier_int - 1];
29
+
30
+ builder->json_char_count += 8; //quotes, colon, brackets, braces, comma maybe
31
+ builder->json_char_count += builder->array_object_key_lengths[identifier_int - 1];
32
+ } else {
33
+ parent_array_object->name_characters = 0;
34
+ }
35
+
36
+ parent_array_object->value_list = (ArrayObjectListItem*)ss_alloc(builder->memory_stack, 1, sizeof(ArrayObjectListItem));
37
+ parent_array_object->value_list->array_object = (JSONObject*)ss_alloc(builder->memory_stack, 1, sizeof(JSONObject));
38
+ parent_array_object->value_list->array_object->array_values = (ArrayValueJSON*)ss_alloc(builder->memory_stack, 1, sizeof(ArrayValueJSON));
39
+ parent_array_object->value_list->array_object->single_objects = (SingleObjectJSON*)ss_alloc(builder->memory_stack, 1, sizeof(SingleObjectJSON));
40
+ parent_array_object->value_list->array_object->last_single_object = parent_array_object->value_list->array_object->single_objects;
41
+ parent_array_object->value_list->array_object->single_values = (SingleValueJSON*)ss_alloc(builder->memory_stack, 1, sizeof(SingleValueJSON));
42
+ parent_array_object->value_list->array_object->last_single_value = parent_array_object->value_list->array_object->single_values;
43
+ parent_array_object->value_list->array_object->array_objects = (ArrayObjectJSON*)ss_alloc(builder->memory_stack, 1, sizeof(ArrayObjectJSON));
44
+ parent_array_object->value_list->array_object->array_objects->next = (ArrayObjectJSON*)ss_alloc(builder->memory_stack, 1, sizeof(ArrayObjectJSON));
45
+ parent_array_object->value_list->associated_hash = hash;
46
+
47
+ parent_array_object->last_list_object = parent_array_object->value_list;
48
+ parent_array_object->set_flag = 1;
49
+ parent_array_object->last_list_object->set_flag = 1;
50
+
51
+ hl_insert_or_find(parent_list, hash, parent_array_object->last_list_object->array_object, parent_level_definitions, empty_child_object, empty_child_array, builder->memory_stack);
52
+ } else if (identifier_int == 0) {
53
+ parent_array_object->last_list_object->next_item = (ArrayObjectListItem*)ss_alloc(builder->memory_stack, 1, sizeof(ArrayObjectListItem));
54
+ parent_array_object->last_list_object->next_item->array_object = (JSONObject*)ss_alloc(builder->memory_stack, 1, sizeof(JSONObject));
55
+ parent_array_object->last_list_object->next_item->array_object->array_values = (ArrayValueJSON*)ss_alloc(builder->memory_stack, 1, sizeof(ArrayValueJSON));
56
+ parent_array_object->last_list_object->next_item->array_object->single_objects = (SingleObjectJSON*)ss_alloc(builder->memory_stack, 1, sizeof(SingleObjectJSON));
57
+ parent_array_object->last_list_object->next_item->array_object->last_single_object = parent_array_object->last_list_object->next_item->array_object->single_objects;
58
+ parent_array_object->last_list_object->next_item->array_object->single_values = (SingleValueJSON*)ss_alloc(builder->memory_stack, 1, sizeof(SingleValueJSON));
59
+ parent_array_object->last_list_object->next_item->array_object->last_single_value = parent_array_object->last_list_object->next_item->array_object->single_values;
60
+ parent_array_object->last_list_object->next_item->array_object->array_objects = (ArrayObjectJSON*)ss_alloc(builder->memory_stack, 1, sizeof(ArrayObjectJSON));
61
+ parent_array_object->last_list_object->next_item->array_object->array_objects->next = (ArrayObjectJSON*)ss_alloc(builder->memory_stack, 1, sizeof(ArrayObjectJSON));
62
+ parent_array_object->last_list_object->next_item->associated_hash = hash;
63
+
64
+ parent_array_object->set_flag = 1;
65
+
66
+ parent_array_object->last_list_object = parent_array_object->last_list_object->next_item;
67
+ hl_insert_or_find(parent_list, hash, parent_array_object->last_list_object->array_object, parent_level_definitions, empty_child_object, empty_child_array, builder->memory_stack);
68
+ }
69
+ }
70
+ }
71
+
72
+ void count_increment_or_create_json_level_child_array(
73
+ JSONDocumentBuilder* builder,
74
+ JSONLevelBuilder* child_array_levels,
75
+ int identifier_length,
76
+ char* identifier,
77
+ int identifier_int,
78
+ uint64_t parent_hash,
79
+ uint64_t child_hash)
80
+ {
81
+ unsigned char found = 0;
82
+
83
+ while(child_array_levels->set_flag && !found) {
84
+ if (child_array_levels->identifier_length == identifier_length) {
85
+ if (!memcmp(child_array_levels->identifier, identifier, identifier_length)) {
86
+ if (child_hash == child_array_levels->hash) {
87
+ found = 1;
88
+ child_array_levels->column_count++;
89
+ }
90
+ }
91
+ }
92
+ if (!found) {
93
+ child_array_levels = child_array_levels->next_child_array;
94
+ }
95
+ }
96
+
97
+ if (!child_array_levels->set_flag && !found) {
98
+ child_array_levels->parent_hash = parent_hash;
99
+ child_array_levels->hash = child_hash;
100
+ child_array_levels->identifier_int = identifier_int;
101
+ child_array_levels->identifier_length = identifier_length;
102
+ child_array_levels->identifier = identifier;
103
+
104
+ child_array_levels->column_count++;
105
+ child_array_levels->set_flag = 1;
106
+ child_array_levels->next_child = (JSONLevelBuilder*)ss_alloc(builder->memory_stack, 1, sizeof(JSONLevelBuilder));
107
+ child_array_levels->next_child_array = (JSONLevelBuilder*)ss_alloc(builder->memory_stack, 1, sizeof(JSONLevelBuilder));
108
+
109
+ child_array_levels->search_list = (HashList*)ss_alloc(builder->memory_stack, 1, sizeof(HashList));
110
+ initialize_search_list(child_array_levels, builder->memory_stack, builder->row_count);
111
+ found = 1;
112
+ }
113
+ }
114
+
115
+ void initialize_child_array_levels(JSONLevelBuilder* child_array_levels, SSMemoryStack* memory_stack)
116
+ {
117
+ while(child_array_levels->set_flag && child_array_levels->identifier_int) {
118
+ if (!child_array_levels->defined_flag) {
119
+ child_array_levels->active_row_strings = (JSONLevelStrings*)ss_alloc(memory_stack, 1, sizeof(JSONLevelStrings));
120
+ child_array_levels->active_row_strings->set_strings_count = 0;
121
+ child_array_levels->active_row_strings->string_lengths = (unsigned long*)ss_alloc(memory_stack, child_array_levels->column_count, sizeof(unsigned long));
122
+ child_array_levels->active_row_strings->row_strings = (char**)ss_alloc(memory_stack, child_array_levels->column_count, sizeof(char*));
123
+ child_array_levels->mapping_array_lengths = (unsigned long*)ss_alloc(memory_stack, 1, sizeof(unsigned long) * child_array_levels->column_count);
124
+ child_array_levels->mapping_array = (char**)ss_alloc(memory_stack, 1, sizeof(char*) * child_array_levels->column_count);
125
+ child_array_levels->quote_array = (unsigned long*)ss_alloc(memory_stack, 1, sizeof(unsigned long) * child_array_levels->column_count);
126
+ child_array_levels->do_not_hash = (unsigned long*)ss_alloc(memory_stack, 1, sizeof(unsigned long) * child_array_levels->column_count);
127
+ child_array_levels->depth_array = (unsigned long*)ss_alloc(memory_stack, 1, sizeof(unsigned long) * child_array_levels->column_count);
128
+ child_array_levels->real_depth_array = (unsigned long*)ss_alloc(memory_stack, 1, sizeof(unsigned long) * child_array_levels->column_count);
129
+ child_array_levels->repeating_array_columns = (unsigned long*)ss_alloc(memory_stack, 1, sizeof(unsigned long) * child_array_levels->column_count);
130
+ child_array_levels->column_name_lengths = (unsigned long*)ss_alloc(memory_stack, 1, sizeof(unsigned long) * child_array_levels->column_count);
131
+ child_array_levels->column_names = (char**)ss_alloc(memory_stack, 1, sizeof(char*) * child_array_levels->column_count);
132
+ child_array_levels->defined_flag = 1;
133
+ }
134
+ child_array_levels = child_array_levels->next_child_array;
135
+ }
136
+ }
137
+
138
+ void set_array_object_child_level_definitions(
139
+ JSONLevelBuilder* level_definitions,
140
+ JSONLevelBuilder* child_array_levels,
141
+ uint64_t hash,
142
+ unsigned long column_count,
143
+ unsigned long accessing_depth
144
+ )
145
+ {
146
+ unsigned long counter = 0;
147
+ int identifier_int;
148
+ int cursor;
149
+ unsigned char found = 0;
150
+ int test_identifier_length;
151
+ char* test_identifier;
152
+ JSONLevelBuilder* child_level_first_node = child_array_levels;
153
+
154
+ while(counter < column_count) {
155
+ if ((read_type(accessing_depth, level_definitions->mapping_array[counter], level_definitions->mapping_array_lengths[counter]) == '4')) {
156
+ found = 0;
157
+ while(child_array_levels->set_flag && !found) {
158
+ read_identifier(accessing_depth, level_definitions->mapping_array[counter], &cursor, &test_identifier_length, level_definitions->mapping_array_lengths[counter]);
159
+ test_identifier = level_definitions->mapping_array[counter] + cursor;
160
+
161
+ identifier_int = atoi(test_identifier);
162
+
163
+ if (
164
+ (child_array_levels->identifier_int == identifier_int)
165
+ && (child_array_levels->parent_hash == hash)
166
+ && (child_array_levels->assigned_count < child_array_levels->column_count)
167
+ ) {
168
+
169
+ child_array_levels->mapping_array_lengths[child_array_levels->assigned_count] = level_definitions->mapping_array_lengths[counter];
170
+ child_array_levels->mapping_array[child_array_levels->assigned_count] = level_definitions->mapping_array[counter];
171
+
172
+ child_array_levels->quote_array[child_array_levels->assigned_count] = level_definitions->quote_array[counter];
173
+ child_array_levels->do_not_hash[child_array_levels->assigned_count] = level_definitions->do_not_hash[counter];
174
+ child_array_levels->depth_array[child_array_levels->assigned_count] = level_definitions->depth_array[counter];
175
+ child_array_levels->real_depth_array[child_array_levels->assigned_count] = level_definitions->real_depth_array[counter];
176
+ child_array_levels->repeating_array_columns[child_array_levels->assigned_count] = level_definitions->repeating_array_columns[counter];
177
+ child_array_levels->column_name_lengths[child_array_levels->assigned_count] = level_definitions->column_name_lengths[counter];
178
+ child_array_levels->column_names[child_array_levels->assigned_count] = level_definitions->column_names[counter];
179
+
180
+ child_array_levels->assigned_count += 1;
181
+ }
182
+ child_array_levels = child_array_levels->next_child_array;
183
+ }
184
+ }
185
+ child_array_levels = child_level_first_node;
186
+ counter++;
187
+ }
188
+ }
189
+
190
+ void assign_array_object_data(
191
+ JSONLevelBuilder* level_definitions,
192
+ JSONLevelBuilder* child_array_levels,
193
+ char** row_strings,
194
+ unsigned long* string_sizes,
195
+ unsigned long column_count,
196
+ unsigned long accessing_depth
197
+ )
198
+ {
199
+ unsigned long counter = 0;
200
+ int cursor;
201
+ int tmp_total_assigned = 0;
202
+ unsigned char found = 0;
203
+ unsigned long inner_counter = 0;
204
+ int test_identifier_length;
205
+ char* test_identifier;
206
+ JSONLevelBuilder* child_level_first_node = child_array_levels;
207
+
208
+ while(counter < column_count) {
209
+ if (read_type(accessing_depth, level_definitions->mapping_array[counter], level_definitions->mapping_array_lengths[counter]) == '4') {
210
+ found = 0;
211
+ read_identifier(accessing_depth, level_definitions->mapping_array[counter], &cursor, &test_identifier_length, level_definitions->mapping_array_lengths[counter]);
212
+ test_identifier = level_definitions->mapping_array[counter] + cursor;
213
+
214
+ while(child_array_levels->set_flag && !found) {
215
+ if (!memcmp(child_array_levels->identifier, test_identifier, test_identifier_length) && (child_array_levels->active_row_strings->set_strings_count < child_array_levels->column_count)) {
216
+ child_array_levels->active_row_strings->string_lengths[child_array_levels->active_row_strings->set_strings_count] = string_sizes[counter];
217
+ child_array_levels->active_row_strings->row_strings[child_array_levels->active_row_strings->set_strings_count] = row_strings[counter];
218
+
219
+ inner_counter = 0;
220
+ while(inner_counter < child_array_levels->active_row_strings->string_lengths[child_array_levels->active_row_strings->set_strings_count]) {
221
+ inner_counter++;
222
+ }
223
+
224
+ child_array_levels->active_row_strings->set_strings_count += 1;
225
+
226
+ tmp_total_assigned++;
227
+ found = 1;
228
+ }
229
+ child_array_levels = child_array_levels->next_child_array;
230
+ }
231
+ }
232
+ child_array_levels = child_level_first_node;
233
+ counter++;
234
+ }
235
+ }
236
+
237
+ void add_or_find_array_object_child_hashes(
238
+ JSONDocumentBuilder* builder,
239
+ JSONLevelBuilder* level_definitions,
240
+ JSONLevelBuilder* child_array_levels,
241
+ unsigned long accessing_depth,
242
+ unsigned long visible_depth,
243
+ unsigned long column_count,
244
+ unsigned long* string_sizes,
245
+ char** row_strings,
246
+ JSONObject* related_object)
247
+ {
248
+ uint64_t child_hash_to_add;
249
+
250
+ ArrayObjectJSON* related_array_objects;
251
+
252
+ JSONLevelBuilder* empty_child_object;
253
+ JSONLevelBuilder* empty_child_array;
254
+ ArrayObjectListItem* hash_tester;
255
+
256
+ int found;
257
+
258
+ while (child_array_levels->set_flag && child_array_levels->identifier_int) {
259
+ found = 0;
260
+
261
+ child_hash_to_add = calculate_identified_hash(level_definitions, column_count, string_sizes, row_strings, accessing_depth + 1, (accessing_depth + visible_depth + 1), child_array_levels->identifier_length, child_array_levels->identifier);
262
+
263
+ related_array_objects = related_object->array_objects;
264
+
265
+ while(related_array_objects->set_flag && !found) {
266
+ empty_child_object = (JSONLevelBuilder*)ss_alloc(builder->memory_stack, 1, sizeof(JSONLevelBuilder));
267
+ empty_child_array = (JSONLevelBuilder*)ss_alloc(builder->memory_stack, 1, sizeof(JSONLevelBuilder));
268
+ empty_child_object->next_child = (JSONLevelBuilder*)ss_alloc(builder->memory_stack, 1, sizeof(JSONLevelBuilder));
269
+ empty_child_object->next_child_array = (JSONLevelBuilder*)ss_alloc(builder->memory_stack, 1, sizeof(JSONLevelBuilder));
270
+ empty_child_array->next_child = (JSONLevelBuilder*)ss_alloc(builder->memory_stack, 1, sizeof(JSONLevelBuilder));
271
+ empty_child_array->next_child_array = (JSONLevelBuilder*)ss_alloc(builder->memory_stack, 1, sizeof(JSONLevelBuilder));
272
+
273
+ if (related_array_objects->identifier_int == child_array_levels->identifier_int) {
274
+ if (related_array_objects->value_list) {
275
+ hash_tester = related_array_objects->value_list;
276
+ while (hash_tester) {
277
+ if (hash_tester->associated_hash == child_hash_to_add) {
278
+ found = 1;
279
+ hl_insert_or_find(child_array_levels->search_list, child_hash_to_add, related_array_objects->last_list_object->array_object, child_array_levels, empty_child_object, empty_child_array, builder->memory_stack);
280
+ break;
281
+ }
282
+ hash_tester = hash_tester->next_item;
283
+ }
284
+ }
285
+
286
+ if (!related_array_objects->value_list && !found) {
287
+ found = 1;
288
+
289
+ related_array_objects->value_list = (ArrayObjectListItem*)ss_alloc(builder->memory_stack, 1, sizeof(ArrayObjectListItem));
290
+ related_array_objects->value_list->array_object = (JSONObject*)ss_alloc(builder->memory_stack, 1, sizeof(JSONObject));
291
+ related_array_objects->value_list->array_object->array_values = (ArrayValueJSON*)ss_alloc(builder->memory_stack, 1, sizeof(ArrayValueJSON));
292
+ related_array_objects->value_list->array_object->single_objects = (SingleObjectJSON*)ss_alloc(builder->memory_stack, 1, sizeof(SingleObjectJSON));
293
+ related_array_objects->value_list->array_object->last_single_object = related_array_objects->value_list->array_object->single_objects;
294
+ related_array_objects->value_list->array_object->single_values = (SingleValueJSON*)ss_alloc(builder->memory_stack, 1, sizeof(SingleValueJSON));
295
+ related_array_objects->value_list->array_object->last_single_value = related_array_objects->value_list->array_object->single_values;
296
+ related_array_objects->value_list->array_object->array_objects = (ArrayObjectJSON*)ss_alloc(builder->memory_stack, 1, sizeof(ArrayObjectJSON));
297
+ related_array_objects->value_list->array_object->array_objects->set_flag = 1;
298
+ related_array_objects->value_list->array_object->array_objects->next = (ArrayObjectJSON*)ss_alloc(builder->memory_stack, 1, sizeof(ArrayObjectJSON));
299
+ related_array_objects->value_list->associated_hash = child_hash_to_add;
300
+
301
+ related_array_objects->last_list_object = related_array_objects->value_list;
302
+ related_array_objects->set_flag = 1;
303
+ related_array_objects->last_list_object->set_flag = 1;
304
+ hl_insert_or_find(child_array_levels->search_list, child_hash_to_add, related_array_objects->last_list_object->array_object, child_array_levels, empty_child_object, empty_child_array, builder->memory_stack);
305
+ } else if (!found) {
306
+ found = 1;
307
+ related_array_objects->last_list_object->next_item = (ArrayObjectListItem*)ss_alloc(builder->memory_stack, 1, sizeof(ArrayObjectListItem));
308
+ related_array_objects->last_list_object->next_item->array_object = (JSONObject*)ss_alloc(builder->memory_stack, 1, sizeof(JSONObject));
309
+ related_array_objects->last_list_object->next_item->array_object->array_values = (ArrayValueJSON*)ss_alloc(builder->memory_stack, 1, sizeof(ArrayValueJSON));
310
+ related_array_objects->last_list_object->next_item->array_object->single_objects = (SingleObjectJSON*)ss_alloc(builder->memory_stack, 1, sizeof(SingleObjectJSON));
311
+ related_array_objects->last_list_object->next_item->array_object->last_single_object = related_array_objects->last_list_object->next_item->array_object->single_objects;
312
+ related_array_objects->last_list_object->next_item->array_object->single_values = (SingleValueJSON*)ss_alloc(builder->memory_stack, 1, sizeof(SingleValueJSON));
313
+ related_array_objects->last_list_object->next_item->array_object->last_single_value = related_array_objects->last_list_object->next_item->array_object->single_values;
314
+ related_array_objects->last_list_object->next_item->array_object->array_objects = (ArrayObjectJSON*)ss_alloc(builder->memory_stack, 1, sizeof(ArrayObjectJSON));
315
+ related_array_objects->last_list_object->next_item->array_object->array_objects->set_flag = 1;
316
+ related_array_objects->last_list_object->next_item->array_object->array_objects->next = (ArrayObjectJSON*)ss_alloc(builder->memory_stack, 1, sizeof(ArrayObjectJSON));
317
+ related_array_objects->last_list_object->next_item->associated_hash = child_hash_to_add;
318
+
319
+ related_array_objects->set_flag = 1;
320
+ related_array_objects->last_list_object->set_flag = 1;
321
+ related_array_objects->last_list_object = related_array_objects->last_list_object->next_item;
322
+
323
+ hl_insert_or_find(child_array_levels->search_list, child_hash_to_add, related_array_objects->last_list_object->array_object, child_array_levels, empty_child_object, empty_child_array, builder->memory_stack);
324
+ }
325
+ }
326
+
327
+ if (!related_array_objects->next) {
328
+ break;
329
+ }
330
+ related_array_objects = related_array_objects->next;
331
+ }
332
+ if (!found) {
333
+ related_array_objects->name_characters = builder->array_object_key_lengths[child_array_levels->identifier_int - 1];
334
+ related_array_objects->name = builder->array_object_key_names[child_array_levels->identifier_int - 1];
335
+
336
+ builder->json_char_count += 8;
337
+ builder->json_char_count += builder->array_object_key_lengths[child_array_levels->identifier_int - 1];
338
+
339
+ related_array_objects->value_list = (ArrayObjectListItem*)ss_alloc(builder->memory_stack, 1, sizeof(ArrayObjectListItem));
340
+ related_array_objects->value_list->array_object = (JSONObject*)ss_alloc(builder->memory_stack, 1, sizeof(JSONObject));
341
+ related_array_objects->value_list->array_object->array_values = (ArrayValueJSON*)ss_alloc(builder->memory_stack, 1, sizeof(ArrayValueJSON));
342
+ related_array_objects->value_list->array_object->single_objects = (SingleObjectJSON*)ss_alloc(builder->memory_stack, 1, sizeof(SingleObjectJSON));
343
+ related_array_objects->value_list->array_object->last_single_object = related_array_objects->value_list->array_object->single_objects;
344
+ related_array_objects->value_list->array_object->single_values = (SingleValueJSON*)ss_alloc(builder->memory_stack, 1, sizeof(SingleValueJSON));
345
+ related_array_objects->value_list->array_object->last_single_value = related_array_objects->value_list->array_object->single_values;
346
+ related_array_objects->value_list->array_object->array_objects = (ArrayObjectJSON*)ss_alloc(builder->memory_stack, 1, sizeof(ArrayObjectJSON));
347
+ related_array_objects->value_list->array_object->array_objects->set_flag = 1;
348
+ related_array_objects->value_list->array_object->array_objects->next = (ArrayObjectJSON*)ss_alloc(builder->memory_stack, 1, sizeof(ArrayObjectJSON));
349
+
350
+ related_array_objects->value_list->associated_hash = child_hash_to_add;
351
+ related_array_objects->identifier_int = child_array_levels->identifier_int;
352
+ related_array_objects->last_list_object = related_array_objects->value_list;
353
+ related_array_objects->set_flag = 1;
354
+ related_array_objects->last_list_object->set_flag = 1;
355
+
356
+ hl_insert_or_find(child_array_levels->search_list, child_hash_to_add, related_array_objects->last_list_object->array_object, child_array_levels, empty_child_object, empty_child_array, builder->memory_stack);
357
+ }
358
+
359
+ child_array_levels = child_array_levels->next_child_array;
360
+ related_array_objects = related_object->array_objects;
361
+ }
362
+ }
363
+
364
+
365
+
366
+ unsigned long finalize_object_array(JSONDocumentBuilder* builder, ArrayObjectJSON* object_array, unsigned long counter)
367
+ {
368
+ ArrayObjectListItem* target_object = NULL;
369
+
370
+ while(object_array) {
371
+ if (object_array->set_flag) {
372
+ target_object = NULL;
373
+ if (object_array->name_characters > 0) {
374
+ memcpy(builder->resulting_json + counter, cm, 1);
375
+ counter++;
376
+ memcpy(builder->resulting_json + counter, oq, 1);
377
+ counter++;
378
+ memcpy(builder->resulting_json + counter, object_array->name, object_array->name_characters);
379
+ counter += object_array->name_characters;
380
+ memcpy(builder->resulting_json + counter, oqc, 2);
381
+ counter += 2;
382
+ memcpy(builder->resulting_json + counter, ob, 1);
383
+ counter++;
384
+ }
385
+
386
+ target_object = object_array->value_list;
387
+ while(target_object) {
388
+ counter = finalize_key_values(builder, target_object->array_object->single_values, target_object->array_object, counter);
389
+ counter = finalize_single_objects(builder, target_object->array_object->single_objects, counter, (target_object->array_object->array_values->set_flag ));
390
+ counter = finalize_value_array(builder, target_object->array_object->array_values, counter);
391
+ counter = finalize_object_array(builder, target_object->array_object->array_objects, counter);
392
+
393
+ memcpy(builder->resulting_json + counter, cbr, 1);
394
+ counter++;
395
+
396
+ if (target_object->next_item) {
397
+ memcpy(builder->resulting_json + counter, cm, 1);
398
+ counter++;
399
+ } else {
400
+ memcpy(builder->resulting_json + counter, cb, 1);
401
+ counter++;
402
+ }
403
+ target_object = target_object->next_item;
404
+ }
405
+ }
406
+ object_array = object_array->next;
407
+ }
408
+ return counter;
409
+ }