add method

ISet<T> add(
  1. T item
)

Returns a new set containing the current set plus the given item.

Implementation

ISet<T> add(T item) {
  ISet<T> result = config.sort
      ? ISet._unsafe(SFlat(_s.followedBy([item]), config: config), config: config)
      : ISet<T>._unsafe(_s.add(item), config: config);

  // A set created with `add` has a larger counter than its source set.
  // This improves the order in which sets are flushed.
  // If the outer set is used, it will be flushed before the source set.
  // If the source set is not used directly, it will not flush unnecessarily,
  // and also may be garbage collected.
  result._counter = _counter;
  result._count();

  return result;
}