Class IdentitySet<T>
Object
A Set
which compares its entries using identity (==
) instead of equality (=
). Unlike
HashSet
, which requires its entries to implement the Key
interface, any type of object may be
used in an IdentitiySet
. However, it is important that the type not be a subclass of Value
, as
values do not have well-defined identities and IdentitySet
will therefore not function properly
with value types.
- Source Code:
- View Source
Initializer Summary
init ()- Creates a new empty
IdentitySet
. init (c :
)CollectionView<T> - Creates a new set containing all of the elements from another collection, with duplicate entries filtered out.
Instance Method Summary
add (value :
)T - Adds a new element to the collection.
addAll (c :
)CollectionView<T> - Adds all elements in
c
to this collection. remove (value :
)T - Removes an entry from the set, if present.
clear ()- Removes all elements in the collection.
contains (value :
):T Bit - Returns
true
if the value is present in the set. filterInPlace (test :
)(T)=>(Bit) - Calls the
test
function on each element in the collection, removing all elements for which the function returnsfalse
. mapInPlace (f :
)(T)=>(T)
map((T)=&>(U)):Array<U>
map((T)=>(U)):Array<U>
apply((T)=&>())
fold((T, T)=&>(T), T):T
fold((T, T)=>(T), T):T
fold((T, T)=&>(T)):T
fold((T, T)=>(T)):T
join(String):String
join():String
Initializers
init
()
Creates a new empty IdentitySet
.
init
(c :CollectionView<T>
)
Creates a new set containing all of the elements from another collection, with duplicate entries filtered out.
- Parameters:
-
- value of typec CollectionView<T>
Instance Methods
@override
method add
(value :T
)
Adds a new element to the collection. The exact semantics of add
- does it add to the end of
the collection, or an arbitrary location? does it always actually add the element, or sometimes
leave the collection unmodified? - are defined by the collection implementation.
- Parameters:
-
- value of typevalue T
- Overrides:
- frost.collections.CollectionWriter.add
@override
method addAll
(c :CollectionView<T>
)
Adds all elements in c
to this collection. The default implementation simply calls add
for
each element in c
, in iteration order.
- Parameters:
-
- value of typec CollectionView<T>
- Overrides:
- frost.collections.CollectionWriter.addAll
method remove
(value :T
)
Removes an entry from the set, if present.
- Parameters:
-
- value of typevalue T
@override
method clear
()
Removes all elements in the collection.
- Overrides:
- frost.collections.CollectionWriter.clear
Returns true
if the value is present in the set.
- Parameters:
-
- value of typevalue T
@override
method filterInPlace
(test :(T)=>(Bit)
)
Calls the test
function on each element in the collection, removing all elements for which the
function returns false
.
For example, the code
def collection := [1, 2, 3, 4 ,5]
collection.filterInPlace(x => x % 2 = 1)
Console.printLine(collection)
will display [1, 3, 5]
, as the filter function returns true only for elements with odd values.
- Parameters:
-
- value of typetest (T)=>(Bit)
@override
method mapInPlace
(f :(T)=>(T)
)
- Parameters:
-
- value of typef (T)=>(T)