enhanced Assortment class

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@141 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 20 years ago
parent 9ee3e69021
commit 79be6f003d

@ -167,7 +167,8 @@ public final class plasmaWordIndexAssortment {
} }
if (oldrow != null) throw new RuntimeException("Store to assortment ambiguous"); if (oldrow != null) throw new RuntimeException("Store to assortment ambiguous");
} }
/*
public record read(String wordHash) { public record read(String wordHash) {
// returns a single word index from assortment database; returns null if index does not exist // returns a single word index from assortment database; returns null if index does not exist
//log.logDebug("readAssortment: wordHash=" + wordHash); //log.logDebug("readAssortment: wordHash=" + wordHash);
@ -208,6 +209,33 @@ public final class plasmaWordIndexAssortment {
resetDatabase(); resetDatabase();
} }
} }
*/
public record remove(String wordHash) {
// deletes a word index from assortment database
// and returns the content record
byte[][] row = null;
try {
row = assortments.remove(wordHash.getBytes());
} catch (IOException e) {
log.logFailure("removeAssortment/IO-error: " + e.getMessage() + " - reset assortment-DB");
e.printStackTrace();
resetDatabase();
return null;
} catch (kelondroException e) {
log.logFailure("removeAssortment/kelondro-error: " + e.getMessage() + " - reset assortment-DB");
e.printStackTrace();
resetDatabase();
return null;
}
if (row == null) return null;
long creationTime = kelondroRecords.bytes2long(row[2]);
plasmaWordIndexEntry[] wordEntries = new plasmaWordIndexEntry[this.bufferStructureLength];
for (int i = 0; i < assortmentCapacity; i++) {
wordEntries[i] = new plasmaWordIndexEntry(new String(row[3 + 2 * i]), new String(row[4 + 2 * i]));
}
return new record(wordEntries, creationTime);
}
private void resetDatabase() { private void resetDatabase() {
// deletes the assortment database and creates a new one // deletes the assortment database and creates a new one

@ -258,7 +258,7 @@ public final class plasmaWordIndexCache implements plasmaWordIndexInterface {
} }
// now decide where to flush that container // now decide where to flush that container
plasmaWordIndexAssortment.record singleton = singletons.read(key); plasmaWordIndexAssortment.record singleton = singletons.remove(key);
if (singleton == null) { if (singleton == null) {
// not found in singletons // not found in singletons
if (container.size() == 1) { if (container.size() == 1) {
@ -273,49 +273,35 @@ public final class plasmaWordIndexCache implements plasmaWordIndexInterface {
// we have a singleton and need to integrate this in the flush // we have a singleton and need to integrate this in the flush
plasmaWordIndexEntry oldEntry = singleton.entries[0]; plasmaWordIndexEntry oldEntry = singleton.entries[0];
long oldTime = singleton.creationTime; long oldTime = singleton.creationTime;
if (container.contains(oldEntry.getUrlHash())) {
// we have an double-occurrence // put new entries to the container
if (container.size() == 1) { if (!(container.contains(oldEntry.getUrlHash()))) container.add(oldEntry);
// it is superfluous to flush this, simple do nothing
return 0; // possibly reintegrate
} else { if (reintegrate) {
// we flush to the backend, and the entry from the singletons // put singleton together with container back to ram
singletons.remove(key); synchronized (cache) {
return backend.addEntries(container, java.lang.Math.max(time, oldTime)); cache.put(key, container);
} hashScore.setScore(key, container.size());
} else { hashDate.put(key, new Long(time));
// now we have more than one entry }
// we must remove the key from the singleton database return -1;
singletons.remove(key); } else {
// .. and put it to the container // add this to the backend
container.add(oldEntry); return backend.addEntries(container, java.lang.Math.max(time, oldTime));
if (reintegrate) {
// put singleton together with container back to ram
synchronized (cache) {
cache.put(key, container);
hashScore.setScore(key, container.size());
hashDate.put(key, new Long(time));
}
return -1;
} else {
// add this to the backend
return backend.addEntries(container, java.lang.Math.max(time, oldTime));
}
} }
} }
} }
private boolean flushFromSingleton(String key) { private boolean flushFromSingleton(String key) {
// this should only be called if the singleton shall be deleted or returned in an index entity // this should only be called if the singleton shall be deleted or returned in an index entity
plasmaWordIndexAssortment.record singleton = singletons.read(key); plasmaWordIndexAssortment.record singleton = singletons.remove(key);
if (singleton == null) { if (singleton == null) {
return false; return false;
} else { } else {
// we have a singleton // we have a singleton
plasmaWordIndexEntry entry = (plasmaWordIndexEntry) singleton.entries[0]; plasmaWordIndexEntry entry = (plasmaWordIndexEntry) singleton.entries[0];
long time = singleton.creationTime; long time = singleton.creationTime;
// remove it from the singleton database
singletons.remove(key);
// integrate it to the backend // integrate it to the backend
return backend.addEntries(plasmaWordIndexEntryContainer.instantContainer(key, entry), time) > 0; return backend.addEntries(plasmaWordIndexEntryContainer.instantContainer(key, entry), time) > 0;
} }

Loading…
Cancel
Save