IdentitySet

open class IdentitySet<T> : MutableSet<T>

This class implements the MutableSet interface with an underlying map and reference-equality instead of object-equality. That means, objects are only considered equal, if they are the same object. This logic is primarily implemented by the underlying IdentityHashMap.

The use case of this MutableSet is quite simple: In order to avoid loops while traversing in the CPG AST we often need to store Node objects in a work-list (usually a set), in order to filter out nodes that were already visited or processed (for example, see SubgraphWalker.flattenAST. However, using a normal set triggers object-equality functions, such as Node.hashCode or even worse Node.equals, if the hashcode is the same. This can potentially be very resource-intensive if nodes are very similar but not the same, in a work-list however we only want just to avoid to place the exact node twice.

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard

This computed property returns the common type in a Collection of Type objects. For example, if two types A and B both derive from the interface C`` then C` would be returned.

Link copied to clipboard
open override val size: Int

Functions

Link copied to clipboard
open override fun add(element: T): Boolean
Link copied to clipboard
open override fun addAll(elements: Collection<T>): Boolean
Link copied to clipboard
fun <T : Node> Collection<T>?.byNameOrNull(lookup: String, modifier: SearchModifier): T?

This function returns the first node that matches the name on the supplied list of nodes.

Link copied to clipboard
open override fun clear()
Link copied to clipboard
open operator override fun contains(element: T): Boolean
Link copied to clipboard
open override fun containsAll(elements: Collection<T>): Boolean
Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
open fun forEach(p0: Consumer<in T>)
Link copied to clipboard
operator fun <T : Node> Collection<T>?.get(predicate: (T) -> Boolean, modifier: SearchModifier = SearchModifier.NONE): T?

A shortcut to call firstOrNull using the [] syntax.

operator fun <T : Node> Collection<T>?.get(lookup: String, modifier: SearchModifier = SearchModifier.NONE): T?

A shortcut to call byNameOrNull using the [] syntax.

Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
operator fun <T : Node> Collection<T>.invoke(predicate: (T) -> Boolean): List<T>

A shortcut invoke filter on a list of nodes.

operator fun <T : Node> Collection<T>.invoke(lookup: String): List<T>

A shortcut to filter a list of nodes by their name.

Link copied to clipboard
open override fun isEmpty(): Boolean
Link copied to clipboard
open operator override fun iterator(): MutableIterator<T>
Link copied to clipboard
open fun parallelStream(): Stream<T>
Link copied to clipboard
open override fun remove(element: T): Boolean
Link copied to clipboard
open override fun removeAll(elements: Collection<T>): Boolean
Link copied to clipboard
open fun removeIf(p0: Predicate<in T>): Boolean
Link copied to clipboard
open override fun retainAll(elements: Collection<T>): Boolean
Link copied to clipboard
open override fun spliterator(): Spliterator<T>
Link copied to clipboard
open fun stream(): Stream<T>
Link copied to clipboard
open fun <T : Any> toArray(p0: IntFunction<Array<T>>): Array<T>
Link copied to clipboard
Link copied to clipboard

Returns the contents of this IdentitySet as a sorted List according to order the nodes were inserted to. This is particularly useful, if you need to look up values in the list according to their "closeness" to the root AST node.

Link copied to clipboard
infix fun <T> IdentitySet<T>.union(other: Iterable<T>): IdentitySet<T>