import java.util.ArrayList;
import java.util.List;
public class Main {
public static void main(String[] args) {
SimpleHashSet hashSet = new SimpleHashSet(10);
hashSet.add("Charlotte");
hashSet.add("Thomas");
hashSet.add("Jens");
hashSet.add("Peter");
hashSet.add("Lisa");
hashSet.add("Adele");
hashSet.add("Michaela");
hashSet.add("Bob");
hashSet.printSet();
System.out.println("\n'Peter' is in the set: " + hashSet.contains("Peter"));
System.out.println("Removing 'Peter'");
hashSet.remove("Peter");
System.out.println("'Peter' is in the set: " + hashSet.contains("Peter"));
System.out.println("'Adele' has hash code: " + hashSet.hashFunction("Adele"));
}
static class SimpleHashSet {
private final int size;
private final List<List<String>> buckets;
public SimpleHashSet(int size) {
this.size = size;
this.buckets = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
buckets.add(new ArrayList<>());
}
}
private int hashFunction(String value) {
return value.chars().reduce(0, Integer::sum) % size;
}
public void add(String value) {