Dart API Referencedart:coreimplHashSetImplementation<E>

HashSetImplementation<E extends Hashable> Class

Implements

HashSet<E>

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 add(E value) #

void add(E value) {
  _backingMap[value] = value;
}

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 contains(E value) #

bool contains(E value) {
  return _backingMap.containsKey(value);
}

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 isEmpty() #

bool isEmpty() {
  return _backingMap.isEmpty();
}

Code bool isSubsetOf(Collection<E> other) #

bool isSubsetOf(Collection<E> other) {
  return new Set<E>.from(other).containsAll(this);
}

Code Iterator<E> iterator() #

Iterator<E> iterator() {
  return new HashSetIterator<E>(this);
}

Code int get length() #

int get length() {
  return _backingMap.length;
}

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);
  });
}

Code bool some(bool f(E element)) #

bool some(bool f(E element)) {
  Collection<E> keys = _backingMap.getKeys();
  return keys.some(f);
}

Code String toString() #

String toString() {
  return Collections.collectionToString(this);
}