private List<ChunkKey> toChunkList(Set<DhtInfo> objects) throws DhtException { if (objects == null || objects.isEmpty()) return null; Map<ChunkKey, ChunkOrderingEntry> map = new HashMap<ChunkKey, ChunkOrderingEntry>(); for (DhtInfo obj : objects) { if (!obj.isInPack()) continue; long chunkPtr = obj.chunkPtr; ChunkKey key = chunkOf(chunkPtr); ChunkOrderingEntry e = map.get(key); if (e == null) { e = new ChunkOrderingEntry(); e.key = key; e.order = chunkIdx(chunkPtr); map.put(key, e); } else { e.order = Math.min(e.order, chunkIdx(chunkPtr)); } } ChunkOrderingEntry[] tmp = map.values().toArray( new ChunkOrderingEntry[map.size()]); Arrays.sort(tmp); ChunkKey[] out = new ChunkKey[tmp.length]; for (int i = 0; i < tmp.length; i++) out[i] = tmp[i].key; return Arrays.asList(out); }
private List<ChunkKey> toChunkList(Set<DhtInfo> objects) throws DhtException { if (objects == null || objects.isEmpty()) return null; Map<ChunkKey, ChunkOrderingEntry> map = new HashMap<ChunkKey, ChunkOrderingEntry>(); for (DhtInfo obj : objects) { if (!obj.isInPack()) continue; long chunkPtr = obj.chunkPtr; ChunkKey key = chunkOf(chunkPtr); ChunkOrderingEntry e = map.get(key); if (e == null) { e = new ChunkOrderingEntry(); e.key = key; e.order = chunkIdx(chunkPtr); map.put(key, e); } else { e.order = Math.min(e.order, chunkIdx(chunkPtr)); } } ChunkOrderingEntry[] tmp = map.values().toArray( new ChunkOrderingEntry[map.size()]); Arrays.sort(tmp); ChunkKey[] out = new ChunkKey[tmp.length]; for (int i = 0; i < tmp.length; i++) out[i] = tmp[i].key; return Arrays.asList(out); }
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 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 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; }