|
A
Node
is a type of
Element.
It becomes a component of a
Graph
by assigning that
Graph
value to the node's
parent
field.
Constants referred to here are contained in the
yoix.graph
dictionary.
The complete set of fields in a
Node
are:
| attribute([int flags], [Object name[, Object value]]) |
A
Builtin
that allows one to add, change, delete or retrieve any type of attribute.
The
flags
argument, when present, specifies the desired action, action scope and the
target attribute type.
The various values described below can be combined by bitwise-OR to specify the
flags
argument.
The default action is either retrieval or replacement, depending on
the context (see below).
The following actions can be indicated specifically:
CREATE,
DELETE,
or
REPLACE.
CREATE
is for creating new attributes, but otherwise generates a
badvalue
error when an existing attribute with the same name is accessible.
Using
REPLACE
avoids this check.
A
DELETE
action is ignored when the requested attribute does not already exist.
The default action scope is local, but can be specified as
SCOPED,
which means that any default attributes that are inherited will be
accessible along with the locally defined attributes.
Otherwise, only the locally defined attributes will be accessed.
By default, the target attributes type are the element's attributes, but
specific default attributes to access can be specified using
NODEDFLT,
EDGEDFLT,
or
GRAPHDFLT.
When working with the local scope, requesting any action (retrieval, creation,
deletion or replacement) and targeting element attributes, the attributes
defined as part of the current element are accessed (i.e., defaults do
not come into play at all).
When working with the local scope, requesting any action (retrieval, creation,
deletion or replacement) and targeting a default attribute
type (graph, node or edge), the default attributes
accessed depends on the current element.
For a node element,
the default attributes owned by its parent are accessed.
When scoping and retrieval are in effect and the element is targeted,
then first this element's own attributes are accessed, failing that the
default node attributes owned by the parent graph are accessed and so
on for its parent graph and up to the root graph, and failing all that the
global node attributes are accessed, if any.
When a specific default
type is specified, the search is the same as above except that this
element's own attributes are skipped and that the attribute type searched
is determined by the flags supplied instead of by the element's type.
When scoping and creation, deletion or replacement are in effect and
the element attributes are targeted, then the default node attributes
owned by the parent graph are accessed.
Finally, when a specific default
type is specified, the behavior is the same as above except that the
attribute type searched is determined by the flags supplied instead of
by the element's type.
When no
value
is supplied, only retrieval or deletion actions are allowed,
with retrieval being the default.
If a
name
is also absent, then the deletion action clears all targeted attributes.
A supplied
name
can be a
String,
Array
or
Dictionary.
When it is a
Dictionary,
it is treated as supplying names and values and specifically supplying a
value
argument in that case will cause an error.
When a
value
is supplied, either explicitly or through a
name
argument
Dictionary,
then the default action is replacement.
Return values are either the requested retrievals, the replaced values or
NULL,
as appropriate.
Multiple values are returned in an
Array.
| | attributes |
After initialization, this field is read-only.
It provides a
Dictionary
of the local attributes of this element and is
equivalent to using the above built-in with no arguments.
| | bfs([int depth], [Function func], [Object args, ...]) |
A
Builtin
for traversing graphs in a breadth-first search manner.
Only other node elements are visited starting from the current node element
with the connective relationship being determined by the edges between
the nodes.
If the graph is a directed graph, then to reach node A from node B, there
must be an edge directed from A to B existing.
The traversal can be restricted to a specified
depth
or distance out from the current node.
If
func
is supplied,
it is called each time an element is traversed and in the context of that
element.
If one or more
args
are supplied, they are used as arguments to
func.
The function need not return a value, but if it does return a non-zero value,
it will cause the traversal to stop at that element.
The defaults are to have no limit on depth and no function provided.
An array of visited elements is returned.
| | dfs([int depth], [Function func], [Object args, ...]) |
This
Builtin
is the same as the bfs built-in, described above, except that
the traversal of the graph is in the manner of a depth-first search.
| | flags |
An
int
representing the bitwise-ORing of the basic characteristics or
preferences of this node element.
Currently, no values are available for nodes.
| | name |
A
String
that is the current name of this element.
Assigning to this field changes the name of this element.
If
name
is currently assigned to another element within the
overall graph containing this element, a
nameclash
error results.
| | parent |
The
Graph
which is the parent graph of this element.
Assigning to this value adds or removes elements from a graph.
| | root |
A read-only field that is the root
Graph
for this element.
| | text([int format[, int mode[, int depth[, String prefix]]]]) |
A
Builtin
that returns a
String
representation of the current graph.
Current
format
values are either
XML,
which results in XML output (see http://www.w3c.org/), or
DOT,
which results in dot output (see http://www.research.att.com/sw/tools/graphviz/).
The default is XML output.
Setting
mode
determines how the graph is traversed and possible values are:
BFS,
for breadth-first search mode,
DFS,
for depth-first search mode, and
WALK,
for a natural walk of the graph.
The default is a natural walk.
See the walk built-in below for a description of a natural walk.
The
depth
argument limits traversal to the specified number of layers.
A negative value, which is the default, indicates no limit.
A
prefix
may be applied to each line of output to allow special marking or indentation
of all the text lines.
The default is to have no prefix.
| | walk([Function func], [Object args, ...]) |
This
Builtin
traverses the graph in the manner of a natural walk starting at the current
element.
For a node element, however, that simply means visiting the node itself.
If
func
is supplied,
it is called each time an element is traversed and in the context of that
element.
If one or more
args
are supplied, they are used as arguments to
func.
The function need not return a value, but if it does return a non-zero value,
it will cause the traversal to stop at that element.
An array of visited elements is returned.
|
Several permanent fields have not been documented and should not be
used in Yoix applications.
| |
| Example: |
The following code sample builds a graph and dumps its XML format and a
breadth-first search anchored at
node_1
to the standard output:
import yoix.graph.*;
import yoix.stdio.*;
String graph_str = "\
<graph name=g directed=1 strict=1 color=white label=Example>\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\
<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\
</graph>\n\
";
Graph g = xmlGraph(graph_str);
stdout.nextline = g.text();
prnt_name() {
stdout.nextline = name;
}
Node n = g.element("node_1");
n.bfs(prnt_name);
The result on standard output looks like:
<graph name=g directed=1 strict=1 color=white label=example>
<node_attributes color=blue />
<node name=node_0 color=red />
<node name=node_1 />
<node name=node_2 color=green />
<node name=node_3 />
<node name=node_4 color=orange />
<edge name=edge_3_0 tail=node_3 head=node_0 color=yellow />
<edge name=edge_0_2 tail=node_0 head=node_2 color=green />
<edge name=edge_2_0 tail=node_2 head=node_0 color=red />
<edge name=edge_1_2 tail=node_1 head=node_2 color=blue />
<edge name=edge_4_0 tail=node_4 head=node_0 color=red />
<edge name=edge_1_4 tail=node_1 head=node_4 color=blue />
</graph>
node_1
node_2
node_4
node_0
| | |
| See Also: |
countElements,
Edge,
Element,
Graph,
listElements,
xmlGraph
|
|