Author: orbiter
Date: 2008-01-22 22:40:25 +0100 (Tue, 22 Jan 2008)
New Revision: 4370

Modified:
   trunk/source/de/anomic/kelondro/kelondroEcoTable.java
Log:
added special handling for doubles in eco tables after initialization

Modified: trunk/source/de/anomic/kelondro/kelondroEcoTable.java
===================================================================
--- trunk/source/de/anomic/kelondro/kelondroEcoTable.java       2008-01-22 
20:49:26 UTC (rev 4369)
+++ trunk/source/de/anomic/kelondro/kelondroEcoTable.java       2008-01-22 
21:40:25 UTC (rev 4370)
@@ -134,6 +134,24 @@
             ArrayList<Integer[]> doubles = index.removeDoubles();
             if (doubles.size() > 0) {
                 System.out.println("DEBUG " + tablefile + ": WARNING - 
EcoTable " + tablefile + " has " + doubles.size() + " doubles");
+                // from all the doubles take one, put it back to the index and 
remove the others from the file
+                Iterator<Integer[]> i = doubles.iterator();
+                Integer[] ds;
+                // first put back one element each
+                while (i.hasNext()) {
+                    ds = i.next();
+                    file.get(ds[0].longValue(), record, 0);
+                    System.arraycopy(record, 0, key, 0, 
rowdef.primaryKeyLength);
+                    index.addi(key, ds[0].intValue());
+                }
+                // then remove the other doubles by removing them from the 
table, but do a re-indexing while doing that
+                i = doubles.iterator();
+                while (i.hasNext()) {
+                    ds = i.next();
+                    for (int j = 1; j < ds.length; j++) {
+                        removeInFile(ds[j].intValue());
+                    }
+                }
             }
         } catch (FileNotFoundException e) {
             // should never happen
@@ -334,11 +352,15 @@
         
         byte[] p = new byte[rowdef.objectsize];
         if (table == null) {
-            file.cleanLast(p, 0);
-            file.put(i, p, 0);
-            byte[] k = new byte[rowdef.primaryKeyLength];
-            System.arraycopy(p, 0, k, 0, rowdef.primaryKeyLength);
-            index.puti(k, i);
+            if (i == index.size() - 1) {
+                file.clean(i);
+            } else {
+                file.cleanLast(p, 0);
+                file.put(i, p, 0);
+                byte[] k = new byte[rowdef.primaryKeyLength];
+                System.arraycopy(p, 0, k, 0, rowdef.primaryKeyLength);
+                index.puti(k, i);
+            }
         } else {
             if (i == index.size() - 1) {
                 // special handling if the entry is the last entry in the file

_______________________________________________
YaCy-svn mailing list
YaCy-svn@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/yacy-svn

Antwort per Email an