public final class SimpleWordSet {
-// to avoid using Enumerations, walk the individual values skipping nulls
-public char[][] words;
-public int elementSize; // number of elements in the table
-public int threshold;
+ // to avoid using Enumerations, walk the individual values skipping nulls
+ public char[][] words;
-public SimpleWordSet(int size) {
- this.elementSize = 0;
- this.threshold = size; // size represents the expected number of elements
- int extraRoom = (int) (size * 1.5f);
- if (this.threshold == extraRoom)
- extraRoom++;
- this.words = new char[extraRoom][];
-}
+ public int elementSize; // number of elements in the table
-public char[] add(char[] word) {
- int length = this.words.length;
- int index = CharOperation.hashCode(word) % length;
- char[] current;
- while ((current = words[index]) != null) {
- if (CharOperation.equals(current, word)) return current;
- if (++index == length) index = 0;
+ public int threshold;
+
+ public SimpleWordSet(int size) {
+ this.elementSize = 0;
+ this.threshold = size; // size represents the expected number of
+ // elements
+ int extraRoom = (int) (size * 1.5f);
+ if (this.threshold == extraRoom)
+ extraRoom++;
+ this.words = new char[extraRoom][];
}
- words[index] = word;
- // assumes the threshold is never equal to the size of the table
- if (++elementSize > threshold) rehash();
- return word;
-}
+ public char[] add(char[] word) {
+ int length = this.words.length;
+ int index = CharOperation.hashCode(word) % length;
+ char[] current;
+ while ((current = words[index]) != null) {
+ if (CharOperation.equals(current, word))
+ return current;
+ if (++index == length)
+ index = 0;
+ }
+ words[index] = word;
+
+ // assumes the threshold is never equal to the size of the table
+ if (++elementSize > threshold)
+ rehash();
+ return word;
+ }
-public boolean includes(char[] word) {
- int length = this.words.length;
- int index = CharOperation.hashCode(word) % length;
- char[] current;
- while ((current = words[index]) != null) {
- if (CharOperation.equals(current, word)) return true;
- if (++index == length) index = 0;
+ public boolean includes(char[] word) {
+ int length = this.words.length;
+ int index = CharOperation.hashCode(word) % length;
+ char[] current;
+ while ((current = words[index]) != null) {
+ if (CharOperation.equals(current, word))
+ return true;
+ if (++index == length)
+ index = 0;
+ }
+ return false;
}
- return false;
-}
-private void rehash() {
- SimpleWordSet newSet = new SimpleWordSet(elementSize * 2); // double the number of expected elements
- char[] current;
- for (int i = words.length; --i >= 0;)
- if ((current = words[i]) != null)
- newSet.add(current);
+ private void rehash() {
+ SimpleWordSet newSet = new SimpleWordSet(elementSize * 2); // double
+ // the
+ // number of
+ // expected
+ // elements
+ char[] current;
+ for (int i = words.length; --i >= 0;)
+ if ((current = words[i]) != null)
+ newSet.add(current);
- this.words = newSet.words;
- this.elementSize = newSet.elementSize;
- this.threshold = newSet.threshold;
-}
+ this.words = newSet.words;
+ this.elementSize = newSet.elementSize;
+ this.threshold = newSet.threshold;
+ }
}
\ No newline at end of file