Class IdentitySet

extends Set implements Collection
A set that uses object identity instead of the == operator to test equality of elements. This set still uses the hash-code method on elements (see Set). There is no identity hash code operation on arbitrary classes in Toit.

Class summary


clear -> none
Removes all elements from this instance.
size -> int
The number of elements in this instance.
is-empty -> bool
Whether this instance is empty.
contains key/any -> bool
Whether this instance contains the given key.
contains-all collection/Collection -> bool
Whether this instance contains all elements of collection.
remove key/any -> none
Removes the given key from this instance.
remove key/any [--if-absent] -> none
Removes the given key from this instance.
remove-all collection/Collection -> none
Removes all elements of collection from this instance.
add key/any -> none
Adds the given key to this instance.
add-all collection/Collection -> none
Adds all elements of the given collection to this instance.
do [block] -> none
do --reversed/True [block] -> none
operator == other/Set -> bool
every [predicate] -> bool
copy -> Set
Copies the set.
any [predicate] -> bool
reduce [block] -> any
reduce --initial/any [block] -> any
map [block] -> Set
Invokes the given block on each element and returns a new set with the results.
filter --in-place/bool= [predicate] -> Set
Filters this instance using the given predicate.
intersect --in-place/bool= other/Set -> Set
Intersects this instance with the other set.
stringify -> string
get key/any [--if-absent] -> any
Returns an element that is equal to the key.
get key/any -> any
Returns an element that is equal to the key.
first -> any
The first element of the set by insertion order.
last -> any
The last element of the set by insertion order.
to-list -> List
Returns a list of the elements of this set.

Methods

add key/any -> none
Adds the given key to this instance.
If an equal key is already in this instance, it is overwritten by the new one.

add-all collection/Collection -> none
Adds all elements of the given collection to this instance.

any [predicate] -> bool

clear -> none
Removes all elements from this instance.

contains key/any -> bool
Whether this instance contains the given key.

Whether this instance contains all elements of collection.

Copies the set.
Returns a new instance that has the same values as this instance.
The copy is shallow and does not clone/copy the elements.

do [block] -> none

do --reversed/True [block] -> none
Iterates over the elements of this collection in reverse order.

every [predicate] -> bool

filter --in-place/bool=false [predicate] -> Set
Filters this instance using the given predicate.
Returns a new set if in-place is false (the default).
Returns this instance if in-place is true.
The result contains all the elements of this instance for which the predicate returns true.
Users must not otherwise modify this instance during the operation.

first -> any
The first element of the set by insertion order.
Throws an error if the set is empty.

get key/any [--if-absent] -> any
Returns an element that is equal to the key.
The key may be a lightweight object that has compatible hash code and equality to the element.

get key/any -> any
Returns an element that is equal to the key.
Returns null if this instance doesn't contain the key.

intersect --in-place/bool=false other/Set -> Set
Intersects this instance with the other set.
The result contains all elements that are both in this instance, as well as in the other set.
Returns a new set if in-place is false (the default).
Returns this instance, if in-place is true.

Whether this instance is empty.

last -> any
The last element of the set by insertion order.
Throws an error if the set is empty.

map [block] -> Set
Invokes the given block on each element and returns a new set with the results.

reduce --initial/any [block] -> any

remove key/any -> none
Removes the given key from this instance.
The key does not need to be present.

remove key/any [--if-absent] -> none
Removes the given key from this instance.
If the key is absent, calls if-absent with the key.

remove-all collection/Collection -> none
Removes all elements of collection from this instance.

The number of elements in this instance.

Returns a list of the elements of this set.