added termination control for RotateIterator

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@4399 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 17 years ago
parent e2e7f065e9
commit 2485681002

@ -164,7 +164,7 @@ public class IndexControlURLs_p {
// generate list
if (post.containsKey("urlhashsimilar")) {
try {
final Iterator entryIt = new kelondroRotateIterator(sb.wordIndex.loadedURL.entries(true, urlhash), new String(kelondroBase64Order.zero(urlhash.length())));
final Iterator<indexURLEntry> entryIt = new kelondroRotateIterator<indexURLEntry>(sb.wordIndex.loadedURL.entries(true, urlhash), new String(kelondroBase64Order.zero(urlhash.length())), sb.wordIndex.size());
StringBuffer result = new StringBuffer("Sequential List of URL-Hashes:<br>");
indexURLEntry entry;
int i = 0;

@ -1049,7 +1049,7 @@ public class kelondroCollectionIndex {
public keycollectionIterator(byte[] startKey, byte[] secondKey, boolean rot) throws IOException {
// iterator of {byte[], kelondroRowSet} Objects
kelondroCloneableIterator<kelondroRow.Entry> i = index.rows(true, startKey);
indexRowIterator = (rot) ? new kelondroRotateIterator<kelondroRow.Entry>(i, secondKey) : i;
indexRowIterator = (rot) ? new kelondroRotateIterator<kelondroRow.Entry>(i, secondKey, index.size()) : i;
}
public boolean hasNext() {

@ -219,7 +219,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<String>(i, null); else return i;
if (rotating) return new kelondroRotateIterator<String>(i, null, index.size()); else return i;
}
public synchronized dynKeyIterator dynKeys(boolean up, byte[] firstKey) throws IOException {

@ -39,14 +39,14 @@ public class kelondroEcoFS {
* The access rules are in such a way that a minimum of IO operations are necessary
* Two caches provide a mirror to content in the file: a read cache and a write buffer
* The read cache contains a number of entries from the file; a mirror that moves
* whenever information outsite the mirror is requested.
* whenever information outside the mirror is requested.
* The write buffer always exists only at the end of the file. It contains only records
* that have never been written to the file before. When the write buffer is flushed,
* the file grows
* The record file may also shrink when the last entry of the file is removed.
* Removal of Entries inside the file is not possible, but such entries can be erased
* by overwriting the data with zero bytes
* All access to the file is made with byte[] that are generated outsite of this class
* All access to the file is made with byte[] that are generated outside of this class
* This class only references byte[] that are handed over to methods of this class.
*/

@ -119,7 +119,7 @@ public class kelondroEcoTable implements kelondroIndex {
byte[] record = new byte[rowdef.objectsize];
byte[] key = new byte[rowdef.primaryKeyLength];
int fs = (int) file.size();
System.out.print("*** initializing RAM index for EcoTable " + tablefile + ":");
System.out.print("*** initializing RAM index for EcoTable " + tablefile.getName() + ":");
for (int i = 0; i < fs; i++) {
// read entry
file.get(i, record, 0);
@ -325,6 +325,9 @@ public class kelondroEcoTable implements kelondroIndex {
public synchronized Entry put(Entry row) throws IOException {
assert file.size() == index.size() : "file.size() = " + file.size() + ", index.size() = " + index.size();
assert ((table == null) || (table.size() == index.size()));
assert row != null;
assert row.bytes() != null;
if ((row == null) || (row.bytes() == null)) return null;
int i = index.geti(row.getPrimaryKeyBytes());
if (i == -1) {
addUnique(row);

@ -147,7 +147,7 @@ public class kelondroMapTable {
kelondroIndex tree = (kelondroIndex) tTables.get(tablename);
if (tree == null) throw new RuntimeException("kelondroTables.bytes: tree table '" + tablename + "' does not exist.");
kelondroCloneableIterator<kelondroRow.Entry> i = tree.rows(up, firstKey);
if (rotating) return new kelondroRotateIterator<kelondroRow.Entry>(i, secondKey); else return i;
if (rotating) return new kelondroRotateIterator<kelondroRow.Entry>(i, secondKey, tree.size()); else return i;
}
// if you need the long-values from a row-iteration, please use kelondroRecords.bytes2long to convert from byte[] to long

@ -140,7 +140,7 @@ public class kelondroObjects {
public synchronized kelondroCloneableIterator<String> keys(final boolean up, final boolean rotating, final byte[] firstKey, final byte[] secondKey) throws IOException {
// simple enumeration of key names without special ordering
kelondroCloneableIterator<String> i = dyn.dynKeys(up, firstKey);
if (rotating) return new kelondroRotateIterator<String>(i, secondKey); else return i;
if (rotating) return new kelondroRotateIterator<String>(i, secondKey, dyn.sizeDyn()); else return i;
}

@ -31,21 +31,23 @@ public class kelondroRotateIterator<E> implements kelondroCloneableIterator<E> {
kelondroCloneableIterator<E> a, clone;
Object modifier;
boolean nempty;
int terminationCount;
public kelondroRotateIterator(kelondroCloneableIterator<E> a, Object modifier) {
public kelondroRotateIterator(kelondroCloneableIterator<E> a, Object modifier, int terminationCount) {
// this works currently only for String-type key iterations
this.a = a;
this.modifier = modifier;
this.terminationCount = terminationCount;
this.clone = (kelondroCloneableIterator<E>) a.clone(modifier);
this.nempty = this.clone.hasNext();
}
public kelondroRotateIterator<E> clone(Object modifier) {
return new kelondroRotateIterator<E>(a, modifier);
return new kelondroRotateIterator<E>(a, modifier, terminationCount - 1);
}
public boolean hasNext() {
return this.nempty;
return (terminationCount > 0) && (this.nempty);
}
public E next() {
@ -56,6 +58,7 @@ public class kelondroRotateIterator<E> implements kelondroCloneableIterator<E> {
a = (kelondroCloneableIterator<E>) clone.clone(modifier);
assert a.hasNext();
}
terminationCount--;
return a.next();
}

@ -552,7 +552,7 @@ public final class plasmaWordIndex implements indexRI {
public synchronized kelondroCloneableIterator<indexContainer> wordContainers(String startHash, boolean ram, boolean rot) {
kelondroCloneableIterator<indexContainer> i = wordContainers(startHash, ram);
if (rot) {
return new kelondroRotateIterator<indexContainer>(i, new String(kelondroBase64Order.zero(startHash.length())));
return new kelondroRotateIterator<indexContainer>(i, new String(kelondroBase64Order.zero(startHash.length())), dhtOutCache.size() + ((ram) ? 0 : collections.size()));
} else {
return i;
}

@ -278,7 +278,7 @@ public class yacyDHTAction implements yacyPeerAction {
public synchronized yacySeed getPublicClusterCrawlSeed(String urlHash, TreeMap<String, String> clusterhashes) {
// clusterhashes is a String(hash)/String(IP) - mapping
kelondroCloneableIterator<String> i = new kelondroRotateIterator<String>(new kelondroCloneableMapIterator<String>(clusterhashes, urlHash), null);
kelondroCloneableIterator<String> i = new kelondroRotateIterator<String>(new kelondroCloneableMapIterator<String>(clusterhashes, urlHash), null, clusterhashes.size());
String hash;
int count = clusterhashes.size(); // counter to ensure termination
while ((i.hasNext()) && (count-- > 0)) {

Loading…
Cancel
Save