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

Public Member Functions

 __construct ()
 _connectTo (&$destinationNode)
 connectsTo (&$target)
 connectTo (&$destinationNode)
& getData ()
& getGraph ()
& getMetadata ($key, $nullIfNonexistent=false)
 getNeighbours ()
 inDegree ()
 metadataKeyExists ($key)
 outDegree ()
 setData (&$data)
 setGraph (&$graph)
 setMetadata ($key, &$data)
 unsetMetadata ($key)

Data Fields

 $_arcs = array()
 $_data = null
 $_graph = null
 $_metadata = array()

Detailed Description

Definition at line 57 of file Node.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( )

Constructor

@access public

Definition at line 78 of file Node.php.

78 {
79 }

Member Function Documentation

◆ _connectTo()

_connectTo ( & $destinationNode)

@access private

Definition at line 223 of file Node.php.

223 {
224 $this->_arcs[] =& $destinationNode;
225 }

Referenced by connectTo().

Here is the caller graph for this function:

◆ connectsTo()

connectsTo ( & $target)

Test wether this node has an arc to the target node

Returns
boolean True if the two nodes are connected @access public

Definition at line 274 of file Node.php.

274 {
275 if (version_compare(PHP_VERSION, '5.0.0') >= 0) {
276 return in_array($target, $this->getNeighbours(), true);
277 }
278
279 $copy = $target;
280 $arcKeys = array_keys($this->_arcs);
281 foreach($arcKeys as $key) {
282 /* ZE1 chokes on this expression:
283 if ($target === $arc) return true;
284 so, we'll use more convoluted stuff
285 */
286 $arc =& $this->_arcs[$key];
287 $target = true;
288 if ($arc === true) {
289 $target = false;
290 if ($arc === false) {
291 $target = $copy;
292 return true;
293 }
294 }
295 }
296 $target = $copy;
297 return false;
298 }

References getNeighbours().

Referenced by inDegree().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ connectTo()

connectTo ( & $destinationNode)

Connect this node to another one.

If the graph is not directed, the reverse arc, connecting $destinationNode to $this is also created.

Parameters
Structures_Graph_NodeNode to connect to @access public

Definition at line 238 of file Node.php.

238 {
239 // We only connect to nodes
240 if (!is_a($destinationNode, 'Structures_Graph_Node')) return Pear::raiseError('Structures_Graph_Node::connectTo received an object that is not a Structures_Graph_Node', STRUCTURES_GRAPH_ERROR_GENERIC);
241 // Nodes must already be in graphs to be connected
242 if ($this->_graph == null) return Pear::raiseError('Structures_Graph_Node::connectTo Tried to connect a node that is not in a graph', STRUCTURES_GRAPH_ERROR_GENERIC);
243 if ($destinationNode->getGraph() == null) return Pear::raiseError('Structures_Graph_Node::connectTo Tried to connect to a node that is not in a graph', STRUCTURES_GRAPH_ERROR_GENERIC);
244 // Connect here
245 $this->_connectTo($destinationNode);
246 // If graph is undirected, connect back
247 if (!$this->_graph->isDirected()) {
248 $destinationNode->_connectTo($this);
249 }
250 }
const STRUCTURES_GRAPH_ERROR_GENERIC
Definition Graph.php:37
_connectTo(&$destinationNode)
Definition Node.php:223

References _connectTo(), and STRUCTURES_GRAPH_ERROR_GENERIC.

Here is the call graph for this function:

◆ getData()

& getData ( )

Node data getter.

Each graph node can contain a reference to one variable. This is the getter for that reference.

Returns
mixed Data stored in node @access public

Definition at line 119 of file Node.php.

119 {
120 return $this->_data;
121 }

References $_data.

◆ getGraph()

& getGraph ( )

Node graph getter

Returns
Structures_Graph Graph where node is stored @access public

Definition at line 90 of file Node.php.

90 {
91 return $this->_graph;
92 }

References $_graph.

◆ getMetadata()

& getMetadata ( $key,
$nullIfNonexistent = false )

Node metadata getter

Each graph node can contain multiple 'metadata' entries, each stored under a different key, as in an associative array or in a dictionary. This method gets the data under the given key. If the key does not exist, an error will be thrown, so testing using metadataKeyExists might be needed.

Parameters
stringKey
booleannullIfNonexistent (defaults to false).
Returns
mixed Metadata Data stored in node under given key
See also
metadataKeyExists @access public

Definition at line 171 of file Node.php.

171 {
172 if (array_key_exists($key, $this->_metadata)) {
173 return $this->_metadata[$key];
174 } else {
175 if ($nullIfNonexistent) {
176 $a = null;
177 return $a;
178 } else {
179 $a = Pear::raiseError('Structures_Graph_Node::getMetadata: Requested key does not exist', STRUCTURES_GRAPH_ERROR_GENERIC);
180 return $a;
181 }
182 }
183 }

References STRUCTURES_GRAPH_ERROR_GENERIC.

◆ getNeighbours()

getNeighbours ( )

Return nodes connected to this one.

Returns
array Array of nodes @access public

Definition at line 261 of file Node.php.

261 {
262 return $this->_arcs;
263 }

References $_arcs.

Referenced by connectsTo().

Here is the caller graph for this function:

◆ inDegree()

inDegree ( )

Calculate the in degree of the node.

The indegree for a node is the number of arcs entering the node. For non directed graphs, the indegree is equal to the outdegree.

Returns
integer In degree of the node @access public

Definition at line 312 of file Node.php.

312 {
313 if ($this->_graph == null) return 0;
314 if (!$this->_graph->isDirected()) return $this->outDegree();
315 $result = 0;
316 $graphNodes =& $this->_graph->getNodes();
317 foreach (array_keys($graphNodes) as $key) {
318 if ($graphNodes[$key]->connectsTo($this)) $result++;
319 }
320 return $result;
321
322 }
$result
connectsTo(&$target)
Definition Node.php:274

References $result, connectsTo(), and outDegree().

Here is the call graph for this function:

◆ metadataKeyExists()

metadataKeyExists ( $key)

Test for existence of metadata under a given key.

Each graph node can contain multiple 'metadata' entries, each stored under a different key, as in an associative array or in a dictionary. This method tests whether a given metadata key exists for this node.

Parameters
stringKey to test
Returns
boolean
@access public

Definition at line 151 of file Node.php.

151 {
152 return array_key_exists($key, $this->_metadata);
153 }

◆ outDegree()

outDegree ( )

Calculate the out degree of the node.

The outdegree for a node is the number of arcs exiting the node. For non directed graphs, the outdegree is always equal to the indegree.

Returns
integer Out degree of the node @access public

Definition at line 336 of file Node.php.

336 {
337 if ($this->_graph == null) return 0;
338 return sizeof($this->_arcs);
339 }

References $_arcs.

Referenced by inDegree().

Here is the caller graph for this function:

◆ setData()

setData ( & $data)

Node data setter

Each graph node can contain a reference to one variable. This is the setter for that reference.

Returns
mixed Data to store in node @access public

Definition at line 134 of file Node.php.

134 {
135 $this->_data =& $data;
136 }

Referenced by PEAR_Downloader\sortPackagesForInstall().

Here is the caller graph for this function:

◆ setGraph()

setGraph ( & $graph)

Node graph setter. This method should not be called directly. Use Graph::addNode instead.

Parameters
Structures_GraphSet the graph for this node.
See also
Structures_Graph::addNode() @access public

Definition at line 104 of file Node.php.

104 {
105 $this->_graph =& $graph;
106 }

◆ setMetadata()

setMetadata ( $key,
& $data )

Node metadata setter

Each graph node can contain multiple 'metadata' entries, each stored under a different key, as in an associative array or in a dictionary. This method stores data under the given key. If the key already exists, previously stored data is discarded.

Parameters
stringKey
mixedData @access public

Definition at line 216 of file Node.php.

216 {
217 $this->_metadata[$key] =& $data;
218 }

◆ unsetMetadata()

unsetMetadata ( $key)

Delete metadata by key

Each graph node can contain multiple 'metadata' entries, each stored under a different key, as in an associative array or in a dictionary. This method removes any data that might be stored under the provided key. If the key does not exist, no error is thrown, so it is safe using this method without testing for key existence.

Parameters
stringKey @access public

Definition at line 198 of file Node.php.

198 {
199 if (array_key_exists($key, $this->_metadata)) unset($this->_metadata[$key]);
200 }

Field Documentation

◆ $_arcs

$_arcs = array()

@access private

Definition at line 66 of file Node.php.

Referenced by getNeighbours(), and outDegree().

◆ $_data

$_data = null

@access private

Definition at line 62 of file Node.php.

Referenced by getData().

◆ $_graph

$_graph = null

@access private

Definition at line 68 of file Node.php.

Referenced by getGraph().

◆ $_metadata

$_metadata = array()

@access private

Definition at line 64 of file Node.php.


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