removed unnecessary exceptions, extended testing in IntegerHandleIndex

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@5701 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 16 years ago
parent 13c666adef
commit 6958eff196

@ -209,12 +209,7 @@ public class HeapReader {
assert index.row().primaryKeyLength == key.length : index.row().primaryKeyLength + "!=" + key.length; assert index.row().primaryKeyLength == key.length : index.row().primaryKeyLength + "!=" + key.length;
// check if the file index contains the key // check if the file index contains the key
try { return index.get(key) >= 0;
return index.get(key) >= 0;
} catch (final IOException e) {
e.printStackTrace();
return false;
}
} }
public ByteOrder ordering() { public ByteOrder ordering() {

@ -33,6 +33,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Random; import java.util.Random;
import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.ArrayBlockingQueue;
@ -46,6 +47,7 @@ import java.util.concurrent.Future;
import de.anomic.kelondro.order.Base64Order; import de.anomic.kelondro.order.Base64Order;
import de.anomic.kelondro.order.ByteOrder; import de.anomic.kelondro.order.ByteOrder;
import de.anomic.kelondro.order.CloneableIterator; import de.anomic.kelondro.order.CloneableIterator;
import de.anomic.kelondro.util.MemoryControl;
import de.anomic.yacy.dht.FlatWordPartitionScheme; import de.anomic.yacy.dht.FlatWordPartitionScheme;
public class IntegerHandleIndex { public class IntegerHandleIndex {
@ -107,7 +109,7 @@ public class IntegerHandleIndex {
return index.row(); return index.row();
} }
public void clear() throws IOException { public void clear() {
this.index.clear(); this.index.clear();
} }
@ -116,14 +118,14 @@ public class IntegerHandleIndex {
return index.has(key); return index.has(key);
} }
public synchronized int get(final byte[] key) throws IOException { public synchronized int get(final byte[] key) {
assert (key != null); assert (key != null);
final Row.Entry indexentry = index.get(key); final Row.Entry indexentry = index.get(key);
if (indexentry == null) return -1; if (indexentry == null) return -1;
return (int) indexentry.getColLong(1); return (int) indexentry.getColLong(1);
} }
public synchronized int put(final byte[] key, final int i) throws IOException { public synchronized int put(final byte[] key, final int i) {
assert i >= 0 : "i = " + i; assert i >= 0 : "i = " + i;
assert (key != null); assert (key != null);
final Row.Entry newentry = index.row().newEntry(); final Row.Entry newentry = index.row().newEntry();
@ -134,7 +136,7 @@ public class IntegerHandleIndex {
return (int) oldentry.getColLong(1); return (int) oldentry.getColLong(1);
} }
public synchronized int inc(final byte[] key, int a) throws IOException { public synchronized int inc(final byte[] key, int a) {
assert key != null; assert key != null;
assert a > 0; // it does not make sense to add 0. If this occurres, it is a performance issue assert a > 0; // it does not make sense to add 0. If this occurres, it is a performance issue
@ -164,7 +166,7 @@ public class IntegerHandleIndex {
} }
*/ */
public synchronized void putUnique(final byte[] key, final int i) throws IOException { public synchronized void putUnique(final byte[] key, final int i) {
assert i >= 0 : "i = " + i; assert i >= 0 : "i = " + i;
assert (key != null); assert (key != null);
final Row.Entry newentry = this.rowdef.newEntry(); final Row.Entry newentry = this.rowdef.newEntry();
@ -173,7 +175,7 @@ public class IntegerHandleIndex {
index.addUnique(newentry); index.addUnique(newentry);
} }
public synchronized ArrayList<Integer[]> removeDoubles() throws IOException { public synchronized ArrayList<Integer[]> removeDoubles() {
final ArrayList<Integer[]> report = new ArrayList<Integer[]>(); final ArrayList<Integer[]> report = new ArrayList<Integer[]>();
Integer[] is; Integer[] is;
int c, i; int c, i;
@ -191,14 +193,14 @@ public class IntegerHandleIndex {
return report; return report;
} }
public synchronized int remove(final byte[] key) throws IOException { public synchronized int remove(final byte[] key) {
assert (key != null); assert (key != null);
final Row.Entry indexentry = index.remove(key); final Row.Entry indexentry = index.remove(key);
if (indexentry == null) return -1; if (indexentry == null) return -1;
return (int) indexentry.getColLong(1); return (int) indexentry.getColLong(1);
} }
public synchronized int removeone() throws IOException { public synchronized int removeone() {
final Row.Entry indexentry = index.removeOne(); final Row.Entry indexentry = index.removeOne();
if (indexentry == null) return -1; if (indexentry == null) return -1;
return (int) indexentry.getColLong(1); return (int) indexentry.getColLong(1);
@ -208,11 +210,11 @@ public class IntegerHandleIndex {
return index.size(); return index.size();
} }
public synchronized CloneableIterator<byte[]> keys(final boolean up, final byte[] firstKey) throws IOException { public synchronized CloneableIterator<byte[]> keys(final boolean up, final byte[] firstKey) {
return index.keys(up, firstKey); return index.keys(up, firstKey);
} }
public synchronized CloneableIterator<Row.Entry> rows(final boolean up, final byte[] firstKey) throws IOException { public synchronized CloneableIterator<Row.Entry> rows(final boolean up, final byte[] firstKey) {
return index.rows(up, firstKey); return index.rows(up, firstKey);
} }
@ -322,17 +324,48 @@ public class IntegerHandleIndex {
} }
public static void main(String[] args) { public static void main(String[] args) {
int count = (args.length == 0) ? 100000 : Integer.parseInt(args[0]); int count = (args.length == 0) ? 1000000 : Integer.parseInt(args[0]);
IntegerHandleIndex idx = new IntegerHandleIndex(12, Base64Order.enhancedCoder, 100000); System.out.println("Starting test with " + count + " objects, minimum memory: " + (count * 16) + " bytes; " + MemoryControl.available(
) + " available");
Random r = new Random(0); Random r = new Random(0);
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
try { System.gc(); // for resource measurement
for (int i = 0; i < count; i++) { long a = MemoryControl.available();
idx.inc(FlatWordPartitionScheme.positionToHash(r.nextInt(count / 32)).getBytes(), 1); IntegerHandleIndex idx = new IntegerHandleIndex(12, Base64Order.enhancedCoder, 0);
} for (int i = 0; i < count; i++) {
} catch (IOException e) { idx.inc(FlatWordPartitionScheme.positionToHash(r.nextInt(count)).getBytes(), 1);
e.printStackTrace();
} }
System.out.println("Result: " + (((long) count) * 1000L / (System.currentTimeMillis() - start)) + " inc per second; " + count + " loops."); long timek = ((long) count) * 1000L / (System.currentTimeMillis() - start);
System.out.println("Result IntegerHandleIndex: " + timek + " inc per second " + count + " loops.");
System.gc();
long memk = a - MemoryControl.available();
System.out.println("Used Memory: " + memk + " bytes");
System.out.println("x " + idx.get(FlatWordPartitionScheme.positionToHash(0).getBytes()));
idx = null;
r = new Random(0);
start = System.currentTimeMillis();
String hash;
Integer d;
System.gc(); // for resource measurement
a = MemoryControl.available();
HashMap<String, Integer> hm = new HashMap<String, Integer>(0);
for (int i = 0; i < count; i++) {
hash = FlatWordPartitionScheme.positionToHash(r.nextInt(count));
d = hm.get(hash);
if (d == null) hm.put(hash, 1); else hm.put(hash, d + 1);
}
long timej = ((long) count) * 1000L / (System.currentTimeMillis() - start);
System.out.println("Result HashMap: " +timej + " inc per second; " + count
+ " loops.");
System.gc();
long memj = a - MemoryControl.available();
System.out.println("Used Memory: " + memj + " bytes");
System.out.println("x " + hm.get(FlatWordPartitionScheme.positionToHash(0)));
System.out.println("Geschwindigkeitsfaktor j/k: " + (timej / timek));
System.out.println("Speicherfaktor j/k: " + (memj / memk));
System.exit(0);
} }
} }

@ -112,18 +112,18 @@ public class LongHandleIndex {
return index.row(); return index.row();
} }
public void clear() throws IOException { public void clear() {
index.clear(); index.clear();
} }
public synchronized long get(final byte[] key) throws IOException { public synchronized long get(final byte[] key) {
assert (key != null); assert (key != null);
final Row.Entry indexentry = index.get(key); final Row.Entry indexentry = index.get(key);
if (indexentry == null) return -1; if (indexentry == null) return -1;
return indexentry.getColLong(1); return indexentry.getColLong(1);
} }
public synchronized long put(final byte[] key, final long l) throws IOException { public synchronized long put(final byte[] key, final long l) {
assert l >= 0 : "l = " + l; assert l >= 0 : "l = " + l;
assert (key != null); assert (key != null);
final Row.Entry newentry = index.row().newEntry(); final Row.Entry newentry = index.row().newEntry();
@ -134,7 +134,7 @@ public class LongHandleIndex {
return oldentry.getColLong(1); return oldentry.getColLong(1);
} }
public synchronized void putUnique(final byte[] key, final long l) throws IOException { public synchronized void putUnique(final byte[] key, final long l) {
assert l >= 0 : "l = " + l; assert l >= 0 : "l = " + l;
assert (key != null); assert (key != null);
final Row.Entry newentry = this.rowdef.newEntry(); final Row.Entry newentry = this.rowdef.newEntry();
@ -143,7 +143,7 @@ public class LongHandleIndex {
index.addUnique(newentry); index.addUnique(newentry);
} }
public synchronized long add(final byte[] key, long a) throws IOException { public synchronized long add(final byte[] key, long a) {
assert key != null; assert key != null;
assert a > 0; // it does not make sense to add 0. If this occurres, it is a performance issue assert a > 0; // it does not make sense to add 0. If this occurres, it is a performance issue
@ -162,15 +162,15 @@ public class LongHandleIndex {
} }
} }
public synchronized long inc(final byte[] key) throws IOException { public synchronized long inc(final byte[] key) {
return add(key, 1); return add(key, 1);
} }
public synchronized long dec(final byte[] key) throws IOException { public synchronized long dec(final byte[] key) {
return add(key, -1); return add(key, -1);
} }
public synchronized ArrayList<Long[]> removeDoubles() throws IOException { public synchronized ArrayList<Long[]> removeDoubles() {
final ArrayList<RowCollection> indexreport = index.removeDoubles(); final ArrayList<RowCollection> indexreport = index.removeDoubles();
final ArrayList<Long[]> report = new ArrayList<Long[]>(); final ArrayList<Long[]> report = new ArrayList<Long[]>();
Long[] is; Long[] is;
@ -186,14 +186,14 @@ public class LongHandleIndex {
return report; return report;
} }
public synchronized long remove(final byte[] key) throws IOException { public synchronized long remove(final byte[] key) {
assert (key != null); assert (key != null);
final Row.Entry indexentry = index.remove(key); final Row.Entry indexentry = index.remove(key);
if (indexentry == null) return -1; if (indexentry == null) return -1;
return indexentry.getColLong(1); return indexentry.getColLong(1);
} }
public synchronized long removeone() throws IOException { public synchronized long removeone() {
final Row.Entry indexentry = index.removeOne(); final Row.Entry indexentry = index.removeOne();
if (indexentry == null) return -1; if (indexentry == null) return -1;
return indexentry.getColLong(1); return indexentry.getColLong(1);
@ -203,11 +203,11 @@ public class LongHandleIndex {
return index.size(); return index.size();
} }
public synchronized CloneableIterator<byte[]> keys(final boolean up, final byte[] firstKey) throws IOException { public synchronized CloneableIterator<byte[]> keys(final boolean up, final byte[] firstKey) {
return index.keys(up, firstKey); return index.keys(up, firstKey);
} }
public synchronized CloneableIterator<Row.Entry> rows(final boolean up, final byte[] firstKey) throws IOException { public synchronized CloneableIterator<Row.Entry> rows(final boolean up, final byte[] firstKey) {
return index.rows(up, firstKey); return index.rows(up, firstKey);
} }

@ -37,7 +37,8 @@ import de.anomic.kelondro.order.StackIterator;
public class ObjectIndexCache implements ObjectIndex { public class ObjectIndexCache implements ObjectIndex {
private final Row rowdef; private final Row rowdef;
private RowSet index0, index1; private RowSet index0;
private RowSet index1;
private final Row.EntryComparator entryComparator; private final Row.EntryComparator entryComparator;
public ObjectIndexCache(final Row rowdef, final int initialspace) { public ObjectIndexCache(final Row rowdef, final int initialspace) {

@ -666,12 +666,7 @@ public class EcoTable implements ObjectIndex {
final byte[] k = i.next(); final byte[] k = i.next();
assert k != null; assert k != null;
if (k == null) return null; if (k == null) return null;
try { this.c = index.get(k);
this.c = index.get(k);
} catch (final IOException e) {
e.printStackTrace();
return null;
}
if (this.c < 0) throw new ConcurrentModificationException(); // this should only happen if the table was modified during the iteration if (this.c < 0) throw new ConcurrentModificationException(); // this should only happen if the table was modified during the iteration
final byte[] b = new byte[rowdef.objectsize]; final byte[] b = new byte[rowdef.objectsize];
if (table == null) { if (table == null) {

@ -164,7 +164,7 @@ public class FlexTable extends FlexWidthArray implements ObjectIndex {
} }
assert (key != null) : "DEBUG: empty key in initializeRamIndex"; // should not happen; if it does, it is an error of the condentNodes iterator assert (key != null) : "DEBUG: empty key in initializeRamIndex"; // should not happen; if it does, it is an error of the condentNodes iterator
//System.out.println("ENTRY: " + serverLog.arrayList(indexentry.bytes(), 0, indexentry.objectsize())); //System.out.println("ENTRY: " + serverLog.arrayList(indexentry.bytes(), 0, indexentry.objectsize()));
try { ri.putUnique(key, i); } catch (final IOException e) {} // no IOException can happen here ri.putUnique(key, i);
if ((i % 10000) == 0) { if ((i % 10000) == 0) {
System.out.print('.'); System.out.print('.');
System.out.flush(); System.out.flush();

Loading…
Cancel
Save