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
countElements (Graph graph [, int types]) yoix.graph
countElements (Graph graph [, String types])  
 
Returns an int giving a count of the number elements in graph. The argument types can be used to restrict the count 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.
 
 Example:   The following script loads a graph in XML format from a string and counts the number of elements in it.
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);

printf("There are a total of %d elements in graph '%s':\n",
       countElements(g), g.name);
printf("\t%d of these are nodes,\n", countElements(g, NODE));
printf("\t%d of these are edges and\n",
	countElements(g, "edgie-wedgies"));
printf("\t%d of these are graphs.\n", countElements(g, GRAPH));
The results on standard output are:
There are a total of 13 elements in graph 'g':
        5 of these are nodes,
        6 of these are edges and
        2 of these are graphs.
 
 Return:   int
 
 See Also:   Edge, Graph, listElements, Node, xmlGraph

 

Yoix is a registered trademark of AT&T Inc.