@Override public Collection<Block> getBySequenceHash(ByteArray hash) { return mem.getBySequenceHash(hash); }
private static Map<String, List<Block>> retrieveFromIndex(CloneIndex index, String originResourceId, Set<ByteArray> hashes) { Map<String, List<Block>> collection = new HashMap<>(); for (ByteArray hash : hashes) { Collection<Block> blocks = index.getBySequenceHash(hash); for (Block blockFromIndex : blocks) { // Godin: skip blocks for this file if they come from index String resourceId = blockFromIndex.getResourceId(); if (!originResourceId.equals(resourceId)) { List<Block> list = collection.get(resourceId); if (list == null) { list = new ArrayList<>(); collection.put(resourceId, list); } list.add(blockFromIndex); } } } return collection; }
ByteArray hash = entry.getKey(); BlocksGroup group = entry.getValue(); for (Block blockFromIndex : cloneIndex.getBySequenceHash(hash)) {
/** * Given: file with repeated hashes * Expected: only one query of index for each unique hash */ @Test public void only_one_query_of_index_for_each_unique_hash() { CloneIndex index = spy(createIndex()); Block[] fileBlocks = newBlocks("a", "1 2 1 2"); detect(index, fileBlocks); verify(index).getBySequenceHash(new ByteArray("01")); verify(index).getBySequenceHash(new ByteArray("02")); verifyNoMoreInteractions(index); }
/** * Given: index, which accepts blocks with 4-byte hash. * Expected: exception during search by 8-byte hash. */ @Test(expected = IllegalArgumentException.class) public void attempt_to_find_hash_of_incorrect_size() { CloneIndex index = new PackedMemoryCloneIndex(4, 1); index.getBySequenceHash(new ByteArray(1L)); }
@Override public Collection<Block> getBySequenceHash(ByteArray hash) { return mem.getBySequenceHash(hash); }
@Override public Collection<Block> getBySequenceHash(ByteArray hash) { return mem.getBySequenceHash(hash); }
@Override public Collection<Block> getBySequenceHash(ByteArray hash) { if (db == null) { return mem.getBySequenceHash(hash); } else { List<Block> result = Lists.newArrayList(mem.getBySequenceHash(hash)); result.addAll(db.getByHash(hash)); return result; } }
private static Map<String, List<Block>> retrieveFromIndex(CloneIndex index, String originResourceId, Set<ByteArray> hashes) { Map<String, List<Block>> collection = Maps.newHashMap(); for (ByteArray hash : hashes) { Collection<Block> blocks = index.getBySequenceHash(hash); for (Block blockFromIndex : blocks) { // Godin: skip blocks for this file if they come from index String resourceId = blockFromIndex.getResourceId(); if (!originResourceId.equals(resourceId)) { List<Block> list = collection.get(resourceId); if (list == null) { list = Lists.newArrayList(); collection.put(resourceId, list); } list.add(blockFromIndex); } } } return collection; }
ByteArray hash = entry.getKey(); BlocksGroup group = entry.getValue(); for (Block blockFromIndex : cloneIndex.getBySequenceHash(hash)) {