Although this is an efficient data struct for specific set of usage patterns, one restriction is that the full set of words to include has to be known before constructing the instnace. Also, the size of the set is limited to total word content of about 20k characters.
Todo
Should document the internal data structure...
| Modifier and Type | Class and Description |
|---|---|
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv static final char | |
| public static final int | MAX_WORDS
Maximum number of words (Strings) an instance can contain |
| pack-priv final char[] | mData
Compressed presentation of the word set. |
| pack-priv static final int | MIN_BINARY_SEARCH
This is actually just a guess; but in general linear search should be faster for short sequences (definitely for 4 or less; maybe up to 8 or less?) |
| pack-priv final String[] | mWords
Array of actual words returned resolved for matches. |
| pack-priv static final int | NEGATIVE_OFFSET
Offset added to numbers to mark 'negative' numbers. |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public static WordResolver | Returns: WordResolver constructed for given set of words, if the word set size is not too big; null to indicate "too big" instance.Tries to construct an instance given ordered set of words. |
| public String | Returns: (Shared) string instance of the word, if it exists in the word set; null if not.Character array that contains the word to find str, final int Index of the first character of the word start, final int Index following the last character of the word,
so that end)end - start equals word length (similar
to the way String.substring() has).
|
| public String | |
| private String | |
| public int | |
| public String |
| CHAR_NULL | back to summary |
|---|---|
| pack-priv static final char CHAR_NULL | |
| MAX_WORDS | back to summary |
|---|---|
| public static final int MAX_WORDS Maximum number of words (Strings) an instance can contain | |
| mData | back to summary |
|---|---|
| pack-priv final char[] mData Compressed presentation of the word set. | |
| MIN_BINARY_SEARCH | back to summary |
|---|---|
| pack-priv static final int MIN_BINARY_SEARCH This is actually just a guess; but in general linear search should be faster for short sequences (definitely for 4 or less; maybe up to 8 or less?) | |
| mWords | back to summary |
|---|---|
| pack-priv final String[] mWords Array of actual words returned resolved for matches. | |
| NEGATIVE_OFFSET | back to summary |
|---|---|
| pack-priv static final int NEGATIVE_OFFSET Offset added to numbers to mark 'negative' numbers. Asymmetric, since range of negative markers needed is smaller than positive numbers... | |
| WordResolver | back to summary |
|---|---|
| pack-priv WordResolver(String[] words, char[] index) | |
| constructInstance | back to summary |
|---|---|
| public static WordResolver constructInstance(TreeSet<String> wordSet) Tries to construct an instance given ordered set of words. Note currently maximum number of words that can be contained
is limited to
| |
| find | back to summary |
|---|---|
public String find(char[] str, final int start, final int end)
| |
| find | back to summary |
|---|---|
public String find(String str)
| |
| findFromOne | back to summary |
|---|---|
| private String findFromOne(char[] str, final int start, final int end) | |
| size | back to summary |
|---|---|
public int size()
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv char[] | |
| pack-priv int | mSize
Number of characters currently used from mData |
| pack-priv final String[] |
| Modifier and Type | Method and Description |
|---|---|
| public WordResolver | |
| private void | constructBranch(int
Index of the character in words to consider
for this round charIndex, int Index of the first word to be processed start, int Index of the word after last word to be processed
(so that number of words is end)end - start - 1Method that is called recursively to build the data representation for a branch, ie. |
| private char[] |
| mData | back to summary |
|---|---|
| pack-priv char[] mData | |
| mSize | back to summary |
|---|---|
| pack-priv int mSize Number of characters currently used from mData | |
| mWords | back to summary |
|---|---|
| pack-priv final String[] mWords | |
| Builder | back to summary |
|---|---|
| public Builder(TreeSet<String> wordSet) | |
| construct | back to summary |
|---|---|
public WordResolver construct()
| |
| constructBranch | back to summary |
|---|---|
| private void constructBranch(int charIndex, int start, int end) Method that is called recursively to build the data representation for a branch, ie. part of word set tree that still has more than one ending
| |
| expand | back to summary |
|---|---|
| private char[] expand(int needSpace) | |