Permalink
Browse files

Fixes for bugs:

 #2536 Bug in Structures_graph::addNode
 #2545 Changes in error reporting


git-svn-id: http://svn.php.net/repository/pear/packages/Structures_Graph/trunk@202473 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
1 parent d6bb025 commit e82d3d9fcd8a6348992aa188226a3ad5f29a9dfe Sergio Carvalho committed Dec 9, 2005
View
@@ -101,25 +101,23 @@ function isDirected() {
*/
function addNode(&$newNode) {
// We only add nodes
- if (!is_a($newNode, 'Structures_Graph_Node'))
- Pear::raiseError('Structures_Graph::addNode received an object that is not a Structures_Graph_Node', STRUCTURES_GRAPH_ERROR_GENERIC);
+ 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
+ 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;
+ if ($node === false) $referenceIsEqualFlag = true;
}
$this->_nodes[$key] = $savedData;
- if ($referenceIsEqualFlag)
- Pear::raiseError('Structures_Graph::addNode received an object that is a duplicate for this dataset', STRUCTURES_GRAPH_ERROR_GENERIC);
+ 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);
@@ -125,8 +125,7 @@ function _isAcyclic(&$graph) {
*/
function isAcyclic(&$graph) {
// We only test graphs
- if (!is_a($graph, 'Structures_Graph'))
- Pear::raiseError('Structures_Graph_Manipulator_AcyclicTest::isAcyclic received an object that is not a Structures_Graph', STRUCTURES_GRAPH_ERROR_GENERIC);
+ if (!is_a($graph, 'Structures_Graph')) return Pear::raiseError('Structures_Graph_Manipulator_AcyclicTest::isAcyclic received an object that is not a Structures_Graph', STRUCTURES_GRAPH_ERROR_GENERIC);
if (!$graph->isDirected()) return false; // Only directed graphs may be acyclic
return Structures_Graph_Manipulator_AcyclicTest::_isAcyclic($graph);
@@ -132,10 +132,8 @@ function _sort(&$graph) {
*/
function sort(&$graph) {
// We only sort graphs
- if (!is_a($graph, 'Structures_Graph'))
- Pear::raiseError('Structures_Graph_Manipulator_TopologicalSorter::sort received an object that is not a Structures_Graph', STRUCTURES_GRAPH_ERROR_GENERIC);
- if (!Structures_Graph_Manipulator_AcyclicTest::isAcyclic($graph))
- Pear::raiseError('Structures_Graph_Manipulator_TopologicalSorter::sort received an graph that has cycles', STRUCTURES_GRAPH_ERROR_GENERIC);
+ if (!is_a($graph, 'Structures_Graph')) return Pear::raiseError('Structures_Graph_Manipulator_TopologicalSorter::sort received an object that is not a Structures_Graph', STRUCTURES_GRAPH_ERROR_GENERIC);
+ if (!Structures_Graph_Manipulator_AcyclicTest::isAcyclic($graph)) return Pear::raiseError('Structures_Graph_Manipulator_TopologicalSorter::sort received an graph that has cycles', STRUCTURES_GRAPH_ERROR_GENERIC);
Structures_Graph_Manipulator_TopologicalSorter::_sort($graph);
$result = array();
@@ -175,7 +175,7 @@ function &getMetadata($key, $nullIfNonexistent = false) {
if ($nullIfNonexistent) {
return null;
} else {
- Pear::raiseError('Structures_Graph_Node::getMetadata: Requested key does not exist', STRUCTURES_GRAPH_ERROR_GENERIC);
+ return Pear::raiseError('Structures_Graph_Node::getMetadata: Requested key does not exist', STRUCTURES_GRAPH_ERROR_GENERIC);
}
}
}
@@ -235,13 +235,10 @@ function _connectTo(&$destinationNode) {
*/
function connectTo(&$destinationNode) {
// We only connect to nodes
- if (!is_a($destinationNode, 'Structures_Graph_Node'))
- Pear::raiseError('Structures_Graph_Node::connectTo received an object that is not a Structures_Graph_Node', STRUCTURES_GRAPH_ERROR_GENERIC);
+ 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);
// Nodes must already be in graphs to be connected
- if ($this->_graph == null)
- Pear::raiseError('Structures_Graph_Node::connectTo Tried to connect a node that is not in a graph', STRUCTURES_GRAPH_ERROR_GENERIC);
- if ($destinationNode->getGraph() == null)
- Pear::raiseError('Structures_Graph_Node::connectTo Tried to connect to a node that is not in a graph', STRUCTURES_GRAPH_ERROR_GENERIC);
+ 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);
+ 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);
// Connect here
$this->_connectTo($destinationNode);
// If graph is undirected, connect back
View
@@ -35,7 +35,7 @@ FILESGOHERE
</filelist>
</release>
<deps>
- <dep type="pkg" rel="ge" version="1.2">Pear</dep>
+ <dep type="pkg" rel="ge" version="1.2">PEAR</dep>
</deps>
</package>
EOF

0 comments on commit e82d3d9

Please sign in to comment.