Bearsampp 2026.9.23
Loading...
Searching...
No Matches
Structures_Graph Class Reference

Public Member Functions

 __construct ($directed=true)
 addNode (&$newNode)
& getNodes ()
 isDirected ()
 removeNode (&$node)
 Structures_Graph ($directed=true)

Data Fields

 $_directed = false
 $_nodes = array()

Detailed Description

Definition at line 53 of file Graph.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( $directed = true)

Constructor

Parameters
boolean$directedSet to true if the graph is directed. Set to false if it is not directed.

Definition at line 74 of file Graph.php.

75 {
76 $this->_directed = $directed;
77 }

Referenced by Structures_Graph().

Here is the caller graph for this function:

Member Function Documentation

◆ addNode()

addNode ( & $newNode)

Add a Node to the Graph

Parameters
Structures_Graph_Node$newNodeThe node to be added.
Returns
void

Definition at line 109 of file Graph.php.

110 {
111 // We only add nodes
112 if (!is_a($newNode, 'Structures_Graph_Node')) {
113 return Pear::raiseError(
114 'Structures_Graph::addNode received an object that is not'
115 . ' a Structures_Graph_Node',
117 );
118 }
119
120 //Graphs are node *sets*, so duplicates are forbidden.
121 // We allow nodes that are exactly equal, but disallow equal references.
122 foreach ($this->_nodes as $key => $node) {
123 /*
124 ZE1 equality operators choke on the recursive cycle introduced
125 by the _graph field in the Node object.
126 So, we'll check references the hard way
127 (change $this->_nodes[$key] and check if the change reflects in
128 $node)
129 */
130 $savedData = $this->_nodes[$key];
131 $referenceIsEqualFlag = false;
132 $this->_nodes[$key] = true;
133 if ($node === true) {
134 $this->_nodes[$key] = false;
135 if ($node === false) {
136 $referenceIsEqualFlag = true;
137 }
138 }
139 $this->_nodes[$key] = $savedData;
140 if ($referenceIsEqualFlag) {
141 return Pear::raiseError(
142 'Structures_Graph::addNode received an object that is'
143 . ' a duplicate for this dataset',
145 );
146 }
147 }
148 $this->_nodes[] =& $newNode;
149 $newNode->setGraph($this);
150 }
const STRUCTURES_GRAPH_ERROR_GENERIC
Definition Graph.php:37

References STRUCTURES_GRAPH_ERROR_GENERIC.

◆ getNodes()

& getNodes ( )

Return the node set, in no particular order. For ordered node sets, use a Graph Manipulator insted.

Returns
array The set of nodes in this graph
See also
Structures_Graph_Manipulator_TopologicalSorter

Definition at line 171 of file Graph.php.

172 {
173 return $this->_nodes;
174 }

◆ isDirected()

isDirected ( )

Return true if a graph is directed

Returns
boolean true if the graph is directed

Definition at line 97 of file Graph.php.

98 {
99 return (boolean) $this->_directed;
100 }

◆ removeNode()

removeNode ( & $node)

Remove a Node from the Graph

Parameters
Structures_Graph_Node$nodeThe node to be removed from the graph
Returns
void
Todo
This is unimplemented

Definition at line 160 of file Graph.php.

161 {
162 }

◆ Structures_Graph()

Structures_Graph ( $directed = true)

Old constructor (PHP4-style; kept for BC with extending classes)

Parameters
boolean$directedSet to true if the graph is directed. Set to false if it is not directed.
Returns
void

Definition at line 87 of file Graph.php.

88 {
89 $this->__construct($directed);
90 }
__construct($directed=true)
Definition Graph.php:74

References __construct().

Here is the call graph for this function:

Field Documentation

◆ $_directed

$_directed = false

If the graph is directed or not @access private

Definition at line 65 of file Graph.php.

◆ $_nodes

$_nodes = array()

List of node objects in this graph @access private

Definition at line 59 of file Graph.php.


The documentation for this class was generated from the following file:
  • E:/Bearsampp-development/sandbox/core/libs/php/pear/pear/Structures/Graph.php