add method

bool add(E element)

Adds value to the set.

Returns true if value (or an equal value) was not yet in the set. Otherwise returns false and the set is not changed.

Example:

var set = new Set();
var time1 = new DateTime.fromMillisecondsSinceEpoch(0);
var time2 = new DateTime.fromMillisecondsSinceEpoch(0);
// time1 and time2 are equal, but not identical.
Expect.isTrue(time1 == time2);
Expect.isFalse(identical(time1, time2));
set.add(time1);  // => true.
// A value equal to time2 exists already in the set, and the call to
// add doesn't change the set.
set.add(time2);  // => false.
Expect.isTrue(set.length == 1);
Expect.isTrue(identical(time1, set.first));

Source

bool add(E element) {
  int compare = _splay(element);
  if (compare == 0) return false;
  _addNewRoot(new _SplayTreeNode(element), compare);
  return true;
}

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dartlang.org/stable/1.24.3/dart-collection/SplayTreeSet/add.html