void setChunkIndex(List<PackedObjectInfo> objs) { builder.setChunkIndex(ChunkIndex.create(objs)); }
/** * @return the PackChunk instance. * @throws DhtException * if early validation indicates the chunk data is corrupt * or not recognized by this version of the library. */ public PackChunk build() throws DhtException { ChunkIndex i; if (indexBuf != null) i = ChunkIndex.fromBytes(chunkKey, indexBuf, indexPtr, indexLen); else i = null; return new PackChunk(chunkKey, dataBuf, dataPtr, dataLen, i, meta); } }
/** @return the complete size of this chunk, in memory. */ int getTotalSize() { // Assume the index is part of the buffer, and report its total size.. if (dataPtr != 0 || dataLen != dataBuf.length) return dataBuf.length; int sz = dataLen; if (index != null) sz += index.getIndexSize(); return sz; }
/** * Search for an object in the index. * * @param objId * the object to locate. * @return offset of the object in the corresponding chunk; -1 if not found. */ final int findOffset(AnyObjectId objId) { int hi, lo; if (fanout != null) { int fb = objId.getFirstByte(); lo = fb == 0 ? 0 : fanout[fb - 1]; hi = fanout[fb]; } else { lo = 0; hi = count; } while (lo < hi) { final int mid = (lo + hi) >>> 1; final int cmp = objId.compareTo(indexBuf, idPosition(mid)); if (cmp < 0) hi = mid; else if (cmp == 0) return getOffset(mid); else lo = mid + 1; } return -1; }
static byte[] create(List<? extends PackedObjectInfo> list) { int cnt = list.size(); sortObjectList(list); for (PackedObjectInfo oe : list) buckets[oe.getFirstByte()]++; fanoutFormat = selectFanoutFormat(buckets); int offsetFormat = selectOffsetFormat(list); byte[] index = new byte[2 // header + 256 * fanoutFormat // (optional) fanout case 3: for (int i = 0; i < 256; i++, ptr += 3) encodeUInt24(index, ptr, buckets[i]); break; case 4: encodeUInt24(index, ptr, (int) oe.getOffset()); ptr += 3;
int findOffset(RepositoryKey repo, AnyObjectId objId) { if (key.getRepositoryId() == repo.asInt() && index != null) return index.findOffset(objId); return -1; }
/** * Get the offset of an object in the chunk. * * @param nth * offset to return. Must be in range [0, getObjectCount). * @return the offset. */ public final int getOffset(int nth) { return getOffset(indexBuf, offsetTable, nth); }
/** * Get an ObjectId from this index. * * @param nth * the object to return. Must be in range [0, getObjectCount). * @return the object id. */ public final ObjectId getObjectId(int nth) { return ObjectId.fromRaw(indexBuf, idPosition(nth)); }
fanout = new int[256]; for (int i = 0; i < 256; i++) { last += decodeUInt24(indexBuf, ptr + 2 + i * 3); fanout[i] = last;
static byte[] create(List<? extends PackedObjectInfo> list) { int cnt = list.size(); sortObjectList(list); for (PackedObjectInfo oe : list) buckets[oe.getFirstByte()]++; fanoutFormat = selectFanoutFormat(buckets); int offsetFormat = selectOffsetFormat(list); byte[] index = new byte[2 // header + 256 * fanoutFormat // (optional) fanout case 3: for (int i = 0; i < 256; i++, ptr += 3) encodeUInt24(index, ptr, buckets[i]); break; case 4: encodeUInt24(index, ptr, (int) oe.getOffset()); ptr += 3;
/** * Search for an object in the index. * * @param objId * the object to locate. * @return offset of the object in the corresponding chunk; -1 if not found. */ final int findOffset(AnyObjectId objId) { int hi, lo; if (fanout != null) { int fb = objId.getFirstByte(); lo = fb == 0 ? 0 : fanout[fb - 1]; hi = fanout[fb]; } else { lo = 0; hi = count; } while (lo < hi) { final int mid = (lo + hi) >>> 1; final int cmp = objId.compareTo(indexBuf, idPosition(mid)); if (cmp < 0) hi = mid; else if (cmp == 0) return getOffset(mid); else lo = mid + 1; } return -1; }
int findOffset(RepositoryKey repo, AnyObjectId objId) { if (key.getRepositoryId() == repo.asInt() && index != null) return index.findOffset(objId); return -1; }
/** * Get the offset of an object in the chunk. * * @param nth * offset to return. Must be in range [0, getObjectCount). * @return the offset. */ public final int getOffset(int nth) { return getOffset(indexBuf, offsetTable, nth); }
/** * Get an ObjectId from this index. * * @param nth * the object to return. Must be in range [0, getObjectCount). * @return the object id. */ public final ObjectId getObjectId(int nth) { return ObjectId.fromRaw(indexBuf, idPosition(nth)); }
fanout = new int[256]; for (int i = 0; i < 256; i++) { last += decodeUInt24(indexBuf, ptr + 2 + i * 3); fanout[i] = last;
void setChunkIndex(List<PackedObjectInfo> objs) { builder.setChunkIndex(ChunkIndex.create(objs)); }
ObjectId id = ObjectId.fromRaw(dataBuf, posPtr + p); PackChunk nc = pc; int base = pc.index.findOffset(id); if (base < 0) { DhtReader.ChunkAndOffset n;
/** @return the complete size of this chunk, in memory. */ int getTotalSize() { // Assume the index is part of the buffer, and report its total size.. if (dataPtr != 0 || dataLen != dataBuf.length) return dataBuf.length; int sz = dataLen; if (index != null) sz += index.getIndexSize(); return sz; }
/** * @return the PackChunk instance. * @throws DhtException * if early validation indicates the chunk data is corrupt * or not recognized by this version of the library. */ public PackChunk build() throws DhtException { ChunkIndex i; if (indexBuf != null) i = ChunkIndex.fromBytes(chunkKey, indexBuf, indexPtr, indexLen); else i = null; return new PackChunk(chunkKey, dataBuf, dataPtr, dataLen, i, meta); } }
builder.setChunkKey(key); byte[] index = ChunkIndex.create(objectList); info.setIndexSize(index.length); builder.setChunkIndex(index);