Library elements: Graph_createNodeLookup and Graph_getNodesFromLookup

The methods Graph_createNodeLookup and Graph_getNodesFromLookup make it possible to do efficient lookups for graph elements based on one identifying attribute. In fact, creating a node lookup map and then searching with this map can drastically increase the performance if matches have to be found within a high number of nodes.

You can find the functions in the Library in Soley Studio under Graph and then Lookup.

Graph_createNodeLookup

Graph_createNodeLookup(NODECLASS_NAME, ATTR_NAME):LOOKUP

This library element enables the user to create a LOOKUP object that can be utilized to carry out efficient lookups for a node with a certain attribute value.

Input Parameters

NODECLASS_NAME:string : This is the class of the nodes that has to be included in the lookup.

ATTRIBUTE_NAME:string : This is the name of the attribute of the node class that will be used for the lookup.

Returns

LOOKUP:object is the return value of this sequence. In addition to that, this is also the lookup object to be used in the sequence Graph_getNodesFromLookup().

Example

sequence createNodeLookup_demo{    LOOKUP:object&    {LOOKUP = Graph_createNodeLookup("ColorNode", "id");}

This sequence outlines how a lookup object is assigned to a variable. The object contains occurring values of ATTRIBUTE_NAME which then reference one or more nodes of the graph model. You may customize the template according to your metamodel.

Graph_getNodesFromLookup

Graph_getNodesFromLookup(LOOKUP, VALUE):NODE_ARRAY

Uses a lookup object LOOKUP to search a list of nodes efficiently and retrieve those featuring a specified attribute value.

The value type of the attribute assigned to the LOOKUP object with Graph_createNodeLookup() must be specified when using Graph_getNodesFromLookup with the following three functions:

  • Graph_getNodesFromLookupInt(LOOKUP, INT_VALUE) , if the attribute is of type integer
  • Graph_getNodesFromLookupLong(LOOKUP, LONG_VALUE ) , if the attribute is of type long
  • Graph_getNodesFromLookupString(LOOKUP, STR_VALUE ) , if the attribute is of type string

It is important to note that it is not possible to call Graph_getNodesFromLookup in your code. One of the three previous functions must be used.

Input Parameters

LOOKUP:object : It is a collection of keys created by Graph_createNodeLookup().

INT_VALUE:int or LONG_VALUE:long or STR_VALUE:string : Attribute value of type integer or long or string that the returned nodes will carry. It is important to denote long values explicitly by postfixing an L e.g. 429496723L.

Returns

ARRAY:array : It is a list of nodes that match the specified attribute value.

Example

sequence getNodesFromLookupIntDemo{   LOOKUP:object &   {LOOKUP = Graph_createNodeLookup("ColorNode", "id");} &   NODE_ARRAY:array<Node>  &   {NODE_ARRAY = Graph_getNodesFromLookupInt(LOOKUP, 1); } }

This demonstration sequence retrieves node instances from a previously created lookup object and stores them in an array of type Node. This particular LOOKUP comprises the graph nodes of class ClassNode and is already sorted by their attribute id. Therefore, a group of nodes having an id value of 1 can readily be selected and assigned to the storage array, which in this case of unique identifiers shall not exceed the cardinality of 1. Note that this example should be adapted according to your metamodel.

Was this article helpful?

Related Articles