package org.eclipse.jdt.internal.core.util;
import org.eclipse.jdt.core.compiler.CharOperation;
public final class SimpleWordSet {
public char[][] words;
public int elementSize;
public int threshold;
public SimpleWordSet(int size) {
this.elementSize = 0;
this.threshold = size;
int extraRoom = (int) (size * 1.5f);
if (this.threshold == extraRoom)
extraRoom++;
this.words = new char[extraRoom][];
}
public char[] add(char[] word) {
int length = this.words.length;
int index = CharOperation.hashCode(word) % length;
char[] current;
while ((current = this.words[index]) != null) {
if (CharOperation.equals(current, word)) return current;
if (++index == length) index = 0;
}
this.words[index] = word;
if (++this.elementSize > this.threshold) rehash();
return word;
}
public boolean includes(char[] word) {
int length = this.words.length;
int index = CharOperation.hashCode(word) % length;
char[] current;
while ((current = this.words[index]) != null) {
if (CharOperation.equals(current, word)) return true;
if (++index == length) index = 0;
}
return false;
}
private void rehash() {
SimpleWordSet newSet = new SimpleWordSet(this.elementSize * 2);
char[] current;
for (int i = this.words.length; --i >= 0;)
if ((current = this.words[i]) != null)
newSet.add(current);
this.words = newSet.words;
this.elementSize = newSet.elementSize;
this.threshold = newSet.threshold;
}
}