private ChunkKey chunkOf(long objectPtr) throws DhtException { List<ChunkKey> list = chunkByOrder[typeOf(objectPtr)]; int idx = chunkIdx(objectPtr); if (list == null || list.size() <= idx) { throw new DhtException(MessageFormat.format( DhtText.get().packParserInvalidPointer, // Constants.typeString(typeOf(objectPtr)), // Integer.valueOf(idx), // Integer.valueOf(offsetOf(objectPtr)))); } return list.get(idx); }
private boolean isInCurrentChunk(long objectPtr) { List<ChunkKey> list = chunkByOrder[typeOf(objectPtr)]; if (list == null) return chunkIdx(objectPtr) == 0; return chunkIdx(objectPtr) == list.size(); }
private boolean isInCurrentChunk(long objectPtr) { List<ChunkKey> list = chunkByOrder[typeOf(objectPtr)]; if (list == null) return chunkIdx(objectPtr) == 0; return chunkIdx(objectPtr) == list.size(); }
private ChunkKey chunkOf(long objectPtr) throws DhtException { List<ChunkKey> list = chunkByOrder[typeOf(objectPtr)]; int idx = chunkIdx(objectPtr); if (list == null || list.size() <= idx) { throw new DhtException(MessageFormat.format( DhtText.get().packParserInvalidPointer, // Constants.typeString(typeOf(objectPtr)), // Integer.valueOf(idx), // Integer.valueOf(offsetOf(objectPtr)))); } return list.get(idx); }
private void computeChunkEdges() throws DhtException { List<DhtInfo> objs = objectListByChunk; int beginIdx = 0; ChunkKey key = chunkOf(objs.get(0).chunkPtr); int type = typeOf(objs.get(0).chunkPtr); int objIdx = 1; for (; objIdx < objs.size(); objIdx++) { DhtInfo oe = objs.get(objIdx); ChunkKey oeKey = chunkOf(oe.chunkPtr); if (!key.equals(oeKey)) { computeEdges(objs.subList(beginIdx, objIdx), key, type); beginIdx = objIdx; key = oeKey; type = typeOf(oe.chunkPtr); } if (type != OBJ_MIXED && type != typeOf(oe.chunkPtr)) type = OBJ_MIXED; } computeEdges(objs.subList(beginIdx, objs.size()), key, type); }
private void computeChunkEdges() throws DhtException { List<DhtInfo> objs = objectListByChunk; int beginIdx = 0; ChunkKey key = chunkOf(objs.get(0).chunkPtr); int type = typeOf(objs.get(0).chunkPtr); int objIdx = 1; for (; objIdx < objs.size(); objIdx++) { DhtInfo oe = objs.get(objIdx); ChunkKey oeKey = chunkOf(oe.chunkPtr); if (!key.equals(oeKey)) { computeEdges(objs.subList(beginIdx, objIdx), key, type); beginIdx = objIdx; key = oeKey; type = typeOf(oe.chunkPtr); } if (type != OBJ_MIXED && type != typeOf(oe.chunkPtr)) type = OBJ_MIXED; } computeEdges(objs.subList(beginIdx, objs.size()), key, type); }
private void putChunkIndexes() throws DhtException { List<DhtInfo> objs = objectListByChunk; int sIdx = 0; DhtInfo oe = objs.get(0); oe.setOffset(offsetOf(oe.chunkPtr)); ChunkKey key = chunkOf(oe.chunkPtr); int type = typeOf(oe.chunkPtr); int objIdx = 1; for (; objIdx < objs.size(); objIdx++) { oe = objs.get(objIdx); oe.setOffset(offsetOf(oe.chunkPtr)); ChunkKey oeKey = chunkOf(oe.chunkPtr); if (!key.equals(oeKey)) { putChunkIndex(objs.subList(sIdx, objIdx), key, type); sIdx = objIdx; key = oeKey; type = typeOf(oe.chunkPtr); } if (type != OBJ_MIXED && type != typeOf(oe.chunkPtr)) type = OBJ_MIXED; } putChunkIndex(objs.subList(sIdx, objs.size()), key, type); }
private void putChunkIndexes() throws DhtException { List<DhtInfo> objs = objectListByChunk; int sIdx = 0; DhtInfo oe = objs.get(0); oe.setOffset(offsetOf(oe.chunkPtr)); ChunkKey key = chunkOf(oe.chunkPtr); int type = typeOf(oe.chunkPtr); int objIdx = 1; for (; objIdx < objs.size(); objIdx++) { oe = objs.get(objIdx); oe.setOffset(offsetOf(oe.chunkPtr)); ChunkKey oeKey = chunkOf(oe.chunkPtr); if (!key.equals(oeKey)) { putChunkIndex(objs.subList(sIdx, objIdx), key, type); sIdx = objIdx; key = oeKey; type = typeOf(oe.chunkPtr); } if (type != OBJ_MIXED && type != typeOf(oe.chunkPtr)) type = OBJ_MIXED; } putChunkIndex(objs.subList(sIdx, objs.size()), key, type); }
private Edges edges(long chunkPtr) throws DhtException { if (isInCurrentChunk(chunkPtr)) { int type = typeOf(chunkPtr); Edges s = openEdges[type]; if (s == null) { s = new Edges(); openEdges[type] = s; } return s; } else { ChunkKey key = chunkOf(chunkPtr); Edges s = chunkEdges.get(key); if (s == null) { s = new Edges(); chunkEdges.put(key, s); } return s; } }
private Edges edges(long chunkPtr) throws DhtException { if (isInCurrentChunk(chunkPtr)) { int type = typeOf(chunkPtr); Edges s = openEdges[type]; if (s == null) { s = new Edges(); openEdges[type] = s; } return s; } else { ChunkKey key = chunkOf(chunkPtr); Edges s = chunkEdges.get(key); if (s == null) { s = new Edges(); chunkEdges.put(key, s); } return s; } }
private void appendToFragment(byte[] raw, int pos, int len) throws DhtException { while (0 < len) { if (currChunk.free() == 0) { int typeCode = typeOf(currChunkPtr); currChunk.setFragment(); currFragments.add(endChunk(typeCode)); currChunk = openChunk(typeCode); } int n = Math.min(len, currChunk.free()); currChunk.append(raw, pos, n); currPackedSize += n; pos += n; len -= n; } }
private void appendToFragment(byte[] raw, int pos, int len) throws DhtException { while (0 < len) { if (currChunk.free() == 0) { int typeCode = typeOf(currChunkPtr); currChunk.setFragment(); currFragments.add(endChunk(typeCode)); currChunk = openChunk(typeCode); } int n = Math.min(len, currChunk.free()); currChunk.append(raw, pos, n); currPackedSize += n; pos += n; len -= n; } }
private boolean longOfsDelta(ChunkFormatter w, long infSize, long basePtr) { final int type = typeOf(basePtr); final List<ChunkKey> infoList = chunkByOrder[type]; final int baseIdx = chunkIdx(basePtr); final ChunkInfo baseInfo = infoByKey.get(infoList.get(baseIdx)); // Go backwards to the start of the base's chunk. long relativeChunkStart = 0; for (int i = infoList.size() - 1; baseIdx <= i; i--) { GitStore.ChunkInfo info = infoByKey.get(infoList.get(i)).getData(); int packSize = info.getChunkSize() - ChunkFormatter.TRAILER_SIZE; relativeChunkStart += packSize; } // Offset to the base goes back to start of our chunk, then start of // the base chunk, but slide forward the distance of the base within // its own chunk. // long ofs = w.position() + relativeChunkStart - offsetOf(basePtr); if (w.ofsDelta(infSize, ofs)) { w.useBaseChunk(relativeChunkStart, baseInfo.getChunkKey()); return true; } return false; }
private boolean longOfsDelta(ChunkFormatter w, long infSize, long basePtr) { final int type = typeOf(basePtr); final List<ChunkKey> infoList = chunkByOrder[type]; final int baseIdx = chunkIdx(basePtr); final ChunkInfo baseInfo = infoByKey.get(infoList.get(baseIdx)); // Go backwards to the start of the base's chunk. long relativeChunkStart = 0; for (int i = infoList.size() - 1; baseIdx <= i; i--) { GitStore.ChunkInfo info = infoByKey.get(infoList.get(i)).getData(); int packSize = info.getChunkSize() - ChunkFormatter.TRAILER_SIZE; relativeChunkStart += packSize; } // Offset to the base goes back to start of our chunk, then start of // the base chunk, but slide forward the distance of the base within // its own chunk. // long ofs = w.position() + relativeChunkStart - offsetOf(basePtr); if (w.ofsDelta(infSize, ofs)) { w.useBaseChunk(relativeChunkStart, baseInfo.getChunkKey()); return true; } return false; }
private void endFragmentedObject() throws DhtException { currChunk.setFragment(); ChunkKey lastKey = endChunk(typeOf(currChunkPtr)); if (lastKey != null) currFragments.add(lastKey); ChunkMeta.Builder protoBuilder = ChunkMeta.newBuilder(); for (ChunkKey key : currFragments) protoBuilder.addFragment(key.asString()); ChunkMeta protoMeta = protoBuilder.build(); for (ChunkKey key : currFragments) { ChunkMeta oldMeta = chunkMeta.get(key); if (oldMeta != null) { ChunkMeta.Builder newMeta = ChunkMeta.newBuilder(oldMeta); newMeta.clearFragment(); newMeta.mergeFrom(protoMeta); ChunkMeta meta = newMeta.build(); dirtyMeta.put(key, meta); chunkMeta.put(key, meta); } else { dirtyMeta.put(key, protoMeta); chunkMeta.put(key, protoMeta); } } currFragments = null; }
private void endFragmentedObject() throws DhtException { currChunk.setFragment(); ChunkKey lastKey = endChunk(typeOf(currChunkPtr)); if (lastKey != null) currFragments.add(lastKey); ChunkMeta.Builder protoBuilder = ChunkMeta.newBuilder(); for (ChunkKey key : currFragments) protoBuilder.addFragment(key.asString()); ChunkMeta protoMeta = protoBuilder.build(); for (ChunkKey key : currFragments) { ChunkMeta oldMeta = chunkMeta.get(key); if (oldMeta != null) { ChunkMeta.Builder newMeta = ChunkMeta.newBuilder(oldMeta); newMeta.clearFragment(); newMeta.mergeFrom(protoMeta); ChunkMeta meta = newMeta.build(); dirtyMeta.put(key, meta); chunkMeta.put(key, meta); } else { dirtyMeta.put(key, protoMeta); chunkMeta.put(key, protoMeta); } } currFragments = null; }
final int hdrPos = offsetOf(currChunkPtr); final int hdrLen = dataPos - hdrPos; final int type = typeOf(currChunkPtr); byte[] dataOld = currChunk.getRawChunkDataArray(); final int typeOld = currChunk.getCurrentObjectType();
final int hdrPos = offsetOf(currChunkPtr); final int hdrLen = dataPos - hdrPos; final int type = typeOf(currChunkPtr); byte[] dataOld = currChunk.getRawChunkDataArray(); final int typeOld = currChunk.getCurrentObjectType();
@Override protected void onBeginOfsDelta(long deltaPos, long basePos, long inflatedSize) throws IOException { long basePtr = objChunkPtrs.get(findStreamIndex(basePos)); int type = typeOf(basePtr); currType = type; currPackedSize = 0; currInflatedSize = inflatedSize; currBasePtr = basePtr; objStreamPos.add(deltaPos); ChunkFormatter w = begin(type); if (isInCurrentChunk(basePtr)) { if (w.ofsDelta(inflatedSize, w.position() - offsetOf(basePtr))) { currDataPos = w.position(); return; } endChunk(type); w = begin(type); } if (!longOfsDelta(w, inflatedSize, basePtr)) { endChunk(type); w = begin(type); if (!longOfsDelta(w, inflatedSize, basePtr)) throw panicCannotInsert(); } currDataPos = w.position(); }
@Override protected void onBeginOfsDelta(long deltaPos, long basePos, long inflatedSize) throws IOException { long basePtr = objChunkPtrs.get(findStreamIndex(basePos)); int type = typeOf(basePtr); currType = type; currPackedSize = 0; currInflatedSize = inflatedSize; currBasePtr = basePtr; objStreamPos.add(deltaPos); ChunkFormatter w = begin(type); if (isInCurrentChunk(basePtr)) { if (w.ofsDelta(inflatedSize, w.position() - offsetOf(basePtr))) { currDataPos = w.position(); return; } endChunk(type); w = begin(type); } if (!longOfsDelta(w, inflatedSize, basePtr)) { endChunk(type); w = begin(type); if (!longOfsDelta(w, inflatedSize, basePtr)) throw panicCannotInsert(); } currDataPos = w.position(); }