frost.collections

Class HashSet<T:HashKey<T>>

    └ Object

Implemented Interfaces:

An implementation of the set abstract data type. Sets are collections which cannot contain duplicate entries; adding an element which already exists to a set does not do anything.

Source Code:
View Source

Initializer Summary

init()
Creates a new empty set.
init(c:CollectionView<T>)
Creates a new set containing all of the elements from another collection.
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 set.

Creates a new set containing all of the elements from another collection. Duplicate entries are filtered out, so

HashSet<Int>(list).count

is an easy way to determine how many unique entries list contains.

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)