remove method
Removes value
from the set.
Returns true
if value
was in the set, and false
if not.
The method has no effect if value
was not in the set.
final characters = <String>{'A', 'B', 'C'};
final didRemoveB = characters.remove('B'); // true
final didRemoveD = characters.remove('D'); // false
print(characters); // {A, C}
Implementation
@override
bool remove(Object? value) {
if (isEmpty) return false;
final index = _getBucketIndex(value);
final bucket = _buckets[index];
if (bucket != null) {
for (int i = 0; i < bucket.length; i++) {
if (bucket[i] == value) {
bucket.removeAt(i);
_size--;
// If bucket becomes empty, set to null to save memory (optional)
if (bucket.isEmpty) {
_buckets[index] = null;
}
return true;
}
}
}
return false;
}