performance tuning using more final modifiers in the kelondro core

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@6402 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 16 years ago
parent cb4de9ceee
commit 2a7fe35f92

@ -30,7 +30,7 @@ import net.yacy.kelondro.order.ByteOrder;
import net.yacy.kelondro.order.NaturalOrder;
public class BinSearch {
public final class BinSearch {
private final byte[] chunks;
private final int chunksize;
@ -43,11 +43,11 @@ public class BinSearch {
this.count = chunks.length / chunksize;
}
public boolean contains(final byte[] t) {
public final boolean contains(final byte[] t) {
return contains(t, 0, this.count);
}
private synchronized boolean contains(final byte[] t, final int beginPos, final int endPos) {
private final synchronized boolean contains(final byte[] t, final int beginPos, final int endPos) {
// the endPos is exclusive, beginPos is inclusive
// this method is synchronized to make the use of the buffer possible
assert t.length == this.chunksize;
@ -61,11 +61,11 @@ public class BinSearch {
return false;
}
public int size() {
public final int size() {
return count;
}
public byte[] get(final int element) {
public final byte[] get(final int element) {
final byte[] a = new byte[chunksize];
System.arraycopy(this.chunks, element * this.chunksize, a, 0, chunksize);
return a;

@ -41,7 +41,7 @@ import net.yacy.kelondro.order.CloneableIterator;
import net.yacy.kelondro.util.MemoryControl;
public class Cache implements ObjectIndex, Iterable<Row.Entry> {
public final class Cache implements ObjectIndex, Iterable<Row.Entry> {
// this is a combined read cache and write buffer
// we maintain four tables:
@ -91,15 +91,15 @@ public class Cache implements ObjectIndex, Iterable<Row.Entry> {
return index.row().objectsize;
}
public int writeBufferSize() {
public final int writeBufferSize() {
return 0;
}
public static long getMemStopGrow() {
public final static long getMemStopGrow() {
return memStopGrow ;
}
public static long getMemStartShrink() {
public final static long getMemStartShrink() {
return memStartShrink ;
}
@ -148,7 +148,7 @@ public class Cache implements ObjectIndex, Iterable<Row.Entry> {
* checks for space in the miss cache
* @return true if it is allowed to write into this cache
*/
private boolean checkMissSpace() {
private final boolean checkMissSpace() {
// returns true if it is allowed to write into this cache
if (readMissCache == null) return false;
long available = MemoryControl.available();
@ -163,7 +163,7 @@ public class Cache implements ObjectIndex, Iterable<Row.Entry> {
* checks for space in the hit cache
* @return true if it is allowed to write into this cache
*/
private boolean checkHitSpace() {
private final boolean checkHitSpace() {
// returns true if it is allowed to write into this cache
if (readHitCache == null) return false;
long available = MemoryControl.available();
@ -174,18 +174,18 @@ public class Cache implements ObjectIndex, Iterable<Row.Entry> {
return (available - 2 * 1024 * 1024 > readHitCache.memoryNeededForGrow());
}
public synchronized void clearCache() {
public final synchronized void clearCache() {
if (readMissCache != null) readMissCache.clear();
if (readHitCache != null) readHitCache.clear();
}
public synchronized void close() {
public final synchronized void close() {
index.close();
readHitCache = null;
readMissCache = null;
}
public synchronized boolean has(final byte[] key) {
public final synchronized boolean has(final byte[] key) {
// first look into the miss cache
if (readMissCache != null) {
if (readMissCache.get(key) == null) {
@ -209,7 +209,7 @@ public class Cache implements ObjectIndex, Iterable<Row.Entry> {
return index.has(key);
}
public synchronized Row.Entry get(final byte[] key) throws IOException {
public final synchronized Row.Entry get(final byte[] key) throws IOException {
// first look into the miss cache
if (readMissCache != null) {
if (readMissCache.get(key) == null) {
@ -250,7 +250,7 @@ public class Cache implements ObjectIndex, Iterable<Row.Entry> {
return entry;
}
public synchronized void put(final Row.Entry row) throws IOException {
public final synchronized void put(final Row.Entry row) throws IOException {
assert (row != null);
assert (row.columns() == row().columns());
//assert (!(serverLog.allZero(row.getColBytes(index.primarykey()))));
@ -280,7 +280,7 @@ public class Cache implements ObjectIndex, Iterable<Row.Entry> {
}
}
public synchronized Row.Entry replace(final Row.Entry row) throws IOException {
public final synchronized Row.Entry replace(final Row.Entry row) throws IOException {
assert (row != null);
assert (row.columns() == row().columns());
//assert (!(serverLog.allZero(row.getColBytes(index.primarykey()))));
@ -313,7 +313,7 @@ public class Cache implements ObjectIndex, Iterable<Row.Entry> {
return entry;
}
public synchronized void addUnique(final Row.Entry row) throws IOException {
public final synchronized void addUnique(final Row.Entry row) throws IOException {
assert (row != null);
assert (row.columns() == row().columns());
//assert (!(serverLog.allZero(row.getColBytes(index.primarykey()))));
@ -342,7 +342,7 @@ public class Cache implements ObjectIndex, Iterable<Row.Entry> {
}
}
public synchronized void addUnique(final Row.Entry row, final Date entryDate) throws IOException {
public final synchronized void addUnique(final Row.Entry row, final Date entryDate) throws IOException {
if (entryDate == null) {
addUnique(row);
return;
@ -368,17 +368,17 @@ public class Cache implements ObjectIndex, Iterable<Row.Entry> {
}
}
public synchronized void addUnique(final List<Row.Entry> rows) throws IOException {
public final synchronized void addUnique(final List<Row.Entry> rows) throws IOException {
final Iterator<Row.Entry> i = rows.iterator();
while (i.hasNext()) addUnique(i.next());
}
public synchronized ArrayList<RowCollection> removeDoubles() throws IOException {
public final synchronized ArrayList<RowCollection> removeDoubles() throws IOException {
return index.removeDoubles();
// todo: remove reported entries from the cache!!!
}
public synchronized Row.Entry remove(final byte[] key) throws IOException {
public final synchronized Row.Entry remove(final byte[] key) throws IOException {
checkMissSpace();
// add entry to miss-cache
@ -407,7 +407,7 @@ public class Cache implements ObjectIndex, Iterable<Row.Entry> {
return index.remove(key);
}
public synchronized Row.Entry removeOne() throws IOException {
public final synchronized Row.Entry removeOne() throws IOException {
checkMissSpace();
@ -425,19 +425,19 @@ public class Cache implements ObjectIndex, Iterable<Row.Entry> {
return entry;
}
public synchronized Row row() {
public final synchronized Row row() {
return index.row();
}
public synchronized CloneableIterator<byte[]> keys(final boolean up, final byte[] firstKey) throws IOException {
public final synchronized CloneableIterator<byte[]> keys(final boolean up, final byte[] firstKey) throws IOException {
return index.keys(up, firstKey);
}
public synchronized CloneableIterator<Row.Entry> rows(final boolean up, final byte[] firstKey) throws IOException {
public final synchronized CloneableIterator<Row.Entry> rows(final boolean up, final byte[] firstKey) throws IOException {
return index.rows(up, firstKey);
}
public Iterator<Entry> iterator() {
public final Iterator<Entry> iterator() {
try {
return rows();
} catch (IOException e) {
@ -445,24 +445,24 @@ public class Cache implements ObjectIndex, Iterable<Row.Entry> {
}
}
public synchronized CloneableIterator<Row.Entry> rows() throws IOException {
public final synchronized CloneableIterator<Row.Entry> rows() throws IOException {
return index.rows();
}
public int size() {
public final int size() {
return index.size();
}
public String filename() {
public final String filename() {
return index.filename();
}
public void clear() throws IOException {
public final void clear() throws IOException {
this.index.clear();
init();
}
public void deleteOnExit() {
public final void deleteOnExit() {
this.index.deleteOnExit();
}

@ -29,7 +29,7 @@ package net.yacy.kelondro.index;
import net.yacy.kelondro.util.kelondroException;
public class Column {
public final class Column {
public static final int celltype_undefined = 0;
public static final int celltype_boolean = 1;
@ -192,7 +192,7 @@ public class Column {
}
}
public String toString() {
public final String toString() {
final StringBuilder s = new StringBuilder();
switch (celltype) {
case celltype_undefined:
@ -245,7 +245,7 @@ public class Column {
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
public final int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + celltype;
@ -260,7 +260,7 @@ public class Column {
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
public final boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)

@ -34,11 +34,10 @@ package net.yacy.kelondro.index;
* at the same size.
*/
public class ConcurrentARC<K, V> implements ARC<K, V> {
public final class ConcurrentARC<K, V> implements ARC<K, V> {
protected int cacheSize;
private int mask;
private ARC<K, V> arc[];
private final ARC<K, V> arc[];
@SuppressWarnings("unchecked")
public ConcurrentARC(final int cacheSize, int partitions) {
@ -54,7 +53,7 @@ public class ConcurrentARC<K, V> implements ARC<K, V> {
* @param s
* @param v
*/
public void put(K s, V v) {
public final void put(K s, V v) {
this.arc[s.hashCode() & mask].put(s, v);
}
@ -63,7 +62,7 @@ public class ConcurrentARC<K, V> implements ARC<K, V> {
* @param s
* @return the value
*/
public V get(K s) {
public final V get(K s) {
return this.arc[s.hashCode() & mask].get(s);
}
@ -72,7 +71,7 @@ public class ConcurrentARC<K, V> implements ARC<K, V> {
* @param s
* @return
*/
public boolean containsKey(K s) {
public final boolean containsKey(K s) {
return this.arc[s.hashCode() & mask].containsKey(s);
}
@ -81,14 +80,14 @@ public class ConcurrentARC<K, V> implements ARC<K, V> {
* @param s
* @return the old value
*/
public V remove(K s) {
public final V remove(K s) {
return this.arc[s.hashCode() & mask].remove(s);
}
/**
* clear the cache
*/
public void clear() {
public final void clear() {
for (ARC<K, V> a: this.arc) a.clear();
}
}

@ -48,7 +48,7 @@ import net.yacy.kelondro.order.ByteOrder;
import net.yacy.kelondro.order.CloneableIterator;
public class HandleMap implements Iterable<Row.Entry> {
public final class HandleMap implements Iterable<Row.Entry> {
private final Row rowdef;
protected ObjectIndexCache index;
@ -92,7 +92,7 @@ public class HandleMap implements Iterable<Row.Entry> {
assert this.index.size() == file.length() / (keylength + idxbytes);
}
public int[] saturation() {
public final int[] saturation() {
int keym = 0;
int valm = this.rowdef.width(1);
int valc;
@ -116,7 +116,7 @@ public class HandleMap implements Iterable<Row.Entry> {
return new int[]{keym, this.rowdef.width(1) - valm};
}
private int eq(byte[] a, byte[] b) {
private final int eq(byte[] a, byte[] b) {
for (int i = 0; i < a.length; i++) {
if (a[i] != b[i]) return i;
}
@ -130,7 +130,7 @@ public class HandleMap implements Iterable<Row.Entry> {
* @return the number of written entries
* @throws IOException
*/
public int dump(File file) throws IOException {
public final int dump(File file) throws IOException {
// we must use an iterator from the combined index, because we need the entries sorted
// otherwise we could just write the byte[] from the in kelondroRowSet which would make
// everything much faster, but this is not an option here.
@ -151,35 +151,35 @@ public class HandleMap implements Iterable<Row.Entry> {
return c;
}
public Row row() {
public final Row row() {
return index.row();
}
public void clear() {
public final void clear() {
index.clear();
}
public synchronized byte[] smallestKey() {
public final synchronized byte[] smallestKey() {
return index.smallestKey();
}
public synchronized byte[] largestKey() {
public final synchronized byte[] largestKey() {
return index.largestKey();
}
public synchronized boolean has(final byte[] key) {
public final synchronized boolean has(final byte[] key) {
assert (key != null);
return index.has(key);
}
public synchronized long get(final byte[] key) {
public final 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) {
public final synchronized long put(final byte[] key, final long l) {
assert l >= 0 : "l = " + l;
assert (key != null);
final Row.Entry newentry = index.row().newEntry();
@ -190,7 +190,7 @@ public class HandleMap implements Iterable<Row.Entry> {
return oldentry.getColLong(1);
}
public synchronized void putUnique(final byte[] key, final long l) {
public final synchronized void putUnique(final byte[] key, final long l) {
assert l >= 0 : "l = " + l;
assert (key != null);
final Row.Entry newentry = this.rowdef.newEntry();
@ -199,7 +199,7 @@ public class HandleMap implements Iterable<Row.Entry> {
index.addUnique(newentry);
}
public synchronized long add(final byte[] key, long a) {
public final 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
@ -217,15 +217,15 @@ public class HandleMap implements Iterable<Row.Entry> {
return i;
}
public synchronized long inc(final byte[] key) {
public final synchronized long inc(final byte[] key) {
return add(key, 1);
}
public synchronized long dec(final byte[] key) {
public final synchronized long dec(final byte[] key) {
return add(key, -1);
}
public synchronized ArrayList<Long[]> removeDoubles() {
public final synchronized ArrayList<Long[]> removeDoubles() {
final ArrayList<Long[]> report = new ArrayList<Long[]>();
Long[] is;
int c;
@ -244,32 +244,32 @@ public class HandleMap implements Iterable<Row.Entry> {
return report;
}
public synchronized long remove(final byte[] key) {
public final 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() {
public final synchronized long removeone() {
final Row.Entry indexentry = index.removeOne();
if (indexentry == null) return -1;
return indexentry.getColLong(1);
}
public synchronized int size() {
public final synchronized int size() {
return index.size();
}
public synchronized CloneableIterator<byte[]> keys(final boolean up, final byte[] firstKey) {
public final 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) {
public final synchronized CloneableIterator<Row.Entry> rows(final boolean up, final byte[] firstKey) {
return index.rows(up, firstKey);
}
public synchronized void close() {
public final synchronized void close() {
index.close();
index = null;
}
@ -284,7 +284,7 @@ public class HandleMap implements Iterable<Row.Entry> {
* @param bufferSize
* @return
*/
public static initDataConsumer asynchronusInitializer(final int keylength, final ByteOrder objectOrder, int idxbytes, final int space, final int expectedspace) {
public final static initDataConsumer asynchronusInitializer(final int keylength, final ByteOrder objectOrder, int idxbytes, final int space, final int expectedspace) {
initDataConsumer initializer = new initDataConsumer(new HandleMap(keylength, objectOrder, idxbytes, space, expectedspace));
ExecutorService service = Executors.newSingleThreadExecutor();
initializer.setResult(service.submit(initializer));
@ -292,7 +292,7 @@ public class HandleMap implements Iterable<Row.Entry> {
return initializer;
}
private static class entry {
private final static class entry {
public byte[] key;
public long l;
public entry(final byte[] key, final long l) {
@ -303,7 +303,7 @@ public class HandleMap implements Iterable<Row.Entry> {
protected static final entry poisonEntry = new entry(new byte[0], 0);
public static class initDataConsumer implements Callable<HandleMap> {
public final static class initDataConsumer implements Callable<HandleMap> {
private BlockingQueue<entry> cache;
private HandleMap map;
@ -316,7 +316,7 @@ public class HandleMap implements Iterable<Row.Entry> {
sortAtEnd = false;
}
protected void setResult(Future<HandleMap> result) {
protected final void setResult(Future<HandleMap> result) {
this.result = result;
}
@ -325,7 +325,7 @@ public class HandleMap implements Iterable<Row.Entry> {
* @param key
* @param l
*/
public void consume(final byte[] key, final long l) {
public final void consume(final byte[] key, final long l) {
try {
cache.put(new entry(key, l));
} catch (InterruptedException e) {
@ -337,7 +337,7 @@ public class HandleMap implements Iterable<Row.Entry> {
* to signal the initialization thread that no more entries will be submitted with consumer()
* this method must be called. The process will not terminate if this is not called before.
*/
public void finish(boolean sortAtEnd) {
public final void finish(boolean sortAtEnd) {
this.sortAtEnd = sortAtEnd;
try {
cache.put(poisonEntry);
@ -354,11 +354,11 @@ public class HandleMap implements Iterable<Row.Entry> {
* @throws InterruptedException
* @throws ExecutionException
*/
public HandleMap result() throws InterruptedException, ExecutionException {
public final HandleMap result() throws InterruptedException, ExecutionException {
return this.result.get();
}
public HandleMap call() throws IOException {
public final HandleMap call() throws IOException {
try {
entry c;
while ((c = cache.take()) != poisonEntry) {

@ -38,7 +38,7 @@ import net.yacy.kelondro.order.ByteOrder;
import net.yacy.kelondro.order.CloneableIterator;
public class HandleSet implements Iterable<byte[]> {
public final class HandleSet implements Iterable<byte[]> {
private final Row rowdef;
private ObjectIndex index;
@ -77,7 +77,7 @@ public class HandleSet implements Iterable<byte[]> {
* @return the number of written entries
* @throws IOException
*/
public int dump(File file) throws IOException {
public final int dump(File file) throws IOException {
// we must use an iterator from the combined index, because we need the entries sorted
// otherwise we could just write the byte[] from the in kelondroRowSet which would make
// everything much faster, but this is not an option here.
@ -93,20 +93,20 @@ public class HandleSet implements Iterable<byte[]> {
return c;
}
public Row row() {
public final Row row() {
return index.row();
}
public void clear() throws IOException {
public final void clear() throws IOException {
this.index.clear();
}
public synchronized boolean has(final byte[] key) {
public final synchronized boolean has(final byte[] key) {
assert (key != null);
return index.has(key);
}
public synchronized int put(final byte[] key) throws IOException {
public final synchronized int put(final byte[] key) throws IOException {
assert (key != null);
final Row.Entry newentry = index.row().newEntry();
newentry.setCol(0, key);
@ -115,31 +115,31 @@ public class HandleSet implements Iterable<byte[]> {
return (int) oldentry.getColLong(1);
}
public synchronized void putUnique(final byte[] key) throws IOException {
public final synchronized void putUnique(final byte[] key) throws IOException {
assert (key != null);
final Row.Entry newentry = this.rowdef.newEntry();
newentry.setCol(0, key);
index.addUnique(newentry);
}
public synchronized int remove(final byte[] key) throws IOException {
public final synchronized int remove(final byte[] key) throws IOException {
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 final synchronized int removeone() throws IOException {
final Row.Entry indexentry = index.removeOne();
if (indexentry == null) return -1;
return (int) indexentry.getColLong(1);
}
public synchronized int size() {
public final synchronized int size() {
return index.size();
}
public synchronized CloneableIterator<byte[]> keys(final boolean up, final byte[] firstKey) {
public final synchronized CloneableIterator<byte[]> keys(final boolean up, final byte[] firstKey) {
try {
return index.keys(up, firstKey);
} catch (IOException e) {
@ -148,11 +148,11 @@ public class HandleSet implements Iterable<byte[]> {
}
}
public Iterator<byte[]> iterator() {
public final Iterator<byte[]> iterator() {
return keys(true, null);
}
public synchronized void close() {
public final synchronized void close() {
index.close();
index = null;
}

@ -32,7 +32,7 @@ import java.util.Random;
import net.yacy.kelondro.order.NaturalOrder;
public class ObjectArrayCache {
public final class ObjectArrayCache {
// we use two indexes: one for initialization, and one for data aquired during runtime
// this has a gread advantage, if the setup-data is large. Then a re-organisation of
@ -43,7 +43,7 @@ public class ObjectArrayCache {
private final Row rowdef;
private final RowSet index0;
private RowSet index1;
private RowSet index1;
//private final kelondroOrder<kelondroRow.Entry> entryOrder;
public ObjectArrayCache(final int payloadSize, final int initSize) {
@ -53,17 +53,17 @@ public class ObjectArrayCache {
//this.entryOrder = new kelondroRow.EntryComparator(rowdef.objectOrder);
}
public long memoryNeededForGrow() {
public final long memoryNeededForGrow() {
if (index1 == null)
return index0.memoryNeededForGrow();
return index1.memoryNeededForGrow();
}
public Row row() {
public final Row row() {
return index0.row();
}
public byte[] getb(final int ii) {
public final byte[] getb(final int ii) {
assert ii >= 0 : "i = " + ii;
final byte[] key = NaturalOrder.encodeLong(ii, 4);
if (index0 != null) {
@ -82,7 +82,7 @@ public class ObjectArrayCache {
return indexentry.getColBytes(1);
}
public byte[] putb(final int ii, final byte[] value) {
public final byte[] putb(final int ii, final byte[] value) {
assert ii >= 0 : "i = " + ii;
assert value != null;
final byte[] key = NaturalOrder.encodeLong(ii, 4);
@ -114,7 +114,7 @@ public class ObjectArrayCache {
return oldentry.getColBytes(1);
}
public void addb(final int ii, final byte[] value) {
public final void addb(final int ii, final byte[] value) {
assert index1 == null; // valid only in init-phase
assert ii >= 0 : "i = " + ii;
assert value != null;
@ -124,7 +124,7 @@ public class ObjectArrayCache {
index0.addUnique(newentry);
}
public byte[] removeb(final int ii) {
public final byte[] removeb(final int ii) {
assert ii >= 0 : "i = " + ii;
final byte[] key = NaturalOrder.encodeLong(ii, 4);
@ -149,7 +149,7 @@ public class ObjectArrayCache {
return indexentry.getColBytes(1);
}
public byte[] removeoneb() {
public final byte[] removeoneb() {
if ((index1 != null) && (index1.size() != 0)) {
final Row.Entry indexentry = index1.removeOne();
assert (indexentry != null);
@ -167,7 +167,7 @@ public class ObjectArrayCache {
return null;
}
public int size() {
public final int size() {
if ((index0 != null) && (index1 == null)) {
//assert consistencyAnalysis0() : "consistency problem: " + consistencyAnalysis();
return index0.size();
@ -181,7 +181,7 @@ public class ObjectArrayCache {
return index0.size() + index1.size();
}
public Iterator<Row.Entry> rows() {
public final Iterator<Row.Entry> rows() {
if (index0 != null) {
if (index1 == null) {
// finish initialization phase
@ -196,7 +196,7 @@ public class ObjectArrayCache {
}
}
public void flush() {
public final void flush() {
if (index0 != null) {
index0.sort();
index0.trim(true);

@ -34,7 +34,7 @@ import net.yacy.kelondro.order.MergeIterator;
import net.yacy.kelondro.order.StackIterator;
public class ObjectIndexCache implements ObjectIndex, Iterable<Row.Entry> {
public final class ObjectIndexCache implements ObjectIndex, Iterable<Row.Entry> {
private final Row rowdef;
private RowSet index0;
@ -53,13 +53,13 @@ public class ObjectIndexCache implements ObjectIndex, Iterable<Row.Entry> {
reset(0);
}
public synchronized void reset(final int initialspace) {
public final synchronized void reset(final int initialspace) {
this.index0 = null; // first flush RAM to make room
this.index0 = new RowSet(rowdef, initialspace);
this.index1 = null; // to show that this is the initialization phase
}
public Row row() {
public final Row row() {
return index0.row();
}
@ -73,7 +73,7 @@ public class ObjectIndexCache implements ObjectIndex, Iterable<Row.Entry> {
}
}
public synchronized byte[] smallestKey() {
public final synchronized byte[] smallestKey() {
byte[] b0 = index0.smallestKey();
if (b0 == null) return null;
if (index1 == null) return b0;
@ -82,7 +82,7 @@ public class ObjectIndexCache implements ObjectIndex, Iterable<Row.Entry> {
return b1;
}
public synchronized byte[] largestKey() {
public final synchronized byte[] largestKey() {
byte[] b0 = index0.largestKey();
if (b0 == null) return null;
if (index1 == null) return b0;
@ -91,7 +91,7 @@ public class ObjectIndexCache implements ObjectIndex, Iterable<Row.Entry> {
return b1;
}
public synchronized Row.Entry get(final byte[] key) {
public final synchronized Row.Entry get(final byte[] key) {
assert (key != null);
finishInitialization();
assert index0.isSorted();
@ -100,7 +100,7 @@ public class ObjectIndexCache implements ObjectIndex, Iterable<Row.Entry> {
return index1.get(key);
}
public synchronized boolean has(final byte[] key) {
public final synchronized boolean has(final byte[] key) {
assert (key != null);
finishInitialization();
assert index0.isSorted();
@ -108,7 +108,7 @@ public class ObjectIndexCache implements ObjectIndex, Iterable<Row.Entry> {
return index1.has(key);
}
public synchronized Row.Entry replace(final Row.Entry entry) {
public final synchronized Row.Entry replace(final Row.Entry entry) {
assert (entry != null);
finishInitialization();
// if the new entry is within the initialization part, just overwrite it
@ -122,7 +122,7 @@ public class ObjectIndexCache implements ObjectIndex, Iterable<Row.Entry> {
return index1.replace(entry);
}
public synchronized void put(final Row.Entry entry) {
public final synchronized void put(final Row.Entry entry) {
assert (entry != null);
if (entry == null) return;
finishInitialization();
@ -137,7 +137,7 @@ public class ObjectIndexCache implements ObjectIndex, Iterable<Row.Entry> {
index1.put(entry);
}
public synchronized void addUnique(final Row.Entry entry) {
public final synchronized void addUnique(final Row.Entry entry) {
assert (entry != null);
if (entry == null) return;
if (index1 == null) {
@ -149,12 +149,12 @@ public class ObjectIndexCache implements ObjectIndex, Iterable<Row.Entry> {
index1.addUnique(entry);
}
public void addUnique(final List<Entry> rows) {
public final void addUnique(final List<Entry> rows) {
final Iterator<Entry> i = rows.iterator();
while (i.hasNext()) addUnique(i.next());
}
public synchronized long inc(final byte[] key, int col, long add, Row.Entry initrow) {
public final synchronized long inc(final byte[] key, int col, long add, Row.Entry initrow) {
assert (key != null);
finishInitialization();
assert index0.isSorted();
@ -163,7 +163,7 @@ public class ObjectIndexCache implements ObjectIndex, Iterable<Row.Entry> {
return index1.inc(key, col, add, initrow);
}
public synchronized ArrayList<RowCollection> removeDoubles() {
public final synchronized ArrayList<RowCollection> removeDoubles() {
// finish initialization phase explicitely
index0.sort();
if (index1 == null) {
@ -175,7 +175,7 @@ public class ObjectIndexCache implements ObjectIndex, Iterable<Row.Entry> {
return d0;
}
public synchronized Row.Entry remove(final byte[] key) {
public final synchronized Row.Entry remove(final byte[] key) {
finishInitialization();
// if the new entry is within the initialization part, just delete it
final Row.Entry indexentry = index0.remove(key);
@ -189,7 +189,7 @@ public class ObjectIndexCache implements ObjectIndex, Iterable<Row.Entry> {
return removed;
}
public synchronized Row.Entry removeOne() {
public final synchronized Row.Entry removeOne() {
if ((index1 != null) && (index1.size() != 0)) {
return index1.removeOne();
}
@ -199,7 +199,7 @@ public class ObjectIndexCache implements ObjectIndex, Iterable<Row.Entry> {
return null;
}
public synchronized int size() {
public final synchronized int size() {
if ((index0 != null) && (index1 == null)) {
return index0.size();
}
@ -210,7 +210,7 @@ public class ObjectIndexCache implements ObjectIndex, Iterable<Row.Entry> {
return index0.size() + index1.size();
}
public synchronized CloneableIterator<byte[]> keys(final boolean up, final byte[] firstKey) {
public final synchronized CloneableIterator<byte[]> keys(final boolean up, final byte[] firstKey) {
// returns the key-iterator of the underlying kelondroIndex
if (index1 == null) {
// finish initialization phase
@ -239,7 +239,7 @@ public class ObjectIndexCache implements ObjectIndex, Iterable<Row.Entry> {
true);
}
public synchronized CloneableIterator<Row.Entry> rows(final boolean up, final byte[] firstKey) {
public final synchronized CloneableIterator<Row.Entry> rows(final boolean up, final byte[] firstKey) {
// returns the row-iterator of the underlying kelondroIndex
if (index1 == null) {
// finish initialization phase
@ -269,11 +269,11 @@ public class ObjectIndexCache implements ObjectIndex, Iterable<Row.Entry> {
true);
}
public Iterator<Entry> iterator() {
public final Iterator<Entry> iterator() {
return rows();
}
public synchronized CloneableIterator<Row.Entry> rows() {
public final synchronized CloneableIterator<Row.Entry> rows() {
// returns the row-iterator of the underlying kelondroIndex
if (index1 == null) {
// finish initialization phase
@ -294,16 +294,16 @@ public class ObjectIndexCache implements ObjectIndex, Iterable<Row.Entry> {
return new StackIterator<Row.Entry>(index0.rows(), index1.rows());
}
public synchronized void close() {
public final synchronized void close() {
if (index0 != null) index0.close();
if (index1 != null) index1.close();
}
public String filename() {
public final String filename() {
return null; // this does not have a file name
}
public void deleteOnExit() {
public final void deleteOnExit() {
// do nothing, there is no file
}

@ -57,12 +57,12 @@ public class RowCollection implements Iterable<Row.Entry> {
public static final ExecutorService sortingthreadexecutor = (availableCPU > 1) ? Executors.newCachedThreadPool(new NamePrefixThreadFactory("sorting")) : null;
public static final ExecutorService partitionthreadexecutor = (availableCPU > 1) ? Executors.newCachedThreadPool(new NamePrefixThreadFactory("partition")) : null;
protected byte[] chunkcache;
protected int chunkcount;
protected long lastTimeWrote;
public Row rowdef;
protected int sortBound;
public final Row rowdef;
protected byte[] chunkcache;
protected int chunkcount;
protected int sortBound;
protected long lastTimeWrote;
private static final int exp_chunkcount = 0;
private static final int exp_last_read = 1;
private static final int exp_last_wrote = 2;

@ -62,7 +62,7 @@ public class RowSet extends RowCollection implements ObjectIndex, Iterable<Row.E
assert rowdef.objectOrder != null;
}
public static RowSet importRowSet(byte[] b, final Row rowdef) {
public final static RowSet importRowSet(byte[] b, final Row rowdef) {
assert b.length >= exportOverheadSize : "b.length = " + b.length;
if (b.length < exportOverheadSize) return new RowSet(rowdef, 0);
final int size = (int) NaturalOrder.decodeLong(b, 0, 4);
@ -82,18 +82,18 @@ public class RowSet extends RowCollection implements ObjectIndex, Iterable<Row.E
super.reset();
}
public synchronized boolean has(final byte[] key) {
public final synchronized boolean has(final byte[] key) {
final int index = find(key, 0, key.length);
return index >= 0;
}
public synchronized Row.Entry get(final byte[] key) {
public final synchronized Row.Entry get(final byte[] key) {
final int index = find(key, 0, key.length);
if (index < 0) return null;
return get(index, true);
}
public synchronized void put(final Row.Entry entry) {
public final synchronized void put(final Row.Entry entry) {
assert (entry != null);
assert (entry.getPrimaryKeyBytes() != null);
// when reaching a specific amount of un-sorted entries, re-sort all
@ -110,7 +110,7 @@ public class RowSet extends RowCollection implements ObjectIndex, Iterable<Row.E
}
}
public synchronized Row.Entry replace(final Row.Entry entry) {
public final synchronized Row.Entry replace(final Row.Entry entry) {
assert (entry != null);
assert (entry.getPrimaryKeyBytes() != null);
int index = -1;
@ -131,7 +131,7 @@ public class RowSet extends RowCollection implements ObjectIndex, Iterable<Row.E
return oldentry;
}
public synchronized long inc(byte[] key, int col, long add, Row.Entry initrow) {
public final synchronized long inc(byte[] key, int col, long add, Row.Entry initrow) {
final int index = find(key, 0, key.length);
if (index >= 0) {
// the entry existed before
@ -150,7 +150,7 @@ public class RowSet extends RowCollection implements ObjectIndex, Iterable<Row.E
}
}
private Row.Entry remove(final byte[] a, final int start, final int length) {
private final Row.Entry remove(final byte[] a, final int start, final int length) {
final int index = find(a, start, length);
if (index < 0) {
return null;
@ -179,7 +179,7 @@ public class RowSet extends RowCollection implements ObjectIndex, Iterable<Row.E
return entry;
}
private int find(final byte[] a, final int astart, final int alength) {
private final int find(final byte[] a, final int astart, final int alength) {
// returns the chunknumber; -1 if not found
if (rowdef.objectOrder == null) return iterativeSearch(a, astart, alength, 0, this.chunkcount);
@ -206,7 +206,7 @@ public class RowSet extends RowCollection implements ObjectIndex, Iterable<Row.E
}
}
private int iterativeSearch(final byte[] key, final int astart, final int alength, final int leftBorder, final int rightBound) {
private final int iterativeSearch(final byte[] key, final int astart, final int alength, final int leftBorder, final int rightBound) {
// returns the chunknumber
for (int i = leftBorder; i < rightBound; i++) {
if (match(key, astart, alength, i)) return i;
@ -214,7 +214,7 @@ public class RowSet extends RowCollection implements ObjectIndex, Iterable<Row.E
return -1;
}
private int binarySearch(final byte[] key, final int astart, final int alength) {
private final int binarySearch(final byte[] key, final int astart, final int alength) {
// returns the exact position of the key if the key exists,
// or -1 if the key does not exist
assert (rowdef.objectOrder != null);
@ -231,7 +231,7 @@ public class RowSet extends RowCollection implements ObjectIndex, Iterable<Row.E
return -1;
}
protected int binaryPosition(final byte[] key, final int astart, final int alength) {
protected final int binaryPosition(final byte[] key, final int astart, final int alength) {
// returns the exact position of the key if the key exists,
// or a position of an entry that is greater than the key if the
// key does not exist
@ -249,16 +249,16 @@ public class RowSet extends RowCollection implements ObjectIndex, Iterable<Row.E
return l;
}
public synchronized Iterator<byte[]> keys() {
public final synchronized Iterator<byte[]> keys() {
sort();
return super.keys(true);
}
public synchronized CloneableIterator<byte[]> keys(final boolean up, final byte[] firstKey) {
public final synchronized CloneableIterator<byte[]> keys(final boolean up, final byte[] firstKey) {
return new keyIterator(up, firstKey);
}
public class keyIterator implements CloneableIterator<byte[]> {
public final class keyIterator implements CloneableIterator<byte[]> {
private final boolean up;
private final byte[] first;
@ -279,11 +279,11 @@ public class RowSet extends RowCollection implements ObjectIndex, Iterable<Row.E
}
}
public keyIterator clone(final Object second) {
public final keyIterator clone(final Object second) {
return new keyIterator(up, (byte[]) second);
}
public boolean hasNext() {
public final boolean hasNext() {
if (p < 0) return false;
if (p >= size()) return false;
if (up) {
@ -293,32 +293,32 @@ public class RowSet extends RowCollection implements ObjectIndex, Iterable<Row.E
}
}
public byte[] next() {
public final byte[] next() {
final byte[] key = getKey(p);
if (up) p++; else p--;
return key;
}
public void remove() {
public final void remove() {
throw new UnsupportedOperationException();
}
}
public synchronized Iterator<Row.Entry> iterator() {
public final synchronized Iterator<Row.Entry> iterator() {
// iterates kelondroRow.Entry - type entries
sort();
return super.iterator();
}
public synchronized CloneableIterator<Row.Entry> rows(final boolean up, final byte[] firstKey) {
public final synchronized CloneableIterator<Row.Entry> rows(final boolean up, final byte[] firstKey) {
return new rowIterator(up, firstKey);
}
public synchronized CloneableIterator<Row.Entry> rows() {
public final synchronized CloneableIterator<Row.Entry> rows() {
return new rowIterator(true, null);
}
public class rowIterator implements CloneableIterator<Row.Entry> {
public final class rowIterator implements CloneableIterator<Row.Entry> {
private final boolean up;
private final byte[] first;
@ -339,11 +339,11 @@ public class RowSet extends RowCollection implements ObjectIndex, Iterable<Row.E
}
}
public rowIterator clone(final Object second) {
public final rowIterator clone(final Object second) {
return new rowIterator(up, (byte[]) second);
}
public boolean hasNext() {
public final boolean hasNext() {
if (p < 0) return false;
if (p >= size()) return false;
if (up) {
@ -353,13 +353,13 @@ public class RowSet extends RowCollection implements ObjectIndex, Iterable<Row.E
}
}
public Row.Entry next() {
public final Row.Entry next() {
final Row.Entry entry = get(p, true);
if (up) p++; else p--;
return entry;
}
public void remove() {
public final void remove() {
throw new UnsupportedOperationException();
}
}
@ -372,7 +372,7 @@ public class RowSet extends RowCollection implements ObjectIndex, Iterable<Row.E
* @param c
* @return
*/
public RowSet merge(RowSet c) {
public final RowSet merge(RowSet c) {
assert c != null;
/*
if (this.isSorted() && this.size() >= c.size()) {
@ -400,7 +400,7 @@ public class RowSet extends RowCollection implements ObjectIndex, Iterable<Row.E
* @param c
* @return
*/
protected static RowSet mergeEnum(RowCollection c0, RowCollection c1) {
protected final static RowSet mergeEnum(RowCollection c0, RowCollection c1) {
assert c0.rowdef == c1.rowdef : c0.rowdef.toString() + " != " + c1.rowdef.toString();
RowSet r = new RowSet(c0.rowdef, c0.size() + c1.size());
try {

@ -32,7 +32,7 @@ import net.yacy.kelondro.order.MergeIterator;
import net.yacy.kelondro.order.StackIterator;
public class RowSetArray implements ObjectIndex, Iterable<Row.Entry> {
public final class RowSetArray implements ObjectIndex, Iterable<Row.Entry> {
private final int objectCount;
private final Row rowdef;
@ -47,15 +47,15 @@ public class RowSetArray implements ObjectIndex, Iterable<Row.Entry> {
this.objectCount = objectCount / arraySize;
}
private int indexFor(byte[] key) {
private final int indexFor(byte[] key) {
return (int) (this.rowdef.objectOrder.cardinal(key) % ((long) array.length));
}
private int indexFor(Entry row) {
private final int indexFor(Entry row) {
return (int) (this.rowdef.objectOrder.cardinal(row.bytes(), 0, row.getPrimaryKeyLength()) % ((long) array.length));
}
private RowSet accessArray(int i) {
private final RowSet accessArray(int i) {
RowSet r = this.array[i];
if (r == null) synchronized (this.array) {
r = new RowSet(this.rowdef, this.objectCount);
@ -64,17 +64,17 @@ public class RowSetArray implements ObjectIndex, Iterable<Row.Entry> {
return r;
}
public void addUnique(Entry row) {
public final void addUnique(Entry row) {
int i = indexFor(row);
if (i < 0) return;
accessArray(i).addUnique(row);
}
public void addUnique(List<Entry> rows) {
public final void addUnique(List<Entry> rows) {
for (Entry row: rows) addUnique(row);
}
public void clear() {
public final void clear() {
synchronized (this.array) {
for (int i = 0; i < this.array.length; i++) {
if (this.array[i] != null) this.array[i].clear();
@ -83,20 +83,20 @@ public class RowSetArray implements ObjectIndex, Iterable<Row.Entry> {
}
}
public void close() {
public final void close() {
clear();
}
public void deleteOnExit() {
public final void deleteOnExit() {
// no nothing here
}
public String filename() {
public final String filename() {
// we don't have a file name
return null;
}
public Entry get(byte[] key) {
public final Entry get(byte[] key) {
int i = indexFor(key);
if (i < 0) return null;
RowSet r = this.array[i];
@ -104,7 +104,7 @@ public class RowSetArray implements ObjectIndex, Iterable<Row.Entry> {
return r.get(key);
}
public boolean has(byte[] key) {
public final boolean has(byte[] key) {
int i = indexFor(key);
if (i < 0) return false;
RowSet r = this.array[i];
@ -112,7 +112,7 @@ public class RowSetArray implements ObjectIndex, Iterable<Row.Entry> {
return r.has(key);
}
public CloneableIterator<byte[]> keys(boolean up, byte[] firstKey) {
public final CloneableIterator<byte[]> keys(boolean up, byte[] firstKey) {
synchronized (this.array) {
Collection<CloneableIterator<byte[]>> col = new ArrayList<CloneableIterator<byte[]>>();
for (int i = 0; i < this.array.length; i++) {
@ -125,19 +125,19 @@ public class RowSetArray implements ObjectIndex, Iterable<Row.Entry> {
}
}
public void put(Entry row) {
public final void put(Entry row) {
int i = indexFor(row);
if (i < 0) return;
accessArray(i).put(row);
}
public Entry remove(byte[] key) {
public final Entry remove(byte[] key) {
int i = indexFor(key);
if (i < 0) return null;
return accessArray(i).remove(key);
}
public ArrayList<RowCollection> removeDoubles() {
public final ArrayList<RowCollection> removeDoubles() {
ArrayList<RowCollection> col = new ArrayList<RowCollection>();
synchronized (this.array) {
for (int i = 0; i < this.array.length; i++) {
@ -150,7 +150,7 @@ public class RowSetArray implements ObjectIndex, Iterable<Row.Entry> {
return col;
}
public Entry removeOne() {
public final Entry removeOne() {
synchronized (this.array) {
for (int i = 0; i < this.array.length; i++) {
if (this.array[i] != null) {
@ -163,17 +163,17 @@ public class RowSetArray implements ObjectIndex, Iterable<Row.Entry> {
return null;
}
public Entry replace(Entry row) {
public final Entry replace(Entry row) {
int i = indexFor(row);
if (i < 0) return null;
return accessArray(i).replace(row);
}
public Row row() {
public final Row row() {
return this.rowdef;
}
public CloneableIterator<Entry> rows(boolean up, byte[] firstKey) {
public final CloneableIterator<Entry> rows(boolean up, byte[] firstKey) {
synchronized (this.array) {
Collection<CloneableIterator<Entry>> col = new ArrayList<CloneableIterator<Entry>>();
for (int i = 0; i < this.array.length; i++) {
@ -186,11 +186,11 @@ public class RowSetArray implements ObjectIndex, Iterable<Row.Entry> {
}
}
public CloneableIterator<Entry> rows() {
public final CloneableIterator<Entry> rows() {
return rows(true, null);
}
public int size() {
public final int size() {
int c = 0;
synchronized (this.array) {
for (int i = 0; i < this.array.length; i++) {
@ -202,11 +202,11 @@ public class RowSetArray implements ObjectIndex, Iterable<Row.Entry> {
return c;
}
public Iterator<Entry> iterator() {
public final Iterator<Entry> iterator() {
return this.rows(true, null);
}
public long inc(byte[] key, int col, long add, Entry initrow) {
public final long inc(byte[] key, int col, long add, Entry initrow) {
int i = indexFor(key);
if (i < 0) return -1;
return accessArray(i).inc(key, col, add, initrow);

@ -37,14 +37,14 @@ import java.util.Map;
* at the same size.
*/
public class SimpleARC<K, V> implements ARC<K, V> {
public final class SimpleARC<K, V> implements ARC<K, V> {
public final static boolean accessOrder = false; // if false, then a insertion-order is used
protected int cacheSize;
private Map<K, V> levelA, levelB;
protected final int cacheSize;
private final Map<K, V> levelA, levelB;
public SimpleARC(int cacheSize) {
public SimpleARC(final int cacheSize) {
this.cacheSize = cacheSize / 2;
this.levelA = new LinkedHashMap<K, V>(cacheSize, 0.1f, accessOrder) {
private static final long serialVersionUID = 1L;
@ -65,7 +65,7 @@ public class SimpleARC<K, V> implements ARC<K, V> {
* @param s
* @param v
*/
public synchronized void put(K s, V v) {
public final synchronized void put(K s, V v) {
if (this.levelB.containsKey(s)) {
this.levelB.put(s, v);
assert (this.levelB.size() <= cacheSize); // the cache should shrink automatically
@ -80,7 +80,7 @@ public class SimpleARC<K, V> implements ARC<K, V> {
* @param s
* @return the value
*/
public synchronized V get(K s) {
public final synchronized V get(K s) {
V v = this.levelB.get(s);
if (v != null) return v;
v = this.levelA.remove(s);
@ -97,7 +97,7 @@ public class SimpleARC<K, V> implements ARC<K, V> {
* @param s
* @return
*/
public synchronized boolean containsKey(K s) {
public final synchronized boolean containsKey(K s) {
if (this.levelB.containsKey(s)) return true;
return this.levelA.containsKey(s);
}
@ -107,7 +107,7 @@ public class SimpleARC<K, V> implements ARC<K, V> {
* @param s
* @return the old value
*/
public synchronized V remove(K s) {
public final synchronized V remove(K s) {
V r = this.levelB.remove(s);
if (r != null) return r;
return this.levelA.remove(s);
@ -116,7 +116,7 @@ public class SimpleARC<K, V> implements ARC<K, V> {
/**
* clear the cache
*/
public synchronized void clear() {
public final synchronized void clear() {
this.levelA.clear();
this.levelB.clear();
}

Loading…
Cancel
Save