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 // generate list
if (post.containsKey("urlhashsimilar")) { if (post.containsKey("urlhashsimilar")) {
try { 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>"); StringBuffer result = new StringBuffer("Sequential List of URL-Hashes:<br>");
indexURLEntry entry; indexURLEntry entry;
int i = 0; int i = 0;

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

@ -219,7 +219,7 @@ public class kelondroDyn {
// iterates only the keys of the Nodes // iterates only the keys of the Nodes
// enumerated objects are of type String // enumerated objects are of type String
dynKeyIterator i = new dynKeyIterator(index.rows(up, null)); 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 { 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 * 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 * 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 * 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 * 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, * that have never been written to the file before. When the write buffer is flushed,
* the file grows * the file grows
* The record file may also shrink when the last entry of the file is removed. * 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 * Removal of Entries inside the file is not possible, but such entries can be erased
* by overwriting the data with zero bytes * 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. * 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[] record = new byte[rowdef.objectsize];
byte[] key = new byte[rowdef.primaryKeyLength]; byte[] key = new byte[rowdef.primaryKeyLength];
int fs = (int) file.size(); 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++) { for (int i = 0; i < fs; i++) {
// read entry // read entry
file.get(i, record, 0); file.get(i, record, 0);
@ -325,6 +325,9 @@ public class kelondroEcoTable implements kelondroIndex {
public synchronized Entry put(Entry row) throws IOException { public synchronized Entry put(Entry row) throws IOException {
assert file.size() == index.size() : "file.size() = " + file.size() + ", index.size() = " + index.size(); assert file.size() == index.size() : "file.size() = " + file.size() + ", index.size() = " + index.size();
assert ((table == null) || (table.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()); int i = index.geti(row.getPrimaryKeyBytes());
if (i == -1) { if (i == -1) {
addUnique(row); addUnique(row);

@ -147,7 +147,7 @@ public class kelondroMapTable {
kelondroIndex tree = (kelondroIndex) tTables.get(tablename); kelondroIndex tree = (kelondroIndex) tTables.get(tablename);
if (tree == null) throw new RuntimeException("kelondroTables.bytes: tree table '" + tablename + "' does not exist."); if (tree == null) throw new RuntimeException("kelondroTables.bytes: tree table '" + tablename + "' does not exist.");
kelondroCloneableIterator<kelondroRow.Entry> i = tree.rows(up, firstKey); 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 // 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 { 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 // simple enumeration of key names without special ordering
kelondroCloneableIterator<String> i = dyn.dynKeys(up, firstKey); 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; kelondroCloneableIterator<E> a, clone;
Object modifier; Object modifier;
boolean nempty; 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 works currently only for String-type key iterations
this.a = a; this.a = a;
this.modifier = modifier; this.modifier = modifier;
this.terminationCount = terminationCount;
this.clone = (kelondroCloneableIterator<E>) a.clone(modifier); this.clone = (kelondroCloneableIterator<E>) a.clone(modifier);
this.nempty = this.clone.hasNext(); this.nempty = this.clone.hasNext();
} }
public kelondroRotateIterator<E> clone(Object modifier) { public kelondroRotateIterator<E> clone(Object modifier) {
return new kelondroRotateIterator<E>(a, modifier); return new kelondroRotateIterator<E>(a, modifier, terminationCount - 1);
} }
public boolean hasNext() { public boolean hasNext() {
return this.nempty; return (terminationCount > 0) && (this.nempty);
} }
public E next() { public E next() {
@ -56,6 +58,7 @@ public class kelondroRotateIterator<E> implements kelondroCloneableIterator<E> {
a = (kelondroCloneableIterator<E>) clone.clone(modifier); a = (kelondroCloneableIterator<E>) clone.clone(modifier);
assert a.hasNext(); assert a.hasNext();
} }
terminationCount--;
return a.next(); return a.next();
} }

@ -552,7 +552,7 @@ public final class plasmaWordIndex implements indexRI {
public synchronized kelondroCloneableIterator<indexContainer> wordContainers(String startHash, boolean ram, boolean rot) { public synchronized kelondroCloneableIterator<indexContainer> wordContainers(String startHash, boolean ram, boolean rot) {
kelondroCloneableIterator<indexContainer> i = wordContainers(startHash, ram); kelondroCloneableIterator<indexContainer> i = wordContainers(startHash, ram);
if (rot) { 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 { } else {
return i; return i;
} }

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

Loading…
Cancel
Save