Top Description Inners Fields Constructors Methods
com.ctc.wstx.util

public final Class WordSet

extends Object
Class Inheritance
Imports
java.util.*

An efficient (both memory and time) implementation of a Set used to verify that a given word is contained within the set. The general usage pattern is expected to be such that most checks are positive, ie. that the word indeed is contained in the set.

Performance of the set is comparable to that of java.util.TreeSet for Strings, ie. 2-3x slower than java.util.HashSet when using pre-constructed Strings. This is generally result of algorithmic complexity of structures; Word and Tree sets are roughly logarithmic to the whole data, whereas Hash set is linear to the length of key. However:

Although this is an efficient set for specific set of usage patterns, one restriction is that the full set of words to include has to be known before constructing the set. Also, the size of the set is limited to total word content of about 20k characters; factory method does verify the limit and indicates if an instance can not be created.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
pack-priv static final char
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 static final int
NEGATIVE_OFFSET

Offset added to numbers to mark 'negative' numbers.

Constructor Summary

AccessConstructor and Description
private
WordSet(char[] data)

Method Summary

Modifier and TypeMethod and Description
public static char[]
public static WordSet
public boolean
contains(char[] buf, int start, int end)

public static boolean
contains(char[] data, char[] str, int start, int end)

public boolean
public static boolean
contains(char[] data, String str)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CHAR_NULLback to summary
pack-priv static final char CHAR_NULL
mDataback to summary
pack-priv final char[] mData

Compressed presentation of the word set.

NEGATIVE_OFFSETback 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...

Constructor Detail

WordSetback to summary
private WordSet(char[] data)

Method Detail

constructRawback to summary
public static char[] constructRaw(TreeSet<String> wordSet)
constructSetback to summary
public static WordSet constructSet(TreeSet<String> wordSet)
containsback to summary
public boolean contains(char[] buf, int start, int end)
containsback to summary
public static boolean contains(char[] data, char[] str, int start, int end)
Annotations
@SuppressWarnings:cast
containsback to summary
public boolean contains(String str)
containsback to summary
public static boolean contains(char[] data, String str)
Annotations
@SuppressWarnings:cast
com.ctc.wstx.util back to summary

private final Class WordSet.Builder

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv char[]
pack-priv int
mSize

Number of characters currently used from mData

pack-priv final String[]

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public char[]

Returns:

Raw character data that contains compressed structure of the word set
construct
()

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 - start - 1
end
)

Method that is called recursively to build the data representation for a branch, ie.

private void
constructLeaf(int charIndex, int wordIndex)

Method called to add leaf entry to word set; basically "here is the rest of the only matching word"

private char[]
expand(int needSpace)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

mDataback to summary
pack-priv char[] mData
mSizeback to summary
pack-priv int mSize

Number of characters currently used from mData

mWordsback to summary
pack-priv final String[] mWords

Constructor Detail

Builderback to summary
public Builder(TreeSet<String> wordSet)

Method Detail

constructback to summary
public char[] construct()
Returns:char[]

Raw character data that contains compressed structure of the word set

constructBranchback 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

Parameters
charIndex:int

Index of the character in words to consider for this round

start:int

Index of the first word to be processed

end:int

Index of the word after last word to be processed (so that number of words is end - start - 1

Annotations
@SuppressWarnings:cast
constructLeafback to summary
private void constructLeaf(int charIndex, int wordIndex)

Method called to add leaf entry to word set; basically "here is the rest of the only matching word"

expandback to summary
private char[] expand(int needSpace)