Skip to content

Instantly share code, notes, and snippets.

@MrTrick
Created December 29, 2011 19:13
Show Gist options
  • Save MrTrick/1535708 to your computer and use it in GitHub Desktop.
Save MrTrick/1535708 to your computer and use it in GitHub Desktop.
DAWG collapsing
@Test
public void testDawgDictionaryCollapse() {
Dictionary dictionary = Dictionary.buildDefaultDictionary();
Trie trie = new Trie(dictionary);
Dawg dawg = new Dawg(dictionary);
assertEquals(395184, trie.countNodes());
int i=0;
//Despite the merged nodes, a dawg should look structurally the same as a trie.
TrieIterator t = trie.iterator(), d = dawg.iterator();
while(t.hasNext() && d.hasNext()) {
Trie.Node tn = t.next(), dn = d.next();
for(char letter='A';letter<='Z';letter++)
assertEquals( tn.getChild(letter)!=null, dn.getChild(letter)!=null );
i++;
}
assertFalse(t.hasNext());
assertFalse(d.hasNext());
assertEquals(395184, i);
assertTrue( trie.countNodes() > dawg.countNodes() );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment