# add method

1. @override

bool add(

1. E element

)
override

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:

    final dateTimes = <DateTime>{};
    final time1 = DateTime.fromMillisecondsSinceEpoch(0);
    final time2 = DateTime.fromMillisecondsSinceEpoch(0);
    // time1 and time2 are equal, but not identical.
    assert(time1 == time2);
    assert(!identical(time1, time2));
    final time1Added = dateTimes.add(time1);
    print(time1Added); // true
    // A value equal to time2 exists already in the set, and the call to
    // add doesn't change the set.
    final time2Added = dateTimes.add(time2);
    print(time2Added); // false

    print(dateTimes); // {1970-01-01 02:00:00.000}
    assert(dateTimes.length == 1);
    assert(identical(time1, dateTimes.first));
    print(dateTimes.length);

## Implementation

    @override
    bool add(E element) {
      if (_size / _capacity > _loadFactorThreshold) {
        _resize();
      }

      final index = _getBucketIndex(element);
      _buckets[index] ??= []; // Initialize bucket if null

      final bucket = _buckets[index]!;
      for (final existingElement in bucket) {
        if (existingElement == element) {
          return false; // Element already exists
        }
      }

      bucket.add(element);
      _size++;
      return true;
    }