Skip to content

Commit

Permalink
bugfix for my last commit:
Browse files Browse the repository at this point in the history
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
  • Loading branch information
orbiter committed Mar 8, 2007
1 parent 264a82e commit 38b93f8
Show file tree
Hide file tree
Showing 23 changed files with 75 additions and 67 deletions.
3 changes: 2 additions & 1 deletion htroot/IndexControl_p.java
Expand Up @@ -64,6 +64,7 @@
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;
Expand Down Expand Up @@ -364,7 +365,7 @@ public static serverObjects respond(httpHeader header, serverObjects post, serve
// 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;
Expand Down
3 changes: 2 additions & 1 deletion source/de/anomic/index/indexCachedRI.java
Expand Up @@ -34,6 +34,7 @@
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;
Expand Down Expand Up @@ -274,7 +275,7 @@ public kelondroCloneableIterator wordContainers(String startHash, boolean ramOnl
true);
}
if (rot) {
return new kelondroRotateIterator(i);
return new kelondroRotateIterator(i, new String(kelondroBase64Order.zero(startHash.length())));
} else {
return i;
}
Expand Down
8 changes: 3 additions & 5 deletions source/de/anomic/index/indexCollectionRI.java
Expand Up @@ -98,16 +98,14 @@ public class wordContainersIterator implements kelondroCloneableIterator {

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() {
Expand Down
6 changes: 2 additions & 4 deletions source/de/anomic/index/indexRAMRI.java
Expand Up @@ -291,17 +291,15 @@ public class wordContainerIterator implements kelondroCloneableIterator {

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() {
Expand Down
6 changes: 6 additions & 0 deletions source/de/anomic/kelondro/kelondroBase64Order.java
Expand Up @@ -89,6 +89,12 @@ public kelondroBase64Order(boolean up, boolean rfc1113compliant) {
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);
Expand Down
4 changes: 3 additions & 1 deletion source/de/anomic/kelondro/kelondroCloneableIterator.java
Expand Up @@ -30,6 +30,8 @@

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

}
8 changes: 4 additions & 4 deletions source/de/anomic/kelondro/kelondroCollectionIndex.java
Expand Up @@ -962,10 +962,10 @@ private kelondroRowSet getwithparams(kelondroRow.Entry indexrow, int chunksize,
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;
Expand All @@ -976,10 +976,10 @@ public class keycollectionIterator implements Iterator {

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() {
Expand Down
6 changes: 3 additions & 3 deletions source/de/anomic/kelondro/kelondroDyn.java
Expand Up @@ -169,8 +169,8 @@ public dynKeyIterator(kelondroCloneableIterator iter) {
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() {
Expand Down Expand Up @@ -215,7 +215,7 @@ public synchronized kelondroCloneableIterator dynKeys(boolean up, boolean rotati
// 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 {
Expand Down
2 changes: 1 addition & 1 deletion source/de/anomic/kelondro/kelondroFlexSplitTable.java
Expand Up @@ -282,7 +282,7 @@ public rowIter() {
tt = null;
}

public Object clone() {
public Object clone(Object modifier) {
return new rowIter();
}

Expand Down
12 changes: 10 additions & 2 deletions source/de/anomic/kelondro/kelondroFlexTable.java
Expand Up @@ -297,13 +297,21 @@ public synchronized kelondroCloneableIterator rows(boolean up, byte[] firstKey)
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() {
Expand Down
4 changes: 2 additions & 2 deletions source/de/anomic/kelondro/kelondroMapObjects.java
Expand Up @@ -285,8 +285,8 @@ public synchronized mapIterator maps(final boolean up, final boolean rotating) t
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) {
Expand Down
8 changes: 4 additions & 4 deletions source/de/anomic/kelondro/kelondroMapTable.java
Expand Up @@ -129,10 +129,10 @@ public synchronized kelondroRow.Entry selectByte(String tablename, String key) t
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) {
Expand All @@ -141,11 +141,11 @@ public synchronized kelondroRow.Entry selectByte(String tablename, String key) t
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
Expand Down
4 changes: 2 additions & 2 deletions source/de/anomic/kelondro/kelondroMergeIterator.java
Expand Up @@ -67,8 +67,8 @@ public kelondroMergeIterator(kelondroCloneableIterator a, kelondroCloneableItera
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() {
Expand Down
8 changes: 4 additions & 4 deletions source/de/anomic/kelondro/kelondroObjects.java
Expand Up @@ -127,19 +127,19 @@ public synchronized kelondroCloneableIterator keys(final boolean up, final boole
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;
}


public synchronized objectIterator entries(final boolean up, final boolean rotating) throws IOException {
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() {
Expand Down
12 changes: 7 additions & 5 deletions source/de/anomic/kelondro/kelondroRotateIterator.java
Expand Up @@ -29,15 +29,17 @@
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() {
Expand All @@ -46,7 +48,7 @@ public boolean hasNext() {

public Object next() {
if (!(a.hasNext())) {
a = (kelondroCloneableIterator) clone.clone();
a = (kelondroCloneableIterator) clone.clone(modifier);
}
return a.next();
}
Expand Down
4 changes: 2 additions & 2 deletions source/de/anomic/kelondro/kelondroRowSet.java
Expand Up @@ -370,8 +370,8 @@ public rowIterator(boolean up, byte[] firstKey) {
}
}

public Object clone() {
return new rowIterator(up, first);
public Object clone(Object second) {
return new rowIterator(up, (byte[]) second);
}

public boolean hasNext() {
Expand Down
6 changes: 2 additions & 4 deletions source/de/anomic/kelondro/kelondroSplittedTree.java
Expand Up @@ -172,20 +172,18 @@ public class ktfsIterator implements kelondroCloneableIterator {

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;
}
Expand Down
8 changes: 3 additions & 5 deletions source/de/anomic/kelondro/kelondroTree.java
Expand Up @@ -1029,7 +1029,6 @@ public kelondroCloneableIterator rows(boolean up, byte[] firstKey) throws IOExce
public class rowIterator implements kelondroCloneableIterator {

int chunkSize;
byte[] start;
boolean inc;
long count;
byte[] lastKey;
Expand All @@ -1039,21 +1038,20 @@ public class rowIterator implements kelondroCloneableIterator {

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;
}
Expand Down
6 changes: 2 additions & 4 deletions source/de/anomic/plasma/plasmaCrawlLURL.java
Expand Up @@ -347,18 +347,16 @@ public class kiter implements kelondroCloneableIterator {
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;
}
Expand Down
2 changes: 1 addition & 1 deletion source/de/anomic/plasma/plasmaRankingCRProcess.java
Expand Up @@ -401,7 +401,7 @@ public static int genrcix(File cr_path_in, File rci_path_out) throws IOException
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;
Expand Down
2 changes: 1 addition & 1 deletion source/de/anomic/plasma/plasmaWordIndex.java
Expand Up @@ -463,7 +463,7 @@ public TreeSet indexContainerSet(String startHash, boolean ram, boolean rot, int
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;
}
Expand Down

0 comments on commit 38b93f8

Please sign in to comment.