mirror of https://github.com/apache/lucene.git
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:
parent
77e9e58300
commit
bbc7dc524a
|
@ -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;
|
||||
|
|
|
@ -711,6 +711,29 @@ public class TestFSTs extends LuceneTestCase {
|
|||
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 {
|
||||
|
||||
|
|
Loading…
Reference in New Issue