From 28f5b79debea57973208c3dfb9eb170fcec5dca4 Mon Sep 17 00:00:00 2001 From: orbiter Date: Wed, 7 Sep 2011 11:42:06 +0000 Subject: [PATCH] added a fast mass-deletion method git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7933 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- source/net/yacy/kelondro/index/RowSet.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/source/net/yacy/kelondro/index/RowSet.java b/source/net/yacy/kelondro/index/RowSet.java index 5e838a3f8..bbc1cccc6 100644 --- a/source/net/yacy/kelondro/index/RowSet.java +++ b/source/net/yacy/kelondro/index/RowSet.java @@ -25,8 +25,10 @@ package net.yacy.kelondro.index; import java.io.IOException; +import java.util.Arrays; import java.util.Collection; import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.Random; import java.util.TreeMap; @@ -234,6 +236,21 @@ public class RowSet extends RowCollection implements Index, Iterable } } + public final synchronized void delete(final List keys) { + final int[] indexes = new int[keys.size()]; + for (int i = 0; i < keys.size(); i++) { + indexes[i] = find(keys.get(i), 0); + } + // we will delete the entries in backward order + // That means it is necessary that the order below the indexes is stable + // therefore we can delete without keeping the order (since it still is stable below the deleted index) + Arrays.sort(indexes); + for (int i = indexes.length - 1; i >= 0; i--) { + if (indexes[i] < 0) break; + super.removeRow(indexes[i], false); + } + } + public final synchronized Row.Entry remove(final byte[] a) { Row.Entry entry = null; int index;