Dart API Referencedart:coreHashSet<E>

HashSet<E> abstract class

abstract class HashSet<E> extends Set<E> {
  factory HashSet() => new HashSetImplementation<E>();

  /**
   * Creates a [Set] that contains all elements of [other].
   */
  factory HashSet.from(Iterable<E> other) =>
      new HashSetImplementation<E>.from(other);
}

Extends

Iterable<E> > Collection<E> > Set<E> > HashSet<E>

Subclasses

HashSetImplementation<E>

Constructors

factory HashSet() #

factory HashSet() => new HashSetImplementation<E>();

factory HashSet.from(Iterable<E> other) #

Creates a Set that contains all elements of other.

factory HashSet.from(Iterable<E> other) =>
    new HashSetImplementation<E>.from(other);

Properties

final int length #

inherited from Collection

Returns the number of elements in this collection.

int get length;

Methods

void add(E value) #

inherited from Set

Adds value into the set. The method has no effect if value was already in the set.

void add(E value);

void addAll(Collection<E> collection) #

inherited from Set

Adds all the elements of the given collection to the set.

void addAll(Collection<E> collection);

void clear() #

inherited from Set

Removes all elements in the set.

void clear();

bool contains(E value) #

inherited from Set

Returns true if value is in the set.

bool contains(E value);

bool containsAll(Collection<E> collection) #

inherited from Set

Returns true if this collection contains all the elements of collection.

bool containsAll(Collection<E> collection);

bool every(bool f(E element)) #

inherited from Collection

Returns true if every elements of this collection satisify the predicate f. Returns false otherwise.

bool every(bool f(E element)) {
  for (E element in this) {
    if (!f(element)) return false;
  }
  return true;
}

Collection<E> filter(bool f(E element)) #

inherited from Collection

Returns a collection with the elements of this collection that satisfy the predicate f.

The returned collection should be of the same type as the collection creating it.

An element satisfies the predicate f if f(element) returns true.

Collection<E> filter(bool f(E element));

void forEach(void f(E element)) #

inherited from Collection

Applies the function f to each element of this collection.

void forEach(void f(E element)) {
  for (E element in this) f(element);
}

Set<E> intersection(Collection<E> other) #

inherited from Set

Returns a new set which is the intersection between this set and the given collection.

Set<E> intersection(Collection<E> other);

bool isEmpty() #

inherited from Collection

Returns true if there is no element in this collection.

bool isEmpty() => !iterator().hasNext();

bool isSubsetOf(Collection<E> collection) #

inherited from Set

Returns true if collection contains all the elements of this collection.

bool isSubsetOf(Collection<E> collection);

Iterator<E> iterator() #

inherited from Iterable

Returns an Iterator that iterates over this Iterable object.

Iterator<E> iterator();

Collection map(f(E element)) #

inherited from Collection

Returns a new collection with the elements f(e) for each element e of this collection.

Subclasses of Collection should implement the map method to return a collection of the same general type as themselves. E.g., List.map should return a List.

Collection map(f(E element));

reduce(initialValue, combine(previousValue, E element)) #

inherited from Collection

Reduce a collection to a single value by iteratively combining each element of the collection with an existing value using the provided function. Use initialValue as the initial value, and the function combine to create a new value from the previous one and an element.

Example of calculating the sum of a collection:

collection.reduce(0, (prev, element) => prev + element);

Dynamic reduce(var initialValue,
               Dynamic combine(var previousValue, E element)) {
  var value = initialValue;
  for (E element in this) value = combine(value, element);
  return value;
}

bool remove(E value) #

inherited from Set

Removes value from the set. Returns true if value was in the set. Returns false otherwise. The method has no effect if value value was not in the set.

bool remove(E value);

void removeAll(Collection<E> collection) #

inherited from Set

Removes all the elements of the given collection from the set.

void removeAll(Collection<E> collection);

bool some(bool f(E element)) #

inherited from Collection

Returns true if one element of this collection satisfies the predicate f. Returns false otherwise.

bool some(bool f(E element)) {
  for (E element in this) {
    if (f(element)) return true;
  }
  return false;
}