@Override protected long index(final int pre, final int id, final byte[] value, final int kind) { final DataAccess store; final TokenObjMap<IntList> map; if (kind == ATTR) { store = values; map = meta.attrindex ? atvBuffer : null; } else { store = texts; // don't index document names map = meta.textindex && kind != DOC ? txtBuffer : null; } // add text to map to index later if (meta.updindex && map != null && value.length <= meta.maxlen) { IntList ids = map.get(value); if (ids == null) { ids = new IntList(1); map.put(value, ids); } ids.add(id); } // add text to text file // inline integer value... final long v = toSimpleInt(value); if (v != Integer.MIN_VALUE) return v | IO.OFFNUM; // store text final long off = store.length(); final byte[] val = COMP.get().pack(value); store.writeToken(off, val); return val == value ? off : off | IO.OFFCOMP; }
@Override public int textLen(final int pre, final boolean text) { final long o = textOff(pre); if (number(o)) return numDigits((int) o); final DataAccess da = text ? texts : values; final int l = da.readNum(o & IO.OFFCOMP - 1); // compressed: next number contains number of compressed bytes return compressed(o) ? da.readNum() : l; }
@Override public synchronized void flush(final boolean all) { try { table.flush(all); if (all) { write(); texts.flush(); values.flush(); if (textIndex != null) ((DiskValues) textIndex).flush(); if (attrIndex != null) ((DiskValues) attrIndex).flush(); } } catch (final IOException ex) { Util.stack(ex); } }
@Override public synchronized void close() { if (closed) return; closed = true; try { write(); table.close(); texts.close(); values.close(); close(IndexType.TEXT); close(IndexType.ATTRIBUTE); close(IndexType.FULLTEXT); } catch (final IOException ex) { Util.stack(ex); } }
@Override protected void updateText(final int pre, final byte[] value, final int kind) { final boolean text = kind != ATTR; if (meta.updindex) { // update indexes final int id = id(pre); final byte[] oldval = text(pre, text); final DiskValues index = (DiskValues) (text ? textIndex : attrIndex); // don't index document names if (index != null && kind != DOC) index.replace(oldval, value, id); } // reference to text store final DataAccess store = text ? texts : values; // file length final long len = store.length(); // new entry (offset or value) final long v = toSimpleInt(value); if (v != Integer.MIN_VALUE) { // inline integer value textOff(pre, v | IO.OFFNUM); } else { // text to be stored (possibly packed) final byte[] val = COMP.get().pack(value); // old entry (offset or value) final long old = textOff(pre); // find text store offset final long off; if (number(old)) { // numeric entry: append new entry at the end off = len; } else { // text size (0 if value will be inlined) final int vl = val.length; off = store.free(old & IO.OFFCOMP - 1, vl + Num.length(vl)); } store.writeToken(off, val); textOff(pre, val == value ? off : off | IO.OFFCOMP); } }