public final class WordResolver
extends java.lang.Object
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 |
WordResolver.Builder |
Modifier and Type | Field and Description |
---|---|
(package private) static char |
CHAR_NULL |
static int |
MAX_WORDS
Maximum number of words (Strings) an instance can contain
|
(package private) char[] |
mData
Compressed presentation of the word set.
|
(package private) static 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?)
|
(package private) java.lang.String[] |
mWords
Array of actual words returned resolved for matches.
|
(package private) static int |
NEGATIVE_OFFSET
Offset added to numbers to mark 'negative' numbers.
|
Modifier | Constructor and Description |
---|---|
private |
WordResolver(java.lang.String[] words,
char[] index) |
Modifier and Type | Method and Description |
---|---|
static WordResolver |
constructInstance(java.util.TreeSet<java.lang.String> wordSet)
Tries to construct an instance given ordered set of words.
|
java.lang.String |
find(char[] str,
int start,
int end) |
java.lang.String |
find(java.lang.String str) |
private java.lang.String |
findFromOne(char[] str,
int start,
int end) |
int |
size() |
java.lang.String |
toString() |
public static final int MAX_WORDS
static final char CHAR_NULL
static final int NEGATIVE_OFFSET
static final int MIN_BINARY_SEARCH
final char[] mData
final java.lang.String[] mWords
public static WordResolver constructInstance(java.util.TreeSet<java.lang.String> wordSet)
Note: currently maximum number of words that can be contained
is limited to MAX_WORDS
; additionally, maximum length
of all such words can not exceed roughly 28000 characters.
public int size()
public java.lang.String find(char[] str, int start, int end)
str
- Character array that contains the word to findstart
- Index of the first character of the wordend
- Index following the last character of the word,
so that end - start
equals word length (similar
to the way String.substring()
has).private java.lang.String findFromOne(char[] str, int start, int end)
public java.lang.String find(java.lang.String str)
public java.lang.String toString()
toString
in class java.lang.Object