AT&T Home | AT&T Labs | Research
AT&T Labs, Inc. - Research

The Yoix® Scripting Language

Home | What's New | Grammar | Documentation | Download | License | YChart | YDAT | YWAIT | Byzgraf | FAQs
listElements (Graph graph [, int types] [, Function func [, Object args, ...]]) yoix.graph
listElements (Graph graph [, String types] [, Function func [, Object args, ...]])  
 
Returns an Array of elements in graph based on the supplied arguments. The argument types can be used to restrict the listing to certain element types, which can be specified either as an int consisting of the bitwise-ORing of the constants EDGE, GRAPH or NODE or as a String containing the words edge, graph or node separated by any non-character delimiter. Note that only the first character of each word is examined and it is in a case-insensitive manner. If func is supplied, then it is executed in the context of each candidate element in graph and if it returns a non-zero value, that element is included in the listing, otherwise it is excluded. The remaining args, if any, are passed as arguments to func each time it is called.
 
 Example:   The following script loads a graph in XML format from a string and provides some counts of elements based on their color attribute.
import yoix.graph.*;
import yoix.stdio.*;

graph_str = "\
<graph name=g directed=1 strict=1 label=Example>\n\
    <graph_attributes color=white />\n\
    <node_attributes color=blue />\n\
    <node name=node_0 color=red />\n\
    <node name=node_1 />\n\
    <node name=node_2 color=green />\n\
    <node name=node_3 />\n\
    <node name=node_4 color=orange />\n\
    <edge name=edge_3_0 tail=node_3 head=node_0 color=yellow />\n\
    <edge name=edge_0_2 tail=node_0 head=node_2 color=green />\n\
    <edge name=edge_2_0 tail=node_2 head=node_0 color=red />\n\
    <edge name=edge_1_2 tail=node_1 head=node_2 color=blue />\n\
    <subgraph name=subg_0>\n\
        <edge name=edge_4_0 tail=node_4 head=node_0 color=red />\n\
        <edge name=edge_1_4 tail=node_1 head=node_4 color=blue />\n\
    </subgraph>\n\
</graph>\n\
";

g = xmlGraph(graph_str);

selector(String col) {
    String color = attribute(SCOPED, "color");
    return(color === col);
}

printf("There are a total of %d elements in graph '%s':\n",
       countElements(g), g.name);
printf("\t%d of these are colored %s,\n",
       listElements(g, selector, "red")@length, "red");
printf("\t%d of these are colored %s and\n",
       listElements(g, selector, "blue")@length, "blue");
printf("\t%d of these are colored %s.\n",
       listElements(g, selector, "green")@length, "green");
The results on standard output are:
There are a total of 13 elements in graph 'g':
        3 of these are colored red,
        4 of these are colored blue and
        2 of these are colored green.
 
 Return:   Array
 
 See Also:   countElements, Edge, Graph, Node, xmlGraph

 

Yoix is a registered trademark of AT&T Inc.