Skip to content

Commit

Permalink
removed unnecessary exceptions, extended testing in IntegerHandleIndex
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@5701 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
orbiter committed Mar 12, 2009
1 parent 13c666a commit 6958eff
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 45 deletions.
7 changes: 1 addition & 6 deletions source/de/anomic/kelondro/blob/HeapReader.java
Expand Up @@ -209,12 +209,7 @@ public synchronized boolean has(final byte[] key) {
assert index.row().primaryKeyLength == key.length : index.row().primaryKeyLength + "!=" + key.length;

// check if the file index contains the key
try {
return index.get(key) >= 0;
} catch (final IOException e) {
e.printStackTrace();
return false;
}
return index.get(key) >= 0;
}

public ByteOrder ordering() {
Expand Down
71 changes: 52 additions & 19 deletions source/de/anomic/kelondro/index/IntegerHandleIndex.java
Expand Up @@ -33,6 +33,7 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Random;
import java.util.concurrent.ArrayBlockingQueue;
Expand All @@ -46,6 +47,7 @@
import de.anomic.kelondro.order.Base64Order;
import de.anomic.kelondro.order.ByteOrder;
import de.anomic.kelondro.order.CloneableIterator;
import de.anomic.kelondro.util.MemoryControl;
import de.anomic.yacy.dht.FlatWordPartitionScheme;

public class IntegerHandleIndex {
Expand Down Expand Up @@ -107,7 +109,7 @@ public Row row() {
return index.row();
}

public void clear() throws IOException {
public void clear() {
this.index.clear();
}

Expand All @@ -116,14 +118,14 @@ public synchronized boolean has(final byte[] key) {
return index.has(key);
}

public synchronized int get(final byte[] key) throws IOException {
public synchronized int get(final byte[] key) {
assert (key != null);
final Row.Entry indexentry = index.get(key);
if (indexentry == null) return -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 (key != null);
final Row.Entry newentry = index.row().newEntry();
Expand All @@ -134,7 +136,7 @@ public synchronized int put(final byte[] key, final int i) throws IOException {
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 a > 0; // it does not make sense to add 0. If this occurres, it is a performance issue

Expand Down Expand Up @@ -164,7 +166,7 @@ public synchronized int inc(final byte[] key, int a) throws IOException {
}
*/

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 (key != null);
final Row.Entry newentry = this.rowdef.newEntry();
Expand All @@ -173,7 +175,7 @@ public synchronized void putUnique(final byte[] key, final int i) throws IOExcep
index.addUnique(newentry);
}

public synchronized ArrayList<Integer[]> removeDoubles() throws IOException {
public synchronized ArrayList<Integer[]> removeDoubles() {
final ArrayList<Integer[]> report = new ArrayList<Integer[]>();
Integer[] is;
int c, i;
Expand All @@ -191,14 +193,14 @@ public synchronized ArrayList<Integer[]> removeDoubles() throws IOException {
return report;
}

public synchronized int remove(final byte[] key) throws IOException {
public synchronized int remove(final byte[] key) {
assert (key != null);
final Row.Entry indexentry = index.remove(key);
if (indexentry == null) return -1;
return (int) indexentry.getColLong(1);
}

public synchronized int removeone() throws IOException {
public synchronized int removeone() {
final Row.Entry indexentry = index.removeOne();
if (indexentry == null) return -1;
return (int) indexentry.getColLong(1);
Expand All @@ -208,11 +210,11 @@ public synchronized int 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);
}

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);
}

Expand Down Expand Up @@ -322,17 +324,48 @@ public IntegerHandleIndex call() throws IOException {
}

public static void main(String[] args) {
int count = (args.length == 0) ? 100000 : Integer.parseInt(args[0]);
IntegerHandleIndex idx = new IntegerHandleIndex(12, Base64Order.enhancedCoder, 100000);
int count = (args.length == 0) ? 1000000 : Integer.parseInt(args[0]);
System.out.println("Starting test with " + count + " objects, minimum memory: " + (count * 16) + " bytes; " + MemoryControl.available(
) + " available");

Random r = new Random(0);
long start = System.currentTimeMillis();
try {
for (int i = 0; i < count; i++) {
idx.inc(FlatWordPartitionScheme.positionToHash(r.nextInt(count / 32)).getBytes(), 1);
}
} catch (IOException e) {
e.printStackTrace();
System.gc(); // for resource measurement
long a = MemoryControl.available();
IntegerHandleIndex idx = new IntegerHandleIndex(12, Base64Order.enhancedCoder, 0);
for (int i = 0; i < count; i++) {
idx.inc(FlatWordPartitionScheme.positionToHash(r.nextInt(count)).getBytes(), 1);
}
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);
}

}
24 changes: 12 additions & 12 deletions source/de/anomic/kelondro/index/LongHandleIndex.java
Expand Up @@ -112,18 +112,18 @@ public Row row() {
return index.row();
}

public void clear() throws IOException {
public void clear() {
index.clear();
}

public synchronized long get(final byte[] key) throws IOException {
public synchronized long get(final byte[] key) {
assert (key != null);
final Row.Entry indexentry = index.get(key);
if (indexentry == null) return -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 (key != null);
final Row.Entry newentry = index.row().newEntry();
Expand All @@ -134,7 +134,7 @@ public synchronized long put(final byte[] key, final long l) throws IOException
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 (key != null);
final Row.Entry newentry = this.rowdef.newEntry();
Expand All @@ -143,7 +143,7 @@ public synchronized void putUnique(final byte[] key, final long l) throws IOExce
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 a > 0; // it does not make sense to add 0. If this occurres, it is a performance issue

Expand All @@ -162,15 +162,15 @@ public synchronized long add(final byte[] key, long a) throws IOException {
}
}

public synchronized long inc(final byte[] key) throws IOException {
public synchronized long inc(final byte[] key) {
return add(key, 1);
}

public synchronized long dec(final byte[] key) throws IOException {
public synchronized long dec(final byte[] key) {
return add(key, -1);
}

public synchronized ArrayList<Long[]> removeDoubles() throws IOException {
public synchronized ArrayList<Long[]> removeDoubles() {
final ArrayList<RowCollection> indexreport = index.removeDoubles();
final ArrayList<Long[]> report = new ArrayList<Long[]>();
Long[] is;
Expand All @@ -186,14 +186,14 @@ public synchronized ArrayList<Long[]> removeDoubles() throws IOException {
return report;
}

public synchronized long remove(final byte[] key) throws IOException {
public synchronized long remove(final byte[] key) {
assert (key != null);
final Row.Entry indexentry = index.remove(key);
if (indexentry == null) return -1;
return indexentry.getColLong(1);
}

public synchronized long removeone() throws IOException {
public synchronized long removeone() {
final Row.Entry indexentry = index.removeOne();
if (indexentry == null) return -1;
return indexentry.getColLong(1);
Expand All @@ -203,11 +203,11 @@ public synchronized int 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);
}

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);
}

Expand Down
3 changes: 2 additions & 1 deletion source/de/anomic/kelondro/index/ObjectIndexCache.java
Expand Up @@ -37,7 +37,8 @@
public class ObjectIndexCache implements ObjectIndex {

private final Row rowdef;
private RowSet index0, index1;
private RowSet index0;
private RowSet index1;
private final Row.EntryComparator entryComparator;

public ObjectIndexCache(final Row rowdef, final int initialspace) {
Expand Down
7 changes: 1 addition & 6 deletions source/de/anomic/kelondro/table/EcoTable.java
Expand Up @@ -666,12 +666,7 @@ public Entry next() {
final byte[] k = i.next();
assert k != null;
if (k == null) return null;
try {
this.c = index.get(k);
} catch (final IOException e) {
e.printStackTrace();
return null;
}
this.c = index.get(k);
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];
if (table == null) {
Expand Down
2 changes: 1 addition & 1 deletion source/de/anomic/kelondro/table/FlexTable.java
Expand Up @@ -164,7 +164,7 @@ private IntegerHandleIndex initializeRamIndex(final int initialSpace) {
}
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()));
try { ri.putUnique(key, i); } catch (final IOException e) {} // no IOException can happen here
ri.putUnique(key, i);
if ((i % 10000) == 0) {
System.out.print('.');
System.out.flush();
Expand Down

0 comments on commit 6958eff

Please sign in to comment.