yeptris 0.6.18.2-arm-linux-eabihf
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.
- checksums.yaml +7 -0
- data/README.adoc +141 -0
- data/ext/build_windows_native.rb +41 -0
- data/ext/libyeptris/extconf.rb +57 -0
- data/ext/yeptris_native/cbor_ruby.c +193 -0
- data/ext/yeptris_native/extconf.rb +47 -0
- data/ext/yeptris_native/json_ruby.c +354 -0
- data/ext/yeptris_native/yeptris_native.c +497 -0
- data/lib/yeptris/cbor.rb +130 -0
- data/lib/yeptris/document.rb +255 -0
- data/lib/yeptris/ffi.rb +426 -0
- data/lib/yeptris/json/descriptor.rb +266 -0
- data/lib/yeptris/json.rb +394 -0
- data/lib/yeptris/materializer.rb +354 -0
- data/lib/yeptris/native-3.4.so +0 -0
- data/lib/yeptris/node.rb +453 -0
- data/lib/yeptris/psych/class_loader.rb +24 -0
- data/lib/yeptris/psych/coder_shim.rb +55 -0
- data/lib/yeptris/psych/drop_in.rb +63 -0
- data/lib/yeptris/psych/encodable.rb +14 -0
- data/lib/yeptris/psych/handler.rb +90 -0
- data/lib/yeptris/psych/parser.rb +105 -0
- data/lib/yeptris/psych/scalar_scanner.rb +149 -0
- data/lib/yeptris/psych/visitors.rb +545 -0
- data/lib/yeptris/psych.rb +622 -0
- data/lib/yeptris/schema.rb +253 -0
- data/lib/yeptris/valueml.rb +455 -0
- data/lib/yeptris/yaml/descriptor.rb +56 -0
- data/lib/yeptris/yaml.rb +422 -0
- data/lib/yeptris.rb +113 -0
- data/libyeptris.so +0 -0
- data/vendor/libyeptris/CMakeLists.txt +254 -0
- data/vendor/libyeptris/cmake/yeptris-config.cmake.in +5 -0
- data/vendor/libyeptris/cmake/yeptris.pc.in +11 -0
- data/vendor/libyeptris/src/CMakeLists.txt +167 -0
- data/vendor/libyeptris/src/include/yeptris/api.h +32 -0
- data/vendor/libyeptris/src/include/yeptris/cbor.h +101 -0
- data/vendor/libyeptris/src/include/yeptris/dom.h +190 -0
- data/vendor/libyeptris/src/include/yeptris/emit.h +81 -0
- data/vendor/libyeptris/src/include/yeptris/error.h +41 -0
- data/vendor/libyeptris/src/include/yeptris/events.h +157 -0
- data/vendor/libyeptris/src/include/yeptris/json.h +45 -0
- data/vendor/libyeptris/src/include/yeptris/json.hpp +258 -0
- data/vendor/libyeptris/src/include/yeptris/jsonc_compat.h +115 -0
- data/vendor/libyeptris/src/include/yeptris/marshal.h +52 -0
- data/vendor/libyeptris/src/include/yeptris/parse.h +48 -0
- data/vendor/libyeptris/src/include/yeptris/plan.h +100 -0
- data/vendor/libyeptris/src/include/yeptris/resolve.h +71 -0
- data/vendor/libyeptris/src/include/yeptris/schema.h +121 -0
- data/vendor/libyeptris/src/include/yeptris/tape.h +123 -0
- data/vendor/libyeptris/src/include/yeptris/types.h +38 -0
- data/vendor/libyeptris/src/include/yeptris/values.h +102 -0
- data/vendor/libyeptris/src/include/yeptris/version.h.in +29 -0
- data/vendor/libyeptris/src/include/yeptris/visit.h +77 -0
- data/vendor/libyeptris/src/include/yeptris/yajl_compat.h +135 -0
- data/vendor/libyeptris/src/include/yeptris.h +23 -0
- data/vendor/libyeptris/src/yeptris/build.c +376 -0
- data/vendor/libyeptris/src/yeptris/cbor/cbor.h +25 -0
- data/vendor/libyeptris/src/yeptris/cbor/decode.c +981 -0
- data/vendor/libyeptris/src/yeptris/cbor/encode.c +835 -0
- data/vendor/libyeptris/src/yeptris/cbor/sink.h +58 -0
- data/vendor/libyeptris/src/yeptris/common/chartype.c +41 -0
- data/vendor/libyeptris/src/yeptris/common/chartype.h +77 -0
- data/vendor/libyeptris/src/yeptris/common/cpu.c +81 -0
- data/vendor/libyeptris/src/yeptris/common/cpu.h +40 -0
- data/vendor/libyeptris/src/yeptris/common/error.c +65 -0
- data/vendor/libyeptris/src/yeptris/common/error.h +79 -0
- data/vendor/libyeptris/src/yeptris/common/mutex.h +45 -0
- data/vendor/libyeptris/src/yeptris/common/nametab.c +275 -0
- data/vendor/libyeptris/src/yeptris/common/nametab.h +68 -0
- data/vendor/libyeptris/src/yeptris/common/port.h +74 -0
- data/vendor/libyeptris/src/yeptris/common/simd_text.c +49 -0
- data/vendor/libyeptris/src/yeptris/common/simd_text.h +295 -0
- data/vendor/libyeptris/src/yeptris/common/simd_text_avx2.c +534 -0
- data/vendor/libyeptris/src/yeptris/common/simd_text_neon.c +662 -0
- data/vendor/libyeptris/src/yeptris/common/simd_text_scalar.c +298 -0
- data/vendor/libyeptris/src/yeptris/common/string_view.c +34 -0
- data/vendor/libyeptris/src/yeptris/common/string_view.h +93 -0
- data/vendor/libyeptris/src/yeptris/doc.h +56 -0
- data/vendor/libyeptris/src/yeptris/dom/dom.c +1192 -0
- data/vendor/libyeptris/src/yeptris/dom/dom.h +312 -0
- data/vendor/libyeptris/src/yeptris/dom/hpool.c +107 -0
- data/vendor/libyeptris/src/yeptris/dom/mapindex.c +173 -0
- data/vendor/libyeptris/src/yeptris/dom/mapindex.h +61 -0
- data/vendor/libyeptris/src/yeptris/dom/mutate.c +431 -0
- data/vendor/libyeptris/src/yeptris/emit/emit.c +434 -0
- data/vendor/libyeptris/src/yeptris/emit/float/api.h +38 -0
- data/vendor/libyeptris/src/yeptris/emit/float/dragon.c +405 -0
- data/vendor/libyeptris/src/yeptris/emit/float/floatint.h +231 -0
- data/vendor/libyeptris/src/yeptris/emit/float/print.c +396 -0
- data/vendor/libyeptris/src/yeptris/emit/style.c +81 -0
- data/vendor/libyeptris/src/yeptris/emit/style.h +24 -0
- data/vendor/libyeptris/src/yeptris/emit/writer.c +816 -0
- data/vendor/libyeptris/src/yeptris/emit/writer.h +76 -0
- data/vendor/libyeptris/src/yeptris/encoding/bom.c +31 -0
- data/vendor/libyeptris/src/yeptris/encoding/encoding.h +63 -0
- data/vendor/libyeptris/src/yeptris/encoding/transcode.c +148 -0
- data/vendor/libyeptris/src/yeptris/encoding/utf8_validate.c +178 -0
- data/vendor/libyeptris/src/yeptris/events/capture.c +150 -0
- data/vendor/libyeptris/src/yeptris/events/capture.h +39 -0
- data/vendor/libyeptris/src/yeptris/events/iterparse.c +208 -0
- data/vendor/libyeptris/src/yeptris/events/pull.c +97 -0
- data/vendor/libyeptris/src/yeptris/events/push.c +104 -0
- data/vendor/libyeptris/src/yeptris/events/recorder.c +107 -0
- data/vendor/libyeptris/src/yeptris/events/values.c +527 -0
- data/vendor/libyeptris/src/yeptris/events/values_priv.h +51 -0
- data/vendor/libyeptris/src/yeptris/events/yaml_compat.c +86 -0
- data/vendor/libyeptris/src/yeptris/events/yaml_compat.h +90 -0
- data/vendor/libyeptris/src/yeptris/jsonapi/jsonc_compat.c +687 -0
- data/vendor/libyeptris/src/yeptris/jsonapi/yajl_compat.c +728 -0
- data/vendor/libyeptris/src/yeptris/marshal.c +782 -0
- data/vendor/libyeptris/src/yeptris/memory/allocator.c +20 -0
- data/vendor/libyeptris/src/yeptris/memory/allocator.h +43 -0
- data/vendor/libyeptris/src/yeptris/memory/arena.c +134 -0
- data/vendor/libyeptris/src/yeptris/memory/arena.h +52 -0
- data/vendor/libyeptris/src/yeptris/memory/pool.c +122 -0
- data/vendor/libyeptris/src/yeptris/memory/pool.h +36 -0
- data/vendor/libyeptris/src/yeptris/parse/engine.c +3698 -0
- data/vendor/libyeptris/src/yeptris/parse/engine.h +65 -0
- data/vendor/libyeptris/src/yeptris/parse/events.h +124 -0
- data/vendor/libyeptris/src/yeptris/parse/numbers.c +349 -0
- data/vendor/libyeptris/src/yeptris/parse/numbers.h +33 -0
- data/vendor/libyeptris/src/yeptris/parse/scalars.c +416 -0
- data/vendor/libyeptris/src/yeptris/parse/scalars.h +75 -0
- data/vendor/libyeptris/src/yeptris/parse.c +737 -0
- data/vendor/libyeptris/src/yeptris/plan.c +824 -0
- data/vendor/libyeptris/src/yeptris/resolve/compat11.c +334 -0
- data/vendor/libyeptris/src/yeptris/resolve/core12.c +143 -0
- data/vendor/libyeptris/src/yeptris/resolve/resolver.h +56 -0
- data/vendor/libyeptris/src/yeptris/resolve/tags.c +58 -0
- data/vendor/libyeptris/src/yeptris/scan/json.c +792 -0
- data/vendor/libyeptris/src/yeptris/scan/json.h +109 -0
- data/vendor/libyeptris/src/yeptris/scan/scan.c +463 -0
- data/vendor/libyeptris/src/yeptris/scan/scan.h +150 -0
- data/vendor/libyeptris/src/yeptris/schema.c +308 -0
- data/vendor/libyeptris/src/yeptris/tape.c +1308 -0
- data/vendor/libyeptris/src/yeptris/tape_in.h +19 -0
- data/vendor/libyeptris/src/yeptris/version.c +7 -0
- data/vendor/libyeptris/src/yeptris/visit/dom_visit.c +115 -0
- data/vendor/libyeptris/src/yeptris/visit/json_visit.c +293 -0
- data/vendor/libyeptris/src/yeptris/visit/yaml_visit.c +127 -0
- metadata +199 -0
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
/* mutate.c — the from-scratch DOM builder (TODO.impl/11 phase 3).
|
|
2
|
+
*
|
|
3
|
+
* Synthesis mirrors what parse produces: runtime values are copied
|
|
4
|
+
* into the DOM pool (nothing is borrowed), typing runs through the
|
|
5
|
+
* core12 resolver (the SSOT — a quoted "12" is a string here exactly
|
|
6
|
+
* as at parse), and links form only through dom_link. Invariants:
|
|
7
|
+
* one parent per node, mapping children always balanced key/value
|
|
8
|
+
* pairs, depth capped at YEP_DOM_MAX_DEPTH — so the emitter's
|
|
9
|
+
* guarantees hold for synthesized trees unchanged.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
#include <string.h>
|
|
13
|
+
|
|
14
|
+
#include <yeptris/resolve.h>
|
|
15
|
+
|
|
16
|
+
#include "dom/dom.h"
|
|
17
|
+
#include "memory/allocator.h"
|
|
18
|
+
#include "resolve/resolver.h"
|
|
19
|
+
|
|
20
|
+
/* status codes (dom.h) */
|
|
21
|
+
#define MUT_ERR -1
|
|
22
|
+
#define MUT_DUP -2
|
|
23
|
+
#define MUT_DEPTH -3
|
|
24
|
+
#define MUT_ATTACHED -4
|
|
25
|
+
|
|
26
|
+
static yep_view mut_copy(yep_dom* d, const char* s, size_t len) {
|
|
27
|
+
yep_view v = {NULL, 0};
|
|
28
|
+
if (len == 0) {
|
|
29
|
+
return v;
|
|
30
|
+
}
|
|
31
|
+
char* cp = yep_pool_alloc(d->pool, len, 16);
|
|
32
|
+
if (cp == NULL) {
|
|
33
|
+
return v;
|
|
34
|
+
}
|
|
35
|
+
memcpy(cp, s, len);
|
|
36
|
+
v.p = cp;
|
|
37
|
+
v.len = (uint32_t)len;
|
|
38
|
+
return v;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
uint32_t yep_mut_scalar(yep_dom* d, const char* value, size_t len, uint8_t style) {
|
|
42
|
+
if (d == NULL || (value == NULL && len > 0)) {
|
|
43
|
+
return UINT32_MAX;
|
|
44
|
+
}
|
|
45
|
+
uint32_t id = dom_new_node(d, NULL, YEP_DOM_SCALAR);
|
|
46
|
+
if (id == UINT32_MAX) {
|
|
47
|
+
return UINT32_MAX;
|
|
48
|
+
}
|
|
49
|
+
yep_dnode* n = &d->nodes[id];
|
|
50
|
+
yep_view v = mut_copy(d, value, len);
|
|
51
|
+
if (len > 0 && v.p == NULL) {
|
|
52
|
+
d->ncount--;
|
|
53
|
+
return UINT32_MAX;
|
|
54
|
+
}
|
|
55
|
+
n->value = yep_dom_str_put(d, v.p ? (const char*)v.p : "", v.len);
|
|
56
|
+
n->style = style;
|
|
57
|
+
n->tag_id = style == YEP_STYLE_PLAIN ? yep_resolver_core12()->resolve(NULL, v.p, v.len)
|
|
58
|
+
: YEPTRIS_TAG_STR;
|
|
59
|
+
return id;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
uint32_t yep_mut_seq(yep_dom* d, uint8_t flow) {
|
|
63
|
+
if (d == NULL) {
|
|
64
|
+
return UINT32_MAX;
|
|
65
|
+
}
|
|
66
|
+
uint32_t id = dom_new_node(d, NULL, YEP_DOM_SEQUENCE);
|
|
67
|
+
if (id == UINT32_MAX) {
|
|
68
|
+
return UINT32_MAX;
|
|
69
|
+
}
|
|
70
|
+
d->nodes[id].flow = flow;
|
|
71
|
+
d->nodes[id].tag_id = YEPTRIS_TAG_SEQ;
|
|
72
|
+
return id;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
uint32_t yep_mut_map(yep_dom* d, uint8_t flow) {
|
|
76
|
+
if (d == NULL) {
|
|
77
|
+
return UINT32_MAX;
|
|
78
|
+
}
|
|
79
|
+
uint32_t id = dom_new_node(d, NULL, YEP_DOM_MAPPING);
|
|
80
|
+
if (id == UINT32_MAX) {
|
|
81
|
+
return UINT32_MAX;
|
|
82
|
+
}
|
|
83
|
+
d->nodes[id].flow = flow;
|
|
84
|
+
d->nodes[id].tag_id = YEPTRIS_TAG_MAP;
|
|
85
|
+
return id;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/* Subtree height with a depth-safe stop (defensive: synthesized trees
|
|
89
|
+
* are capped before links form, so the walk never exceeds the cap). */
|
|
90
|
+
static int mut_height(const yep_dom* d, uint32_t id, uint32_t* height) {
|
|
91
|
+
const yep_dnode* n = yep_dom_node(d, id);
|
|
92
|
+
if (n == NULL) {
|
|
93
|
+
return -1;
|
|
94
|
+
}
|
|
95
|
+
uint32_t child_h = 0;
|
|
96
|
+
uint32_t c = n->first_child;
|
|
97
|
+
while (c != UINT32_MAX) {
|
|
98
|
+
const yep_dnode* cn = yep_dom_node(d, c);
|
|
99
|
+
if (cn == NULL) {
|
|
100
|
+
return -1;
|
|
101
|
+
}
|
|
102
|
+
uint32_t h = 0;
|
|
103
|
+
if (mut_height(d, c, &h) != 0) {
|
|
104
|
+
return -1;
|
|
105
|
+
}
|
|
106
|
+
if (h + 1 > child_h) {
|
|
107
|
+
child_h = h + 1;
|
|
108
|
+
}
|
|
109
|
+
c = cn->next_sibling;
|
|
110
|
+
}
|
|
111
|
+
*height = child_h;
|
|
112
|
+
return 0;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/* Descendant depths after a move/relink (one walk); also the
|
|
116
|
+
* stream-end fixup: builder links form bottom-up, so local depths are
|
|
117
|
+
* relative until the tree completes (dom.c calls this per root). */
|
|
118
|
+
/* Mutation links carry the side-table facts parse no longer writes
|
|
119
|
+
* (64-2a): the attached flag and the child's depth under its parent. */
|
|
120
|
+
static void mut_link(yep_dom* d, uint32_t parent, uint32_t child) {
|
|
121
|
+
dom_link(d, parent, child);
|
|
122
|
+
dom_mut_set_att(d, child, 1);
|
|
123
|
+
dom_mut_set_depth(d, child, (uint16_t)(dom_mut_depth(d, parent) + 1));
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
void yep_mut_set_depths(yep_dom* d, uint32_t id, uint16_t depth) {
|
|
127
|
+
dom_mut_set_depth(d, id, depth);
|
|
128
|
+
uint32_t c = d->nodes[id].first_child;
|
|
129
|
+
while (c != UINT32_MAX) {
|
|
130
|
+
yep_mut_set_depths(d, c, (uint16_t)(depth + 1));
|
|
131
|
+
c = d->nodes[c].next_sibling;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
static int mut_attach_ok(yep_dom* d, uint32_t parent, uint32_t child) {
|
|
136
|
+
if (child >= d->ncount || dom_mut_att(d, child)) {
|
|
137
|
+
return MUT_ATTACHED;
|
|
138
|
+
}
|
|
139
|
+
uint32_t h = 0;
|
|
140
|
+
if (mut_height(d, child, &h) != 0) {
|
|
141
|
+
return MUT_ERR;
|
|
142
|
+
}
|
|
143
|
+
if ((uint32_t)dom_mut_depth(d, parent) + 1 + h > YEP_DOM_MAX_DEPTH) {
|
|
144
|
+
return MUT_DEPTH;
|
|
145
|
+
}
|
|
146
|
+
return 0;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
int yep_mut_seq_add(yep_dom* d, uint32_t seq, uint32_t child) {
|
|
150
|
+
if (d == NULL || seq >= d->ncount || d->nodes[seq].kind != YEP_DOM_SEQUENCE) {
|
|
151
|
+
return MUT_ERR;
|
|
152
|
+
}
|
|
153
|
+
int rc = mut_attach_ok(d, seq, child);
|
|
154
|
+
if (rc != 0) {
|
|
155
|
+
return rc;
|
|
156
|
+
}
|
|
157
|
+
mut_link(d, seq, child);
|
|
158
|
+
return 0;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
static uint32_t map_find(const yep_dom* d, uint32_t map, const char* key, size_t klen) {
|
|
162
|
+
const yep_dnode* m = yep_dom_node(d, map);
|
|
163
|
+
if (m == NULL) {
|
|
164
|
+
return UINT32_MAX;
|
|
165
|
+
}
|
|
166
|
+
uint32_t c = m->first_child;
|
|
167
|
+
while (c != UINT32_MAX) {
|
|
168
|
+
const yep_dnode* k = yep_dom_node(d, c);
|
|
169
|
+
if (k == NULL) {
|
|
170
|
+
return UINT32_MAX;
|
|
171
|
+
}
|
|
172
|
+
yep_view kv = yep_dom_view(d, k->value);
|
|
173
|
+
if (kv.len == klen && (klen == 0 || memcmp(kv.p, key, klen) == 0)) {
|
|
174
|
+
return c;
|
|
175
|
+
}
|
|
176
|
+
c = k->next_sibling; /* the value node follows the key */
|
|
177
|
+
if (c == UINT32_MAX) {
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
k = yep_dom_node(d, c);
|
|
181
|
+
if (k == NULL) {
|
|
182
|
+
return UINT32_MAX;
|
|
183
|
+
}
|
|
184
|
+
c = k->next_sibling;
|
|
185
|
+
}
|
|
186
|
+
return UINT32_MAX;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/* Appends the (key,value) pair; assumes the dup check already ran. */
|
|
190
|
+
static int map_place_pair(yep_dom* d, uint32_t map, const char* key, size_t klen, uint32_t value) {
|
|
191
|
+
uint32_t k = yep_mut_scalar(d, key, klen, YEP_STYLE_PLAIN);
|
|
192
|
+
if (k == UINT32_MAX) {
|
|
193
|
+
return MUT_ERR;
|
|
194
|
+
}
|
|
195
|
+
int rc = mut_attach_ok(d, map, value);
|
|
196
|
+
if (rc != 0) {
|
|
197
|
+
d->ncount--; /* the key node never linked: retract */
|
|
198
|
+
return rc;
|
|
199
|
+
}
|
|
200
|
+
mut_link(d, map, k);
|
|
201
|
+
mut_link(d, map, value);
|
|
202
|
+
yep_midx_invalidate(d, map);
|
|
203
|
+
return 0;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
int yep_mut_map_add(yep_dom* d, uint32_t map, const char* key, size_t klen, uint32_t value) {
|
|
207
|
+
if (d == NULL || key == NULL || map >= d->ncount || d->nodes[map].kind != YEP_DOM_MAPPING) {
|
|
208
|
+
return MUT_ERR;
|
|
209
|
+
}
|
|
210
|
+
if (map_find(d, map, key, klen) != UINT32_MAX) {
|
|
211
|
+
return MUT_DUP;
|
|
212
|
+
}
|
|
213
|
+
return map_place_pair(d, map, key, klen, value);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
int yep_mut_map_set(yep_dom* d, uint32_t map, const char* key, size_t klen, uint32_t value) {
|
|
217
|
+
if (d == NULL || key == NULL || map >= d->ncount || d->nodes[map].kind != YEP_DOM_MAPPING) {
|
|
218
|
+
return MUT_ERR;
|
|
219
|
+
}
|
|
220
|
+
uint32_t k = map_find(d, map, key, klen);
|
|
221
|
+
if (k == UINT32_MAX) {
|
|
222
|
+
return map_place_pair(d, map, key, klen, value);
|
|
223
|
+
}
|
|
224
|
+
int rc = mut_attach_ok(d, map, value);
|
|
225
|
+
if (rc != 0) {
|
|
226
|
+
return rc;
|
|
227
|
+
}
|
|
228
|
+
/* replace the value in place: position preserved (json-c) */
|
|
229
|
+
yep_dnode* m = &d->nodes[map];
|
|
230
|
+
yep_dnode* kn = &d->nodes[k];
|
|
231
|
+
uint32_t old = kn->next_sibling;
|
|
232
|
+
if (old == UINT32_MAX) {
|
|
233
|
+
return MUT_ERR; /* unbalanced pair: impossible by construction */
|
|
234
|
+
}
|
|
235
|
+
dom_mut_set_att(d, old, 0);
|
|
236
|
+
d->nodes[value].next_sibling = d->nodes[old].next_sibling;
|
|
237
|
+
kn->next_sibling = value;
|
|
238
|
+
if (m->last_child == old) {
|
|
239
|
+
m->last_child = value;
|
|
240
|
+
}
|
|
241
|
+
dom_mut_set_att(d, value, 1);
|
|
242
|
+
yep_mut_set_depths(d, value, (uint16_t)(dom_mut_depth(d, k) + 1));
|
|
243
|
+
yep_midx_invalidate(d, map);
|
|
244
|
+
return 1;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/* Unlinks ONE node from a parent's child chain (pairs call it twice). */
|
|
248
|
+
static int unlink_child(yep_dom* d, uint32_t parent, uint32_t child) {
|
|
249
|
+
yep_dnode* p = &d->nodes[parent];
|
|
250
|
+
if (child == UINT32_MAX || p->first_child == UINT32_MAX) {
|
|
251
|
+
return MUT_ERR;
|
|
252
|
+
}
|
|
253
|
+
if (p->first_child == child) {
|
|
254
|
+
p->first_child = d->nodes[child].next_sibling;
|
|
255
|
+
if (p->last_child == child) {
|
|
256
|
+
p->last_child = UINT32_MAX;
|
|
257
|
+
}
|
|
258
|
+
} else {
|
|
259
|
+
uint32_t c = p->first_child;
|
|
260
|
+
while (c != UINT32_MAX && d->nodes[c].next_sibling != child) {
|
|
261
|
+
c = d->nodes[c].next_sibling;
|
|
262
|
+
}
|
|
263
|
+
if (c == UINT32_MAX) {
|
|
264
|
+
return MUT_ERR;
|
|
265
|
+
}
|
|
266
|
+
d->nodes[c].next_sibling = d->nodes[child].next_sibling;
|
|
267
|
+
if (p->last_child == child) {
|
|
268
|
+
p->last_child = c;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
d->child_cache_id = UINT32_MAX; /* #377: the list changed */
|
|
272
|
+
d->child_cache_len = 0;
|
|
273
|
+
d->nodes[child].next_sibling = UINT32_MAX;
|
|
274
|
+
dom_mut_set_att(d, child, 0);
|
|
275
|
+
p->count--;
|
|
276
|
+
return 0;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
int yep_mut_seq_del(yep_dom* d, uint32_t seq, uint32_t index) {
|
|
280
|
+
if (d == NULL || seq >= d->ncount || d->nodes[seq].kind != YEP_DOM_SEQUENCE) {
|
|
281
|
+
return MUT_ERR;
|
|
282
|
+
}
|
|
283
|
+
yep_dnode* s = &d->nodes[seq];
|
|
284
|
+
if (index >= s->count) {
|
|
285
|
+
return MUT_ERR;
|
|
286
|
+
}
|
|
287
|
+
uint32_t c = s->first_child;
|
|
288
|
+
for (uint32_t i = 0; i < index && c != UINT32_MAX; i++) {
|
|
289
|
+
c = d->nodes[c].next_sibling;
|
|
290
|
+
}
|
|
291
|
+
return unlink_child(d, seq, c);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
int yep_mut_set_anchor(yep_dom* d, uint32_t node, const char* name, size_t len) {
|
|
295
|
+
if (d == NULL || node >= d->ncount || name == NULL) {
|
|
296
|
+
return MUT_ERR;
|
|
297
|
+
}
|
|
298
|
+
d->nodes[node].anchor = yep_dom_str_put(d, name, (uint32_t)len);
|
|
299
|
+
return 0;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
int yep_mut_set_tag(yep_dom* d, uint32_t node, const char* tag, size_t len) {
|
|
303
|
+
if (d == NULL || node >= d->ncount || tag == NULL) {
|
|
304
|
+
return MUT_ERR;
|
|
305
|
+
}
|
|
306
|
+
d->nodes[node].tag = yep_dom_str_put(d, tag, (uint32_t)len);
|
|
307
|
+
return 0;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
uint32_t yep_mut_new_alias(yep_dom* d, uint32_t target, const char* name, size_t len) {
|
|
311
|
+
if (d == NULL || name == NULL) {
|
|
312
|
+
return UINT32_MAX;
|
|
313
|
+
}
|
|
314
|
+
uint32_t id = dom_new_node(d, NULL, YEP_DOM_ALIAS);
|
|
315
|
+
if (id == UINT32_MAX) {
|
|
316
|
+
return UINT32_MAX;
|
|
317
|
+
}
|
|
318
|
+
d->nodes[id].target = target;
|
|
319
|
+
d->nodes[id].value = yep_dom_str_put(d, name, (uint32_t)len);
|
|
320
|
+
return id;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
int yep_mut_seq_set(yep_dom* d, uint32_t seq, uint32_t index, uint32_t value) {
|
|
324
|
+
if (d == NULL || seq >= d->ncount || d->nodes[seq].kind != YEP_DOM_SEQUENCE) {
|
|
325
|
+
return MUT_ERR;
|
|
326
|
+
}
|
|
327
|
+
yep_dnode* s = &d->nodes[seq];
|
|
328
|
+
if (index >= s->count) {
|
|
329
|
+
return MUT_ERR;
|
|
330
|
+
}
|
|
331
|
+
uint32_t cur = s->first_child;
|
|
332
|
+
for (uint32_t i = 0; i < index && cur != UINT32_MAX; i++) {
|
|
333
|
+
cur = d->nodes[cur].next_sibling;
|
|
334
|
+
}
|
|
335
|
+
int rc = mut_attach_ok(d, seq, value);
|
|
336
|
+
if (rc != 0) {
|
|
337
|
+
return rc;
|
|
338
|
+
}
|
|
339
|
+
/* splice: value takes cur's position (first-child or prev's
|
|
340
|
+
* next_sibling), cur is detached — same shape as map_set */
|
|
341
|
+
if (s->first_child == cur) {
|
|
342
|
+
s->first_child = value;
|
|
343
|
+
} else {
|
|
344
|
+
uint32_t prev = s->first_child;
|
|
345
|
+
while (d->nodes[prev].next_sibling != cur) {
|
|
346
|
+
prev = d->nodes[prev].next_sibling;
|
|
347
|
+
}
|
|
348
|
+
d->nodes[prev].next_sibling = value;
|
|
349
|
+
}
|
|
350
|
+
if (s->last_child == cur) {
|
|
351
|
+
s->last_child = value;
|
|
352
|
+
}
|
|
353
|
+
d->nodes[value].next_sibling = d->nodes[cur].next_sibling;
|
|
354
|
+
d->nodes[cur].next_sibling = UINT32_MAX;
|
|
355
|
+
dom_mut_set_att(d, cur, 0);
|
|
356
|
+
dom_mut_set_att(d, value, 1);
|
|
357
|
+
yep_mut_set_depths(d, value, (uint16_t)(dom_mut_depth(d, seq) + 1));
|
|
358
|
+
return 0;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
int yep_mut_map_add_node(yep_dom* d, uint32_t map, uint32_t key, uint32_t value) {
|
|
362
|
+
if (d == NULL || map >= d->ncount || d->nodes[map].kind != YEP_DOM_MAPPING) {
|
|
363
|
+
return MUT_ERR;
|
|
364
|
+
}
|
|
365
|
+
yep_view kv = yep_dom_view(d, d->nodes[key].value);
|
|
366
|
+
if (map_find(d, map, (const char*)kv.p, kv.len) != UINT32_MAX) {
|
|
367
|
+
return MUT_DUP;
|
|
368
|
+
}
|
|
369
|
+
int rc = mut_attach_ok(d, map, value);
|
|
370
|
+
if (rc != 0) {
|
|
371
|
+
return rc;
|
|
372
|
+
}
|
|
373
|
+
mut_link(d, map, key);
|
|
374
|
+
mut_link(d, map, value);
|
|
375
|
+
yep_midx_invalidate(d, map);
|
|
376
|
+
return 0;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/* The bulk-build pairing twin of map_add_node: same invariants,
|
|
380
|
+
* without the duplicate scan — document-order entries from a host
|
|
381
|
+
* mapping cannot carry a duplicate, and the linear scan is O(n^2)
|
|
382
|
+
* on wide maps (187 ms of a 20k-node build). Last wins, as at
|
|
383
|
+
* parse. Depths come from mut_link (top-down links, O(1) each). */
|
|
384
|
+
int yep_mut_map_append(yep_dom* d, uint32_t map, uint32_t key, uint32_t value) {
|
|
385
|
+
if (d == NULL || map >= d->ncount || d->nodes[map].kind != YEP_DOM_MAPPING) {
|
|
386
|
+
return MUT_ERR;
|
|
387
|
+
}
|
|
388
|
+
int rc = mut_attach_ok(d, map, value);
|
|
389
|
+
if (rc != 0) {
|
|
390
|
+
return rc;
|
|
391
|
+
}
|
|
392
|
+
mut_link(d, map, key);
|
|
393
|
+
mut_link(d, map, value);
|
|
394
|
+
yep_midx_invalidate(d, map);
|
|
395
|
+
return 0;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
int yep_mut_map_del(yep_dom* d, uint32_t map, const char* key, size_t klen) {
|
|
399
|
+
if (d == NULL || key == NULL || map >= d->ncount || d->nodes[map].kind != YEP_DOM_MAPPING) {
|
|
400
|
+
return MUT_ERR;
|
|
401
|
+
}
|
|
402
|
+
uint32_t k = map_find(d, map, key, klen);
|
|
403
|
+
if (k == UINT32_MAX) {
|
|
404
|
+
return MUT_ERR;
|
|
405
|
+
}
|
|
406
|
+
uint32_t v = d->nodes[k].next_sibling;
|
|
407
|
+
if (unlink_child(d, map, k) != 0) {
|
|
408
|
+
return MUT_ERR;
|
|
409
|
+
}
|
|
410
|
+
int rc = unlink_child(d, map, v);
|
|
411
|
+
yep_midx_invalidate(d, map);
|
|
412
|
+
return rc;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
int yep_mut_add_root(yep_dom* d, uint32_t node) {
|
|
416
|
+
if (d == NULL || node >= d->ncount || dom_mut_att(d, node)) {
|
|
417
|
+
return MUT_ATTACHED;
|
|
418
|
+
}
|
|
419
|
+
uint32_t h = 0;
|
|
420
|
+
if (mut_height(d, node, &h) != 0 || h + 1 > YEP_DOM_MAX_DEPTH) {
|
|
421
|
+
return MUT_DEPTH;
|
|
422
|
+
}
|
|
423
|
+
if (!dom_grow_docs(d, 1)) {
|
|
424
|
+
return MUT_ERR;
|
|
425
|
+
}
|
|
426
|
+
dom_mut_set_att(d, node, 1);
|
|
427
|
+
dom_mut_set_depth(d, node, 0);
|
|
428
|
+
yep_mut_set_depths(d, node, 0);
|
|
429
|
+
d->docs[d->dcount++] = node;
|
|
430
|
+
return 0;
|
|
431
|
+
}
|