HashSetImplementation<E extends Hashable> Class
Implements
Constructors
Code new HashSetImplementation() #
HashSetImplementation() { _backingMap = new HashMapImplementation<E, E>(); }
Code factory HashSetImplementation.from(Iterable<E> other) #
factory HashSetImplementation.from(Iterable<E> other) { Set<E> set = new HashSetImplementation<E>(); for (final e in other) { set.add(e); } return set; }
Methods
Code void addAll(Collection<E> collection) #
void addAll(Collection<E> collection) { collection.forEach(void _(E value) { add(value); }); }
Code void clear() #
void clear() { _backingMap.clear(); }
Code bool containsAll(Collection<E> collection) #
bool containsAll(Collection<E> collection) { return collection.every(bool _(E value) { return contains(value); }); }
Code bool every(bool f(E element)) #
bool every(bool f(E element)) { Collection<E> keys = _backingMap.getKeys(); return keys.every(f); }
Code Set<E> filter(bool f(E element)) #
Set<E> filter(bool f(E element)) { Set<E> result = new Set<E>(); _backingMap.forEach(void _(E key, E value) { if (f(key)) result.add(key); }); return result; }
Code void forEach(void f(E element)) #
void forEach(void f(E element)) { _backingMap.forEach(void _(E key, E value) { f(key); }); }
Code Set<E> intersection(Collection<E> collection) #
Set<E> intersection(Collection<E> collection) { Set<E> result = new Set<E>(); collection.forEach(void _(E value) { if (contains(value)) result.add(value); }); return result; }
Code bool isSubsetOf(Collection<E> other) #
bool isSubsetOf(Collection<E> other) { return new Set<E>.from(other).containsAll(this); }
Code Set map(f(E element)) #
Set map(f(E element)) { Set result = new Set(); _backingMap.forEach(void _(E key, E value) { result.add(f(key)); }); return result; }
Code bool remove(E value) #
bool remove(E value) { if (!_backingMap.containsKey(value)) return false; _backingMap.remove(value); return true; }
Code void removeAll(Collection<E> collection) #
void removeAll(Collection<E> collection) { collection.forEach(void _(E value) { remove(value); }); }