An identity map implemented as a hash map stored in an Array of singly linked lists of Entrys. The hash code of a key is defined by identityHash(). Note that an IdentitySet is not a Map, since it does not obey the semantics of a Map. In particular, it may contain multiple keys which are equal, as determined by the == operator.

By: Gavin King

no subtypes hierarchy

IdentityMap(Hashtable hashtable = ..., {<Key->Item>*} entries = ...)
  • hashtable = Hashtable()

    Performance-related settings for the backing array.

  • entries = {}

    The initial entries in the map.

hashSource Codeshared actual Integer hash

The hash value of the value, which allows the value to be an element of a hash-based set or key of a hash-based map. Implementations must respect the constraint that:

  • if x==y then x.hash==y.hash.

Therefore, a class which refines equals must also refine hash.

In general, hash values vary between platforms and between executions of the same program.

Note that when executing on a Java Virtual Machine, the 64-bit Integer value returned by an implementation of hash is truncated to a 32-bit integer value by removal of the 32 highest order bits, before returning the value to the caller.

Refines Identifiable.hash ultimately refines Object.hash
sizeSource Codeshared actual Integer size

The number of elements returned by the iterator of this stream, if the iterator terminates. In the case of an infinite stream, this operation never terminates.

Inherited Attributes
Attributes inherited from: Object
Attributes inherited from: Collection<Element>
Attributes inherited from: Correspondence<Key,Item>
Attributes inherited from: Iterable<Element,Absent>
clearSource Codeshared void clear()

Removes every key/value mapping

cloneSource Codeshared actual IdentityMap<Key,Item> clone()

A shallow copy of this collection, that is, a collection with identical elements which does not change if this collection changes. If this collection is immutable, it is acceptable to return a reference to this collection. If this collection is mutable, a newly instantiated collection must be returned.

containsSource Codeshared actual Boolean contains(Object element)

Returns true if the given value belongs to this Category, that is, if it is an element of this Category, or false otherwise.

For most Categorys the following relationship is satisfied by every pair of elements x and y:

  • if x==y, then x in category == y in category

However, it is possible to form a useful Category consistent with some other equivalence relation, for example ===. Therefore implementations of contains() which do not satisfy this relationship are tolerated.

Refines Iterable.contains ultimately refines Category.contains
countSource Codeshared actual Integer count(Boolean selecting(Key->Item element))

Produces the number of elements in this stream that satisfy the given predicate function (selecting). For an infinite stream, this method never terminates.

definesSource Codeshared actual Boolean defines(Key key)

Determines if there is a value defined for the given key.

eachSource Codeshared actual void each(void step(Key->Item element))

Call the given function (step) for each element of this stream, passing the elements in the order they occur in this stream.

For example:

words.each((word) {

Has the same effect as the following for loop:

for (word in words) {

For certain streams this method is highly efficient, surpassing the performance of for loops on the JVM. Thus, each() is sometimes preferred in highly performance-critical low-level code.

equalsSource Codeshared actual Boolean equals(Object that)

Determine if two values are equal. Implementations should respect the constraints that:

  • if x===y then x==y (reflexivity),
  • if x==y then y==x (symmetry),
  • if x==y and y==z then x==z (transitivity).

Furthermore it is recommended that implementations ensure that if x==y then x and y have the same concrete class.

A class which explicitly refines equals() is said to support value equality, and the equality operator == is considered much more meaningful for such classes than for a class which simply inherits the default implementation of identity equality from Identifiable.

Note that an implementation of equals() that always returns false does satisfy the constraints given above. Therefore, in very rare cases where there is no reasonable definition of value equality for a class, for example, function references (Callable), it is acceptable for equals() to be defined to return false for every argument.

Refines Identifiable.equals ultimately refines Object.equals
getSource Codeshared actual Item? get(Key key)

Returns the value defined for the given key, or null if there is no value defined for the given key.

iteratorSource Codeshared actual Iterator<Key->Item> iterator()

An iterator for the elements belonging to this stream.

putSource Codeshared Item? put(Key key, Item item)
putAllSource Codeshared void putAll({<Key->Item>*} entries)

Adds a collection of key/value mappings to this map, may be used to change existing mappings

removeSource Codeshared Item? remove(Key key)

Removes a key/value mapping if it exists

removeAllSource Codeshared void removeAll({Key*} keys)

Remove the entries associated with the given keys, if any, from this map

removeEntrySource Codeshared Boolean removeEntry(Key key, Item&Object item)
replaceEntrySource Codeshared Boolean replaceEntry(Key key, Item&Object item, Item newItem)
Inherited Methods
Methods inherited from: Object
Methods inherited from: Category<Element>
Methods inherited from: Collection<Element>
Methods inherited from: Correspondence<Key,Item>
Methods inherited from: Iterable<Element,Absent>