/usr/share/php/Structures/Graph.php is in php-pear 5.4.45-0+deb7u2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | <?php
/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */
// +-----------------------------------------------------------------------------+
// | Copyright (c) 2003 Sérgio Gonçalves Carvalho |
// +-----------------------------------------------------------------------------+
// | This file is part of Structures_Graph. |
// | |
// | Structures_Graph is free software; you can redistribute it and/or modify |
// | it under the terms of the GNU Lesser General Public License as published by |
// | the Free Software Foundation; either version 2.1 of the License, or |
// | (at your option) any later version. |
// | |
// | Structures_Graph is distributed in the hope that it will be useful, |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
// | GNU Lesser General Public License for more details. |
// | |
// | You should have received a copy of the GNU Lesser General Public License |
// | along with Structures_Graph; if not, write to the Free Software |
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
// | 02111-1307 USA |
// +-----------------------------------------------------------------------------+
// | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> |
// +-----------------------------------------------------------------------------+
//
/**
* The Graph.php file contains the definition of the Structures_Graph class
*
* @see Structures_Graph
* @package Structures_Graph
*/
/* dependencies {{{ */
/** PEAR base classes */
require_once 'PEAR.php';
/** Graph Node */
require_once 'Structures/Graph/Node.php';
/* }}} */
define('STRUCTURES_GRAPH_ERROR_GENERIC', 100);
/* class Structures_Graph {{{ */
/**
* The Structures_Graph class represents a graph data structure.
*
* A Graph is a data structure composed by a set of nodes, connected by arcs.
* Graphs may either be directed or undirected. In a directed graph, arcs are
* directional, and can be traveled only one way. In an undirected graph, arcs
* are bidirectional, and can be traveled both ways.
*
* @author Sérgio Carvalho <sergio.carvalho@portugalmail.com>
* @copyright (c) 2004 by Sérgio Carvalho
* @package Structures_Graph
*/
/* }}} */
class Structures_Graph {
/* fields {{{ */
/**
* @access private
*/
var $_nodes = array();
/**
* @access private
*/
var $_directed = false;
/* }}} */
/* Constructor {{{ */
/**
*
* Constructor
*
* @param boolean Set to true if the graph is directed. Set to false if it is not directed. (Optional, defaults to true)
* @access public
*/
function Structures_Graph($directed = true) {
$this->_directed = $directed;
}
/* }}} */
/* isDirected {{{ */
/**
*
* Return true if a graph is directed
*
* @return boolean true if the graph is directed
* @access public
*/
function isDirected() {
return (boolean) $this->_directed;
}
/* }}} */
/* addNode {{{ */
/**
*
* Add a Node to the Graph
*
* @param Structures_Graph_Node The node to be added.
* @access public
*/
function addNode(&$newNode) {
// We only add nodes
if (!is_a($newNode, 'Structures_Graph_Node')) return Pear::raiseError('Structures_Graph::addNode received an object that is not a Structures_Graph_Node', STRUCTURES_GRAPH_ERROR_GENERIC);
// Graphs are node *sets*, so duplicates are forbidden. We allow nodes that are exactly equal, but disallow equal references.
foreach($this->_nodes as $key => $node) {
/*
ZE1 equality operators choke on the recursive cycle introduced by the _graph field in the Node object.
So, we'll check references the hard way (change $this->_nodes[$key] and check if the change reflects in
$node)
*/
$savedData = $this->_nodes[$key];
$referenceIsEqualFlag = false;
$this->_nodes[$key] = true;
if ($node === true) {
$this->_nodes[$key] = false;
if ($node === false) $referenceIsEqualFlag = true;
}
$this->_nodes[$key] = $savedData;
if ($referenceIsEqualFlag) return Pear::raiseError('Structures_Graph::addNode received an object that is a duplicate for this dataset', STRUCTURES_GRAPH_ERROR_GENERIC);
}
$this->_nodes[] =& $newNode;
$newNode->setGraph($this);
}
/* }}} */
/* removeNode (unimplemented) {{{ */
/**
*
* Remove a Node from the Graph
*
* @todo This is unimplemented
* @param Structures_Graph_Node The node to be removed from the graph
* @access public
*/
function removeNode(&$node) {
}
/* }}} */
/* getNodes {{{ */
/**
*
* Return the node set, in no particular order. For ordered node sets, use a Graph Manipulator insted.
*
* @access public
* @see Structures_Graph_Manipulator_TopologicalSorter
* @return array The set of nodes in this graph
*/
function &getNodes() {
return $this->_nodes;
}
/* }}} */
}
?>
|