MCPcopy Create free account
hub / github.com/BaseXdb/basex / insert

Method insert

basex-core/src/main/java/org/basex/index/resource/Docs.java:144–175  ·  view source on GitHub ↗

Adds entries to the index and updates subsequent nodes. @param pre insertion position @param clip data clip

(final int pre, final DataClip clip)

Source from the content-addressed store, hash-verified

142 * @param clip data clip
143 */
144 void insert(final int pre, final DataClip clip) {
145 // find all document nodes in the given data instance
146 final IntList il = new IntList();
147 final Data src = clip.data;
148 for(int dpre = clip.start; dpre < clip.end;) {
149 final int k = src.kind(dpre);
150 if(k == Data.DOC) il.add(pre + dpre);
151 dpre += src.size(dpre, k);
152 }
153 final int[] pres = il.finish();
154 final int ps = pres.length;
155
156 // find insertion offset
157 final IntList docs = docs();
158 int i = docs.sortedIndexOf(pre);
159 if(i < 0) i = -i - 1;
160
161 // insert paths from given data instance
162 if(pathIndex) {
163 final TokenList paths = paths();
164 final byte[][] tmp = new byte[ps][];
165 for(int t = 0; t < ps; t++) tmp[t] = normalize(clip.data.text(pres[t] - pre, true));
166 paths.insert(i, tmp);
167 }
168
169 // insert PRE values
170 docs.insert(i, pres);
171 // adjust PRE values of following document nodes
172 docs.incFrom(clip.size(), i + ps);
173
174 update();
175 }
176
177 /**
178 * Deletes the specified entry and updates subsequent nodes.

Callers

nothing calls this directly

Calls 14

kindMethod · 0.95
addMethod · 0.95
sizeMethod · 0.95
finishMethod · 0.95
docsMethod · 0.95
sortedIndexOfMethod · 0.95
pathsMethod · 0.95
normalizeMethod · 0.95
insertMethod · 0.95
incFromMethod · 0.95
updateMethod · 0.95
insertMethod · 0.65

Tested by

no test coverage detected