gzz-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gzz-commits] storm/org/nongnu/storm/pointers PointerBlock.ja...


From: Benja Fallenstein
Subject: [Gzz-commits] storm/org/nongnu/storm/pointers PointerBlock.ja...
Date: Thu, 22 May 2003 18:03:52 -0400

CVSROOT:        /cvsroot/storm
Module name:    storm
Changes by:     Benja Fallenstein <address@hidden>      03/05/22 18:03:52

Modified files:
        org/nongnu/storm/pointers: PointerBlock.java PointerIndex.java 
                                   TitleIndex.java 

Log message:
        title stuff compiles

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/storm/storm/org/nongnu/storm/pointers/PointerBlock.java.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/storm/storm/org/nongnu/storm/pointers/PointerIndex.java.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/storm/storm/org/nongnu/storm/pointers/TitleIndex.java.diff?tr1=1.2&tr2=1.3&r1=text&r2=text

Patches:
Index: storm/org/nongnu/storm/pointers/PointerBlock.java
diff -u storm/org/nongnu/storm/pointers/PointerBlock.java:1.3 
storm/org/nongnu/storm/pointers/PointerBlock.java:1.4
--- storm/org/nongnu/storm/pointers/PointerBlock.java:1.3       Thu May 22 
17:31:00 2003
+++ storm/org/nongnu/storm/pointers/PointerBlock.java   Thu May 22 18:03:52 2003
@@ -37,11 +37,13 @@
     public static final String COOKIE = 
        "File format: <http://fenfire.org/2003/05/pointer-block-0.1>";
 
+    private BlockId blockId;
     private PointerId pointer;
     private long timestamp;
     private BlockId target;
     private String name;
 
+    public BlockId getBlockId() { return blockId; }
     public PointerId getPointer() { return pointer; }
     public long getTimestamp() { return timestamp; }
     public BlockId getTarget() { return target; }
@@ -51,6 +53,8 @@
        throws IOException, GeneralSecurityException {
        if(!block.getId().getContentType().equals("text/plain"))
            throw new IllegalArgumentException("Not a pointer block");
+
+       blockId = block.getId();
 
        InputStream is = block.getInputStream();
        Reader isr = new InputStreamReader(is, "US-ASCII");
Index: storm/org/nongnu/storm/pointers/PointerIndex.java
diff -u storm/org/nongnu/storm/pointers/PointerIndex.java:1.6 
storm/org/nongnu/storm/pointers/PointerIndex.java:1.7
--- storm/org/nongnu/storm/pointers/PointerIndex.java:1.6       Thu May 22 
17:31:00 2003
+++ storm/org/nongnu/storm/pointers/PointerIndex.java   Thu May 22 18:03:52 2003
@@ -68,6 +68,13 @@
        return b.getTarget();
     }
 
+    public String getTitle(PointerId id)
+       throws IOException, GeneralSecurityException {
+       PointerBlock b = getPointerBlock(id);
+       if(b == null) return null;
+       return b.getName();
+    }
+
     public PointerBlock getPointerBlock(PointerId id) 
        throws IOException, GeneralSecurityException {
        if(dbg) p("Get: "+id);
@@ -108,7 +115,11 @@
 
     public void set(PointerId id, BlockId target, KeyPair keyPair) 
        throws IOException, GeneralSecurityException {
-       set(id, target, keyPair, null);
+       PointerBlock current = (PointerBlock)getPointerBlock(id);
+       if(current == null)
+           set(id, target, keyPair, null);
+       else
+           set(id, target, keyPair, current.getName());
     }
 
     public void set(PointerId id, BlockId target, KeyPair keyPair,
Index: storm/org/nongnu/storm/pointers/TitleIndex.java
diff -u storm/org/nongnu/storm/pointers/TitleIndex.java:1.2 
storm/org/nongnu/storm/pointers/TitleIndex.java:1.3
--- storm/org/nongnu/storm/pointers/TitleIndex.java:1.2 Thu May 22 17:32:45 2003
+++ storm/org/nongnu/storm/pointers/TitleIndex.java     Thu May 22 18:03:52 2003
@@ -44,6 +44,33 @@
 
     protected IndexedPool pool;
     protected IndexedPool.DB db;
+    protected PointerIndex pointerIndex;
+
+    /** Returns a set of *current* pointer blocks.
+     */
+    public Set getPointers(String query) throws IOException {
+       Iterator i=splitWords(query).iterator();
+       if(!i.hasNext()) return new HashSet();
+       Set refs = new HashSet(db.get((String)i.next()).block());
+       while(i.hasNext())
+           refs.retainAll(db.get((String)i.next()).block());
+
+       Set result = new HashSet();
+       for(i=refs.iterator(); i.hasNext();) {
+           IndexedPool.Mapping m = (IndexedPool.Mapping)i.next();
+           try {
+               PointerId id = new PointerId(m.value);
+               PointerBlock cur = pointerIndex.getPointerBlock(id);
+               if(cur.getBlockId().equals(m.block))
+                   result.add(cur);
+           } catch(Throwable _) {
+               // bad data, ignore
+               continue;
+           }
+       }
+
+       return result;
+    }
 
     /** Return a set of words from a title.
      *  E.g. "Hifi sp82;kzz1 anT hifi anT"
@@ -84,23 +111,21 @@
            String name = p.getName();
            if(name == null) return mappings;
 
-           // Mapping pointer id -> pointer blocks
-           // for resolving a pointer
-           mappings.add(new IndexedPool.Mapping(block.getId(),
-                                                p.getPointer().toString(),
-                                                ""+p.getTimestamp()));
-
-           // Mapping "" -> pointer id
-           // for finding all pointers
-           mappings.add(new IndexedPool.Mapping(block.getId(), "",
-                                                p.getPointer().toString()));
+           Set words = splitWords(name);
+
+           for(Iterator i=words.iterator(); i.hasNext();) {
+               // Mapping word in title -> pointer
+               mappings.add(new IndexedPool.Mapping(block.getId(), 
+                                                    (String)i.next(),
+                                                    p.getPointer().getURI()));
+           }
 
            return mappings;
        }
 
        public Object createIndex(IndexedPool pool,
                                  IndexedPool.DB db) {
-           return new PointerIndex(pool, db);
+           return new TitleIndex(pool, db);
        }
        
        public String getIndexTypeURI() {
@@ -108,12 +133,14 @@
        }
        
        public String getHumanReadableName() {
-           return ("An index of 0.1 pointer blocks by pointer URN.");
+           return ("An index of 0.1 pointers by pointer title.");
        }
     }
 
     public TitleIndex(IndexedPool pool, IndexedPool.DB db) {
        this.pool = pool;
        this.db = db;
+       this.pointerIndex = 
+           (PointerIndex)pool.getIndex(PointerIndex.uri);
     }
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]