MCPcopy Index your code
hub / github.com/jankotek/mapdb / treePut

Method treePut

src/main/java/org/mapdb/IndexTreeListJava.java:321–376  ·  view source on GitHub ↗
(
            int dirShift,
            long recid,
            final Store store,
            int level,
            final long index,
            long value)

Source from the content-addressed store, hash-verified

319 }
320
321 static final void treePut(
322 int dirShift,
323 long recid,
324 final Store store,
325 int level,
326 final long index,
327 long value){
328 if(CC.ASSERT && index<0)
329 throw new AssertionError();
330 if(CC.ASSERT && index>>>(level*dirShift)!=0)
331 throw new AssertionError();
332
333
334 for(;level>=0;) {
335 long[] dir = store.get(recid, dirSer);
336 final int slot = treePos(dirShift, level, index);
337 int dirPos = dirOffsetFromSlot(dir,slot);
338 if(dirPos<0){
339 //empty slot, just update
340 dir = dirPut(dir, slot, value, index+1);
341 store.update(recid, dir, dirSer);
342 return;
343 }
344
345 final long oldVal = dir[dirPos];
346 final long oldIndex = dir[dirPos + 1]-1;
347
348 if (oldIndex == -1) {
349 if (oldVal == 0) {
350 throw new AssertionError(); //empty pos, but that should be already covered by dirPos<0
351 } else {
352 //dive deeper
353 recid = oldVal;
354 level--;
355 continue; // recursive call to treePut (sort of)
356 }
357 } else if (oldIndex == index) {
358 //slot is occupied by the same index
359 if (oldVal == value)
360 return; //do not update if same
361 dir = dir.clone();
362 dir[dirPos] = value;
363 store.update(recid, dir, dirSer);
364 } else {
365 // is occupied by the different value, must split it
366 dir = dir.clone();
367 //recid of subdir
368 dir[dirPos] = treePutSub(dirShift, store, level-1, index, value, oldIndex, oldVal);
369 //this is turning into directory
370 dir[dirPos + 1] = 0;
371 store.update(recid, dir, dirSer);
372 }
373 return;
374 }
375 throw new DBException.DataCorruption("level too low");
376 }
377
378 /**

Callers

nothing calls this directly

Calls 6

treePosMethod · 0.95
dirOffsetFromSlotMethod · 0.95
dirPutMethod · 0.95
treePutSubMethod · 0.95
cloneMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected