package org.eclipse.jdt.internal.core.builder;
public class StringSet {
public String[] values;
public int elementSize;
public int threshold;
public StringSet(int size) {
this.elementSize = 0;
this.threshold = size;
int extraRoom = (int) (size * 1.5f);
if (this.threshold == extraRoom)
extraRoom++;
this.values = new String[extraRoom];
}
public boolean add(String value) {
int length = this.values.length;
int index = (value.hashCode() & 0x7FFFFFFF) % length;
String current;
while ((current = this.values[index]) != null) {
if (value.equals(current)) return false;
if (++index == length) index = 0;
}
this.values[index] = value;
if (++this.elementSize > this.threshold) rehash();
return true;
}
public void clear() {
for (int i = this.values.length; --i >= 0;)
this.values[i] = null;
this.elementSize = 0;
}
public boolean includes(String value) {
int length = this.values.length;
int index = (value.hashCode() & 0x7FFFFFFF) % length;
String current;
while ((current = this.values[index]) != null) {
if (value.equals(current)) return true;
if (++index == length) index = 0;
}
return false;
}
private void rehash() {
StringSet newSet = new StringSet(this.elementSize * 2);
String current;
for (int i = this.values.length; --i >= 0;)
if ((current = this.values[i]) != null)
newSet.add(current);
this.values = newSet.values;
this.elementSize = newSet.elementSize;
this.threshold = newSet.threshold;
}
@Override
public String toString() {
String s = "";
String value;
for (int i = 0, l = this.values.length; i < l; i++)
if ((value = this.values[i]) != null)
s += value + "\n";
return s;
}
}