You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2012/01/20 00:54:55 UTC

svn commit: r1233696 - in /lucene/dev/trunk/lucene/src: java/org/apache/lucene/util/fst/ByteSequenceOutputs.java java/org/apache/lucene/util/fst/IntSequenceOutputs.java test/org/apache/lucene/util/fst/TestFSTs.java

Author: mikemccand
Date: Thu Jan 19 23:54:55 2012
New Revision: 1233696

URL: http://svn.apache.org/viewvc?rev=1233696&view=rev
Log:
use singletons in FST outputs; add 2 commented out test cases showing non-minimality

Modified:
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/fst/ByteSequenceOutputs.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/fst/IntSequenceOutputs.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/fst/TestFSTs.java

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/fst/ByteSequenceOutputs.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/fst/ByteSequenceOutputs.java?rev=1233696&r1=1233695&r2=1233696&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/fst/ByteSequenceOutputs.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/fst/ByteSequenceOutputs.java Thu Jan 19 23:54:55 2012
@@ -32,12 +32,13 @@ import org.apache.lucene.util.BytesRef;
 public final class ByteSequenceOutputs extends Outputs<BytesRef> {
 
   private final static BytesRef NO_OUTPUT = new BytesRef();
+  private final static ByteSequenceOutputs singleton = new ByteSequenceOutputs();
 
   private ByteSequenceOutputs() {
   }
 
   public static ByteSequenceOutputs getSingleton() {
-    return new ByteSequenceOutputs();
+    return singleton;
   }
 
   @Override

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/fst/IntSequenceOutputs.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/fst/IntSequenceOutputs.java?rev=1233696&r1=1233695&r2=1233696&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/fst/IntSequenceOutputs.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/fst/IntSequenceOutputs.java Thu Jan 19 23:54:55 2012
@@ -32,12 +32,13 @@ import org.apache.lucene.util.IntsRef;
 public final class IntSequenceOutputs extends Outputs<IntsRef> {
 
   private final static IntsRef NO_OUTPUT = new IntsRef();
+  private final static IntSequenceOutputs singleton = new IntSequenceOutputs();
 
   private IntSequenceOutputs() {
   }
 
   public static IntSequenceOutputs getSingleton() {
-    return new IntSequenceOutputs();
+    return singleton;
   }
 
   @Override

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/fst/TestFSTs.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/fst/TestFSTs.java?rev=1233696&r1=1233695&r2=1233696&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/fst/TestFSTs.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/fst/TestFSTs.java Thu Jan 19 23:54:55 2012
@@ -1055,6 +1055,50 @@ public class TestFSTs extends LuceneTest
     }
   }
 
+  // NOTE: this test shows a case where our current builder
+  // fails to produce minimal FST:
+  /*
+  public void test3() throws Exception {
+    final PositiveIntOutputs outputs = PositiveIntOutputs.getSingleton(true);
+    Builder<Long> builder = new Builder<Long>(FST.INPUT_TYPE.BYTE1, outputs);
+    IntsRef scratchIntsRef = new IntsRef();
+    builder.add(Util.toIntsRef(new BytesRef("aa$"), scratchIntsRef), outputs.get(0));
+    builder.add(Util.toIntsRef(new BytesRef("aab$"), scratchIntsRef), 1L);
+    builder.add(Util.toIntsRef(new BytesRef("bbb$"), scratchIntsRef), 2L);
+    final FST<Long> fst = builder.finish();
+    //System.out.println("NODES " + fst.getNodeCount() + " ARCS " + fst.getArcCount());
+    // NOTE: we produce 7 nodes today
+    assertEquals(6, fst.getNodeCount());
+    // NOTE: we produce 8 arcs today
+    assertEquals(7, fst.getNodeCount());
+    //Writer w = new OutputStreamWriter(new FileOutputStream("out.dot"), "UTF-8");
+    //Util.toDot(fst, w, false, false);
+    //w.close();
+  }
+  */
+
+  // NOTE: this test shows a case where our current builder
+  // fails to produce minimal FST:
+  /*
+  public void test4() throws Exception {
+    final ByteSequenceOutputs outputs = ByteSequenceOutputs.getSingleton();
+    Builder<BytesRef> builder = new Builder<BytesRef>(FST.INPUT_TYPE.BYTE1, outputs);
+    IntsRef scratchIntsRef = new IntsRef();
+    builder.add(Util.toIntsRef(new BytesRef("aa$"), scratchIntsRef), outputs.getNoOutput());
+    builder.add(Util.toIntsRef(new BytesRef("aab$"), scratchIntsRef), new BytesRef("1"));
+    builder.add(Util.toIntsRef(new BytesRef("bbb$"), scratchIntsRef), new BytesRef("11"));
+    final FST<BytesRef> fst = builder.finish();
+    //System.out.println("NODES " + fst.getNodeCount() + " ARCS " + fst.getArcCount());
+    // NOTE: we produce 7 nodes today
+    assertEquals(6, fst.getNodeCount());
+    // NOTE: we produce 8 arcs today
+    assertEquals(7, fst.getNodeCount());
+    //Writer w = new OutputStreamWriter(new FileOutputStream("out.dot"), "UTF-8");
+    //Util.toDot(fst, w, false, false);
+    //w.close();
+  }
+  */
+
   // Build FST for all unique terms in the test line docs
   // file, up until a time limit
   public void testRealTerms() throws Exception {