CustomSet<T> class

Represents a mathematical set containing unique elements.

A set is a collection of distinct objects, called elements or members. This implementation follows standard set theory principles where:

  • Order of elements does not matter
  • Duplicate elements are automatically removed
  • All elements must be of the same type T

Example:

final numbers = CustomSet<int>([1, 2, 3, 4]);
final letters = CustomSet<String>(['a', 'b', 'c']);

Constructors

CustomSet([Iterable<T>? elements])
Creates a set from an iterable of elements.
CustomSet.empty()
Creates an empty set.
CustomSet.fromPredicate(Iterable<T> universe, bool predicate(T))
Creates a set from a predicate function applied to a universe.

Properties

cardinality int
Returns the cardinality (number of elements) in the set.
no setter
elements UnmodifiableSetView<T>
Returns an unmodifiable view of the set elements.
no setter
hashCode int
The hash code for this object.
no setteroverride
isEmpty bool
Returns true if the set contains no elements.
no setter
isNotEmpty bool
Returns true if the set contains at least one element.
no setter
powerSet CustomSet<CustomSet<T>>
Returns the power set of this set.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

add(T element) bool
Adds element to the set.
clear() → void
Removes all elements from the set.
complement(CustomSet<T> universal) CustomSet<T>
Returns the complement of this set with respect to universal.
contains(T element) bool
Checks if element is a member of this set.
difference(CustomSet<T> other) CustomSet<T>
Returns the difference of this set with other.
emptySet() CustomSet<T>
Creates an empty set.
equals(CustomSet<T> other) bool
Checks if this set is equal to other.
intersection(CustomSet<T> other) CustomSet<T>
Returns the intersection of this set with other.
isDisjointFrom(CustomSet<T> other) bool
Checks if this set is disjoint from other.
isEquivalentTo(CustomSet<T> other) bool
Checks if this set is equivalent to other.
isProperSubsetOf(CustomSet<T> other) bool
Checks if this set is a proper subset of other.
isProperSupersetOf(CustomSet<T> other) bool
Checks if this set is a proper superset of other.
isSubsetOf(CustomSet<T> other) bool
Checks if this set is a subset of other.
isSupersetOf(CustomSet<T> other) bool
Checks if this set is a superset of other.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
remove(T element) bool
Removes element from the set.
symmetricDifference(CustomSet<T> other) CustomSet<T>
Returns the symmetric difference of this set with other.
toString() String
A string representation of this object.
override
union(CustomSet<T> other) CustomSet<T>
Returns the union of this set with other.
universal(Iterable<T> elements) CustomSet<T>
Creates a universal set from the given elements.

Operators

operator ==(Object other) bool
The equality operator.
override