LUCENE-4887: NoOutputs implements merge. Lets FSA behave like a Set<Input>

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1461409 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Ryan McKinley 2013-03-27 04:11:49 +00:00
parent 77e9e58300
commit bbc7dc524a
2 changed files with 30 additions and 0 deletions

View File

@ -73,6 +73,13 @@ public final class NoOutputs extends Outputs<Object> {
return NO_OUTPUT;
}
@Override
public Object merge(Object first, Object second) {
assert first == NO_OUTPUT;
assert second == NO_OUTPUT;
return NO_OUTPUT;
}
@Override
public void write(Object prefix, DataOutput out) {
//assert false;

View File

@ -710,6 +710,29 @@ public class TestFSTs extends LuceneTestCase {
assertNull(fstEnum.seekFloor(new BytesRef("foo")));
assertNull(fstEnum.seekCeil(new BytesRef("foobaz")));
}
public void testDuplicateFSAString() throws Exception {
String str = "foobar";
final Outputs<Object> outputs = NoOutputs.getSingleton();
final Builder<Object> b = new Builder<Object>(FST.INPUT_TYPE.BYTE1, outputs);
IntsRef ints = new IntsRef();
for(int i=0; i<10; i++) {
b.add(Util.toIntsRef(new BytesRef(str), ints), outputs.getNoOutput());
}
FST<Object> fst = b.finish();
// count the input paths
int count = 0;
final BytesRefFSTEnum<Object> fstEnum = new BytesRefFSTEnum<Object>(fst);
while(fstEnum.next()!=null) {
count++;
}
assertEquals(1, count);
assertNotNull(Util.get(fst, new BytesRef(str)));
assertNull(Util.get(fst, new BytesRef("foobaz")));
}
/*
public void testTrivial() throws Exception {