frost.collections

Class IdentitySet<T>

    └ Object

Implemented Interfaces:

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.
Inherited Fields:

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 returns false.
mapInPlace(f:(T)=>(T))
Inherited Methods:

Initializers

init ()

Creates a new empty IdentitySet.

Creates a new set containing all of the elements from another collection, with duplicate entries filtered out.

Parameters:
c - value of type 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 - value of type 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:
c - value of type CollectionView<T>
Overrides:
frost.collections.CollectionWriter.addAll
method remove (value:T)

Removes an entry from the set, if present.

Parameters:
value - value of type T
@override
method clear ()

Removes all elements in the collection.

Overrides:
frost.collections.CollectionWriter.clear
function contains (value:T
):Bit

Returns true if the value is present in the set.

Parameters:
value - value of type 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:
test - value of type (T)=>(Bit)
Overrides:
frost.collections.CollectionWriter.filterInPlace
@override
method mapInPlace (f:(T)=>(T))
Parameters:
f - value of type (T)=>(T)