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

Method delete

basex-core/src/main/java/org/basex/index/IdPreMap.java:177–242  ·  view source on GitHub ↗

Deletes records. @param pre PRE of the first record @param id ID of the first deleted record @param c number of deleted records (negative)

(final int pre, final int id, final int c)

Source from the content-addressed store, hash-verified

175 * @param c number of deleted records (negative)
176 */
177 public void delete(final int pre, final int id, final int c) {
178 if(rows == 0 && pre == id && id - c == baseid + 1) {
179 // no mapping, and we delete at the end => nothing to do
180 baseid += c;
181 return;
182 }
183
184 if(rows == 0) {
185 // no previous updates: add a new record
186 add(0, pre, INV, INV, c, id);
187 return;
188 }
189
190 final int end = pre - c - 1;
191 final int startIndex = findPre(pre);
192
193 // remove all updates which has affected records which now have to be deleted
194 final int removeStart = startIndex < rows && pres[startIndex] < pre ?
195 startIndex + 1 : startIndex;
196 int removeEnd = -1;
197 for(int i = startIndex; i < rows; ++i) {
198 if(end < pres[i] + nids[i] - fids[i]) break;
199 removeEnd = i;
200 }
201
202 final int inc;
203 final int oid;
204 int endIndex;
205 if(removeEnd >= 0) {
206 inc = incs[removeEnd];
207 oid = oids[removeEnd];
208 endIndex = removeStart;
209 remove(removeStart, removeEnd);
210 } else {
211 inc = startIndex > 0 ? incs[startIndex - 1] : 0;
212 oid = id;
213 endIndex = startIndex;
214 }
215
216 if(rows <= startIndex) {
217 // the deletion does not affect previous updates
218 add(startIndex, pre, INV, INV, inc + c, oid);
219 return;
220 }
221
222 final int min = pres[startIndex];
223 if(startIndex < endIndex) {
224 if(endIndex < rows && pres[endIndex] <= end) {
225 shrinkFromStart(endIndex, pre, c);
226 } else {
227 --endIndex; // endIndex is not processed, so we let the increment do that
228 }
229 shrinkFromEnd(startIndex, pre, inc + c);
230 } else if(min < pre) {
231 add(++endIndex, pres[startIndex], fids[startIndex], nids[startIndex],
232 incs[startIndex], oids[startIndex]);
233 shrinkFromStart(endIndex, pre, c);
234 shrinkFromEnd(startIndex, pre, inc + c);

Callers

nothing calls this directly

Calls 6

addMethod · 0.95
findPreMethod · 0.95
removeMethod · 0.95
shrinkFromStartMethod · 0.95
shrinkFromEndMethod · 0.95
incrementMethod · 0.95

Tested by

no test coverage detected