bugfix for my last commit:

iterator did not consider secondary start point in case of rotation

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@3456 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 18 years ago
parent 264a82eec8
commit 38b93f8cb8

@ -64,6 +64,7 @@ import de.anomic.index.indexContainer;
import de.anomic.index.indexRWIEntry;
import de.anomic.plasma.plasmaURL;
import de.anomic.index.indexURLEntry;
import de.anomic.kelondro.kelondroBase64Order;
import de.anomic.kelondro.kelondroRotateIterator;
import de.anomic.net.URL;
import de.anomic.plasma.plasmaCondenser;
@ -364,7 +365,7 @@ public class IndexControl_p {
// generate list
if (post.containsKey("urlhashsimilar")) {
try {
final Iterator entryIt = new kelondroRotateIterator(switchboard.wordIndex.loadedURL.entries(true, urlhash));
final Iterator entryIt = new kelondroRotateIterator(switchboard.wordIndex.loadedURL.entries(true, urlhash), new String(kelondroBase64Order.zero(urlhash.length())));
StringBuffer result = new StringBuffer("Sequential List of URL-Hashes:<br>");
indexURLEntry entry;
int i = 0;

@ -34,6 +34,7 @@ import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import de.anomic.kelondro.kelondroBase64Order;
import de.anomic.kelondro.kelondroCloneableIterator;
import de.anomic.kelondro.kelondroMergeIterator;
import de.anomic.kelondro.kelondroOrder;
@ -274,7 +275,7 @@ public class indexCachedRI implements indexRI {
true);
}
if (rot) {
return new kelondroRotateIterator(i);
return new kelondroRotateIterator(i, new String(kelondroBase64Order.zero(startHash.length())));
} else {
return i;
}

@ -98,16 +98,14 @@ public class indexCollectionRI implements indexRI {
private Iterator wci;
private boolean rot;
private String startWordHash;
public wordContainersIterator(String startWordHash, boolean rot) {
this.startWordHash = startWordHash;
this.rot = rot;
this.wci = collectionIndex.keycollections(startWordHash.getBytes(), rot);
this.wci = collectionIndex.keycollections(startWordHash.getBytes(), kelondroBase64Order.zero(startWordHash.length()), rot);
}
public Object clone() {
return new wordContainersIterator(startWordHash, rot);
public Object clone(Object secondWordHash) {
return new wordContainersIterator((String) secondWordHash, rot);
}
public boolean hasNext() {

@ -291,17 +291,15 @@ public final class indexRAMRI implements indexRI {
private boolean rot;
private Iterator iterator;
private String startWordHash;
public wordContainerIterator(String startWordHash, boolean rot) {
this.startWordHash = startWordHash;
this.rot = rot;
this.iterator = (startWordHash == null) ? cache.values().iterator() : cache.tailMap(startWordHash).values().iterator();
// The collection's iterator will return the values in the order that their corresponding keys appear in the tree.
}
public Object clone() {
return new wordContainerIterator(startWordHash, rot);
public Object clone(Object secondWordHash) {
return new wordContainerIterator((String) secondWordHash, rot);
}
public boolean hasNext() {

@ -89,6 +89,12 @@ public class kelondroBase64Order extends kelondroAbstractOrder implements kelond
this.log = new serverLog("BASE64");
}
public static byte[] zero(int length) {
byte[] z = new byte[length];
while (length > 0) { length--; z[length] = (byte) alpha_standard[0]; }
return z;
}
public Object clone() {
kelondroBase64Order o = new kelondroBase64Order(this.asc, this.rfc1113compliant);
o.rotate(this.zero);

@ -30,6 +30,8 @@ import java.util.Iterator;
public interface kelondroCloneableIterator extends Iterator {
public Object /* instance of kelondroCloneableIterator*/ clone();
// clone the iterator using a modifier
// the modifier can be i.e. a re-start position
public Object /* instance of kelondroCloneableIterator*/ clone(Object modifier);
}

@ -962,10 +962,10 @@ public class kelondroCollectionIndex {
return collection;
}
public synchronized Iterator keycollections(byte[] startKey, boolean rot) {
public synchronized Iterator keycollections(byte[] startKey, byte[] secondKey, boolean rot) {
// returns an iteration of {byte[], kelondroRowSet} Objects
try {
return new keycollectionIterator(startKey, rot);
return new keycollectionIterator(startKey, secondKey, rot);
} catch (IOException e) {
e.printStackTrace();
return null;
@ -976,10 +976,10 @@ public class kelondroCollectionIndex {
Iterator indexRowIterator;
public keycollectionIterator(byte[] startKey, boolean rot) throws IOException {
public keycollectionIterator(byte[] startKey, byte[] secondKey, boolean rot) throws IOException {
// iterator of {byte[], kelondroRowSet} Objects
kelondroCloneableIterator i = index.rows(true, startKey);
indexRowIterator = (rot) ? new kelondroRotateIterator(i) : i;
indexRowIterator = (rot) ? new kelondroRotateIterator(i, secondKey) : i;
}
public boolean hasNext() {

@ -169,8 +169,8 @@ public class kelondroDyn {
nextKey = n();
}
public Object clone() {
return new dynKeyIterator((kelondroCloneableIterator) ri.clone());
public Object clone(Object modifier) {
return new dynKeyIterator((kelondroCloneableIterator) ri.clone(modifier));
}
public boolean hasNext() {
@ -215,7 +215,7 @@ public class kelondroDyn {
// iterates only the keys of the Nodes
// enumerated objects are of type String
dynKeyIterator i = new dynKeyIterator(index.rows(up, null));
if (rotating) return new kelondroRotateIterator(i); else return i;
if (rotating) return new kelondroRotateIterator(i, null); else return i;
}
public synchronized dynKeyIterator dynKeys(boolean up, byte[] firstKey) throws IOException {

@ -282,7 +282,7 @@ public class kelondroFlexSplitTable implements kelondroIndex {
tt = null;
}
public Object clone() {
public Object clone(Object modifier) {
return new rowIter();
}

@ -297,13 +297,21 @@ public class kelondroFlexTable extends kelondroFlexWidthArray implements kelondr
public class rowIterator implements kelondroCloneableIterator {
kelondroCloneableIterator indexIterator;
kelondroBytesIntMap index;
boolean up;
public rowIterator(kelondroBytesIntMap index, boolean up, byte[] firstKey) throws IOException {
this.index = index;
this.up = up;
indexIterator = index.rows(up, firstKey);
}
public Object clone() {
return null;
public Object clone(Object modifier) {
try {
return new rowIterator(index, up, (byte[]) modifier);
} catch (IOException e) {
return null;
}
}
public boolean hasNext() {

@ -285,8 +285,8 @@ public class kelondroMapObjects extends kelondroObjects {
return new mapIterator(keys(up, rotating));
}
public synchronized mapIterator maps(final boolean up, final boolean rotating, final byte[] firstKey) throws IOException {
return new mapIterator(keys(up, rotating, firstKey));
public synchronized mapIterator maps(final boolean up, final boolean rotating, final byte[] firstKey, final byte[] secondKey) throws IOException {
return new mapIterator(keys(up, rotating, firstKey, secondKey));
}
public synchronized long getLongAcc(final String field) {

@ -129,10 +129,10 @@ public class kelondroMapTable {
return table.maps(up, rotating);
}
public synchronized kelondroMapObjects.mapIterator /* of Map-Elements */ maps(String tablename, boolean up, boolean rotating, byte[] firstKey) throws IOException {
public synchronized kelondroMapObjects.mapIterator /* of Map-Elements */ maps(String tablename, boolean up, boolean rotating, byte[] firstKey, byte[] secondKey) throws IOException {
kelondroMapObjects table = (kelondroMapObjects) mTables.get(tablename);
if (table == null) throw new RuntimeException("kelondroTables.maps: map table '" + tablename + "' does not exist.");
return table.maps(up, rotating, firstKey);
return table.maps(up, rotating, firstKey, secondKey);
}
public synchronized kelondroMapObjects.mapIterator /* of Map-Elements */ maps(String tablename, boolean up, String field) {
@ -141,11 +141,11 @@ public class kelondroMapTable {
return table.maps(up, field);
}
public synchronized kelondroCloneableIterator /* of kelondroRow.Entry-Elements */ rows(String tablename, boolean up, boolean rotating, byte[] firstKey) throws IOException {
public synchronized kelondroCloneableIterator /* of kelondroRow.Entry-Elements */ rows(String tablename, boolean up, boolean rotating, byte[] firstKey, byte[] secondKey) throws IOException {
kelondroIndex tree = (kelondroIndex) tTables.get(tablename);
if (tree == null) throw new RuntimeException("kelondroTables.bytes: tree table '" + tablename + "' does not exist.");
kelondroCloneableIterator i = tree.rows(up, firstKey);
if (rotating) return new kelondroRotateIterator(i); else return i;
if (rotating) return new kelondroRotateIterator(i, secondKey); else return i;
}
// if you need the long-values from a row-iteration, please use kelondroRecords.bytes2long to convert from byte[] to long

@ -67,8 +67,8 @@ public class kelondroMergeIterator implements kelondroCloneableIterator {
nextb();
}
public Object clone() {
return new kelondroMergeIterator((kelondroCloneableIterator) a.clone(), (kelondroCloneableIterator) b.clone(), comp, merger, up);
public Object clone(Object modifier) {
return new kelondroMergeIterator((kelondroCloneableIterator) a.clone(modifier), (kelondroCloneableIterator) b.clone(modifier), comp, merger, up);
}
public void finalize() {

@ -127,10 +127,10 @@ public class kelondroObjects {
return dyn.dynKeys(up, rotating);
}
public synchronized kelondroCloneableIterator keys(final boolean up, final boolean rotating, final byte[] firstKey) throws IOException {
public synchronized kelondroCloneableIterator keys(final boolean up, final boolean rotating, final byte[] firstKey, final byte[] secondKey) throws IOException {
// simple enumeration of key names without special ordering
kelondroCloneableIterator i = dyn.dynKeys(up, firstKey);
if (rotating) return new kelondroRotateIterator(i); else return i;
if (rotating) return new kelondroRotateIterator(i, secondKey); else return i;
}
@ -138,8 +138,8 @@ public class kelondroObjects {
return new objectIterator(keys(up, rotating));
}
public synchronized objectIterator entries(final boolean up, final boolean rotating, final byte[] firstKey) throws IOException {
return new objectIterator(keys(up, rotating, firstKey));
public synchronized objectIterator entries(final boolean up, final boolean rotating, final byte[] firstKey, final byte[] secondKey) throws IOException {
return new objectIterator(keys(up, rotating, firstKey, secondKey));
}
public synchronized int size() {

@ -29,15 +29,17 @@ package de.anomic.kelondro;
public class kelondroRotateIterator implements kelondroCloneableIterator {
kelondroCloneableIterator a, clone;
Object modifier;
public kelondroRotateIterator(kelondroCloneableIterator a) {
public kelondroRotateIterator(kelondroCloneableIterator a, Object modifier) {
// this works currently only for String-type key iterations
this.a = a;
this.clone = (kelondroCloneableIterator) a.clone();
this.modifier = modifier;
this.clone = (kelondroCloneableIterator) a.clone(modifier);
}
public Object clone() {
return new kelondroRotateIterator(a);
public Object clone(Object modifier) {
return new kelondroRotateIterator(a, modifier);
}
public boolean hasNext() {
@ -46,7 +48,7 @@ public class kelondroRotateIterator implements kelondroCloneableIterator {
public Object next() {
if (!(a.hasNext())) {
a = (kelondroCloneableIterator) clone.clone();
a = (kelondroCloneableIterator) clone.clone(modifier);
}
return a.next();
}

@ -370,8 +370,8 @@ public class kelondroRowSet extends kelondroRowCollection implements kelondroInd
}
}
public Object clone() {
return new rowIterator(up, first);
public Object clone(Object second) {
return new rowIterator(up, (byte[]) second);
}
public boolean hasNext() {

@ -172,20 +172,18 @@ public class kelondroSplittedTree implements kelondroIndex {
int c = 0;
Iterator ktfsI;
byte[] firstKey;
boolean up;
public ktfsIterator(boolean up, byte[] firstKey) throws IOException {
this.up = up;
this.firstKey = firstKey;
c = (up) ? 0 : (ff - 1);
if (firstKey != null) throw new UnsupportedOperationException("ktfsIterator does not work with a start key");
ktfsI = ktfs[c].rows(up, firstKey); // FIXME: this works only correct with firstKey == null
}
public Object clone() {
public Object clone(Object secondKey) {
try {
return new ktfsIterator(up, firstKey);
return new ktfsIterator(up, (byte[]) secondKey);
} catch (IOException e) {
return null;
}

@ -1029,7 +1029,6 @@ public class kelondroTree extends kelondroRecords implements kelondroIndex {
public class rowIterator implements kelondroCloneableIterator {
int chunkSize;
byte[] start;
boolean inc;
long count;
byte[] lastKey;
@ -1039,21 +1038,20 @@ public class kelondroTree extends kelondroRecords implements kelondroIndex {
public rowIterator(boolean up, byte[] firstKey, long guessedCountLimit) throws IOException {
this.guessedCountLimit = guessedCountLimit;
start = firstKey;
inc = up;
count = 0;
lastKey = null;
//System.out.println("*** rowIterator: " + filename + ": readAheadChunkSize = " + readAheadChunkSize + ", lastIteratorCount = " + lastIteratorCount);
readAheadChunkSize = Math.min(1000, 3 + (int) ((3 * readAheadChunkSize + lastIteratorCount) / 4));
chunkSize = (int) Math.min(readAheadChunkSize / 3, guessedCountLimit);
rowBuffer = rowMap(inc, start, true, chunkSize);
rowBuffer = rowMap(inc, firstKey, true, chunkSize);
bufferIterator = rowBuffer.entrySet().iterator();
lastIteratorCount = 0;
}
public Object clone() {
public Object clone(Object secondStart) {
try {
return new rowIterator(inc, start, guessedCountLimit);
return new rowIterator(inc, (byte[]) secondStart, guessedCountLimit);
} catch (IOException e) {
return null;
}

@ -347,18 +347,16 @@ public final class plasmaCrawlLURL {
private Iterator iter;
private boolean error;
boolean up;
String firstHash;
public kiter(boolean up, String firstHash) throws IOException {
this.up = up;
this.firstHash = firstHash;
this.iter = plasmaCrawlLURL.this.urlIndexFile.rows(up, (firstHash == null) ? null : firstHash.getBytes());
this.error = false;
}
public Object clone() {
public Object clone(Object secondHash) {
try {
return new kiter(up, firstHash);
return new kiter(up, (String) secondHash);
} catch (IOException e) {
return null;
}

@ -401,7 +401,7 @@ public class plasmaRankingCRProcess {
int size = seq.size();
long start = System.currentTimeMillis();
long l;
final Iterator i = seq.keycollections(null, false);
final Iterator i = seq.keycollections(null, null, false);
Object[] keycollection;
String referee, refereeDom, anchor, anchorDom;
kelondroRowSet cr_entry, rci_entry;

@ -463,7 +463,7 @@ public final class plasmaWordIndex implements indexRI {
public kelondroCloneableIterator wordContainers(String startHash, boolean ram, boolean rot) {
kelondroCloneableIterator i = wordContainers(startHash, ram);
if (rot) {
return new kelondroRotateIterator(i);
return new kelondroRotateIterator(i, new String(kelondroBase64Order.zero(startHash.length())));
} else {
return i;
}

@ -90,8 +90,8 @@ public class plasmaWordIndexFileCluster implements indexRI {
this.wordIterator = wordIterator;
}
public Object clone() {
return new containerIterator((kelondroCloneableIterator) this.wordIterator.clone());
public Object clone(Object modifier) {
return new containerIterator((kelondroCloneableIterator) this.wordIterator.clone(modifier));
}
public boolean hasNext() {
@ -123,11 +123,9 @@ public class plasmaWordIndexFileCluster implements indexRI {
private final ArrayList hierarchy; // contains TreeSet elements, earch TreeSet contains File Entries
private final Comparator comp; // for string-compare
private String buffer; // the prefetch-buffer
private String startHash;
private boolean up;
public iterateFiles(String startHash, boolean up) {
this.startHash = startHash;
this.up = up;
this.hierarchy = new ArrayList();
this.comp = new kelondroNaturalOrder(up);
@ -160,8 +158,8 @@ public class plasmaWordIndexFileCluster implements indexRI {
}
}
public Object clone() {
return new iterateFiles(startHash, up);
public Object clone(Object secondHash) {
return new iterateFiles((String) secondHash, up);
}
private synchronized void delete(String pattern, TreeSet names) {

@ -250,17 +250,17 @@ public final class yacySeedDB {
public Enumeration seedsConnected(boolean up, boolean rot, String firstHash, float minVersion) {
// enumerates seed-type objects: all seeds sequentially without order
return new seedEnum(up, rot, (firstHash == null) ? null : firstHash.getBytes(), seedActiveDB, minVersion);
return new seedEnum(up, rot, (firstHash == null) ? null : firstHash.getBytes(), null, seedActiveDB, minVersion);
}
public Enumeration seedsDisconnected(boolean up, boolean rot, String firstHash, float minVersion) {
// enumerates seed-type objects: all seeds sequentially without order
return new seedEnum(up, rot, (firstHash == null) ? null : firstHash.getBytes(), seedPassiveDB, minVersion);
return new seedEnum(up, rot, (firstHash == null) ? null : firstHash.getBytes(), null, seedPassiveDB, minVersion);
}
public Enumeration seedsPotential(boolean up, boolean rot, String firstHash, float minVersion) {
// enumerates seed-type objects: all seeds sequentially without order
return new seedEnum(up, rot, (firstHash == null) ? null : firstHash.getBytes(), seedPotentialDB, minVersion);
return new seedEnum(up, rot, (firstHash == null) ? null : firstHash.getBytes(), null, seedPotentialDB, minVersion);
}
public yacySeed anySeedVersion(float minVersion) {
@ -840,11 +840,11 @@ public final class yacySeedDB {
kelondroMapObjects database;
float minVersion;
public seedEnum(boolean up, boolean rot, byte[] firstKey, kelondroMapObjects database, float minVersion) {
public seedEnum(boolean up, boolean rot, byte[] firstKey, byte[] secondKey, kelondroMapObjects database, float minVersion) {
this.database = database;
this.minVersion = minVersion;
try {
it = (firstKey == null) ? database.maps(up, rot) : database.maps(up, rot, firstKey);
it = (firstKey == null) ? database.maps(up, rot) : database.maps(up, rot, firstKey, secondKey);
while (true) {
nextSeed = internalNext();
if (nextSeed == null) break;

Loading…
Cancel
Save