IdentitySet
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.
Properties
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.
Functions
This function returns the first node that matches the name on the supplied list of nodes.
A shortcut to call firstOrNull using the []
syntax.
A shortcut to call byNameOrNull using the []
syntax.
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.