When dealing with generic classes in Java (like Trie<String, Boolean>) you ARE dealing with the Boolean object. Sure you can pass true and false in there, but it's auto-boxed into the Boolean.TRUE and BOOLEAN.FALSE. The same applies to using Integer, you can pass in ints (i.e. x), but it auto-boxes it to new Integer(x).

I should change the example so it looks a little nicer, even though what I have is perfectly correct.

Some Strings cause an exception. I obtained a Trie through Tries.forString() and am using the Moby word list names.txt file for keys/values. I put each trim()ed String as the key and value in order. The exception is thrown for the 771st String "Ameli".

Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 5 at java.lang.String.charAt(String.java:658) at org.magnos.trie.TrieSequencerCharSequence.hashOf(TrieSequencerCharSequence.java:54) at org.magnos.trie.TrieSequencerCharSequence.hashOf(TrieSequencerCharSequence.java:28) at org.magnos.trie.Trie.put(Trie.java:165)

Optimized read only structures are neat. Let me ask/confirm a few things:Isn't your implementation 5 bit? (And uses lowercase letters) What do you use to encode the trie? Are there multiple encodings?I wonder how if you did have a 7-bit tree if it would be relatively simple to encode UTF-8.I don't know if it qualifies as efficient for disk storage. It might be close to zip compression. Can the structure be compressed further?

@ClickerMonkey: I loaded the text file with the wrong encoding. (It was not UTF.) However loading the entire list changed the String for which the exception was thrown.

@Nate: I think you could use 7 bits per node if you used a terminator character. The structure would be bigger, but if the Strings were Huffman encoded you could fit more characters into fewer nodes. Not that I am suggesting that. Just pointing it out.

So you are still having an exception? Can you post the full stack trace if so? Also, can you send me that list of words... the words inserted before the culprit are the ones to blame mostly. Also, make sure you are using the most up-to-date JAR, I fixed a NPE about two weeks ago. Thanks!

@Nate

That's a pretty awesome Trie! Is there a way to efficiently query all words that start with "moo" or something? I skimmed through the code, but since you didn't post the encoder it's harder to just stare at and understand how it works =P

I use the Moby word lists because it's public domain and already in plain text format. My JRE is up to date. I downloaded the source as a zip file. The stack trace is:

Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 3 at java.lang.String.charAt at org.magnos.trie.TrieSequencerCharSequence.hashOf(TrieSequencerCharSequence.java:54) at org.magnos.trie.TrieSequencerCharSequence.hashOf(TrieSequencerCharSequence.java:28) at org.magnos.trie.Trie.put(Trie.java:165) ...

That's a pretty awesome Trie! Is there a way to efficiently query all words that start with "moo" or something? I skimmed through the code, but since you didn't post the encoder it's harder to just stare at and understand how it works =P

You could walk the trie and get out words that start with, but only a contains method is implemented. The encoder is junk, super inefficient in pretty much all ways, but since it runs offline it isn't a huge deal. It'd be better to use something like your trie then write out the readonly encoding. I'd post the encoder but I'm not yet sure if I'll do something with the trie.

I can't think of anything I'd need this for in a game but I have a non-game use for it. I was actually looking at trie a few weeks ago wondering if there was a java lib out there that would make it easy to pull off.

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org