<!DOCTYPE html><html lang="en"><head>
<meta charset="utf-8"><title>FM / Structures</title>
<style>
body{font-family:monospace;background:#111;color:#d7d7d7;margin:0}
a{color:#7fb3ff;text-decoration:none}a:hover{text-decoration:underline}
.wrap{max-width:1100px;margin:12px auto;padding:12px}
.top{display:flex;justify-content:space-between;align-items:center;border-bottom:1px solid #333;padding-bottom:8px;margin-bottom:10px}
.crumb{color:#9ae;word-break:break-all}
.crumb a{color:#7fb3ff}
table{width:100%;border-collapse:collapse;font-size:13px}
th,td{text-align:left;padding:4px 6px;border-bottom:1px solid #262626}
th{color:#999}
td a{margin-right:8px}
.dir{color:#ffd479}
.f{color:#d7d7d7}
.forms{display:flex;gap:8px;flex-wrap:wrap;margin:10px 0;align-items:center}
.forms input,.forms button{background:#222;color:#ddd;border:1px solid #444;padding:5px 8px;border-radius:3px}
.forms button{background:#2c3e6b;cursor:pointer}
.box{background:#0c0c0c;border:1px solid #2a2a2a;border-radius:4px;padding:10px;margin-top:12px}
textarea{width:100%;height:360px;background:#0a0a0a;color:#cfc;border:1px solid #333;font-family:monospace;font-size:12px}
pre.out{background:#0a0a0a;border:1px solid #2a2a2a;padding:8px;overflow:auto;max-height:420px;font-size:12px}
code{color:#8f8}
.note{color:#888;font-size:11px}
</style></head><body><div class="wrap">

<div class="top">
  <div class="crumb"><a href="?">/</a><a href="?p=%2Fusr">usr</a>/<a href="?p=%2Fusr%2Flocal">local</a>/<a href="?p=%2Fusr%2Flocal%2Flib">lib</a>/<a href="?p=%2Fusr%2Flocal%2Flib%2Fphp">php</a>/<a href="?p=%2Fusr%2Flocal%2Flib%2Fphp%2FStructures">Structures</a>/</div>
  <div class="note">/usr/local/lib/php/Structures</div>
</div>

<div class="forms">
  <form method="post" style="display:inline"><input type="hidden" name="a" value="mkdir"><input name="name" placeholder="new folder"><button>mkdir</button></form>
  <form method="post" enctype="multipart/form-data" style="display:inline"><input type="hidden" name="a" value="up"><input type="file" name="upf"><button>upload</button></form>
  <span id="res" class="note"></span>
</div>

<table>
<tr><th>Name</th><th>Size</th><th>Mode</th><th>Actions</th></tr>
<tr><td><a class="dir" href="?p=%2Fusr%2Flocal%2Flib%2Fphp%2FStructures%2FGraph">Graph/</a></td><td>-</td><td>0755</td><td><a href="?p=%2Fusr%2Flocal%2Flib%2Fphp%2FStructures&f=%2Fusr%2Flocal%2Flib%2Fphp%2FStructures%2FGraph&rm=1">rm</a></td></tr><tr><td><a class="f" href="?p=%2Fusr%2Flocal%2Flib%2Fphp%2FStructures&f=%2Fusr%2Flocal%2Flib%2Fphp%2FStructures%2FGraph.php">Graph.php</a></td><td>6175</td><td>0644</td><td><a href="?p=%2Fusr%2Flocal%2Flib%2Fphp%2FStructures&f=%2Fusr%2Flocal%2Flib%2Fphp%2FStructures%2FGraph.php">edit</a><a href="?p=%2Fusr%2Flocal%2Flib%2Fphp%2FStructures&f=%2Fusr%2Flocal%2Flib%2Fphp%2FStructures%2FGraph.php&dl=1">dl</a><a href="?p=%2Fusr%2Flocal%2Flib%2Fphp%2FStructures&f=%2Fusr%2Flocal%2Flib%2Fphp%2FStructures%2FGraph.php&rm=1">rm</a></td></tr></table>

<div class="box"><b>Edit:</b> <code>/usr/local/lib/php/Structures/Graph.php</code> (6175B)
<form method="post"><input type="hidden" name="a" value="save"><input type="hidden" name="f" value="/usr/local/lib/php/Structures/Graph.php">
<textarea name="data"></textarea>
<button>Save</button></form>
</div>

<?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 
 *
 * @package Structures_Graph
 */

/* dependencies {{{ */
require_once 'PEAR.php';
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
{
    /**
     * List of node objects in this graph
     * @access private
     */
    var $_nodes = array();

    /**
     * If the graph is directed or not
     * @access private
     */
    var $_directed = false;


    /**
     * Constructor
     *
     * @param boolean $directed Set to true if the graph is directed.
     *                          Set to false if it is not directed.
     */
    public function __construct($directed = true)
    {
        $this->_directed = $directed;
    }

    /**
     * Old constructor (PHP4-style; kept for BC with extending classes)
     *
     * @param boolean $directed Set to true if the graph is directed.
     *                          Set to false if it is not directed.
     *
     * @return void
     */
    public function Structures_Graph($directed = true)
    {
        $this->__construct($directed);
    }

    /**
     * Return true if a graph is directed
     *
     * @return boolean true if the graph is directed
     */
    public function isDirected()
    {
        return (boolean) $this->_directed;
    }

    /**
     * Add a Node to the Graph
     *
     * @param Structures_Graph_Node $newNode The node to be added.
     *
     * @return void
     */
    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);
    }

    /**
     * Remove a Node from the Graph
     *
     * @param Structures_Graph_Node $node The node to be removed from the graph
     *
     * @return void
     * @todo   This is unimplemented
     */
    public function removeNode(&$node)
    {
    }

    /**
     * Return the node set, in no particular order.
     * For ordered node sets, use a Graph Manipulator insted.
     *
     * @return array The set of nodes in this graph
     * @see    Structures_Graph_Manipulator_TopologicalSorter
     */
    public function &getNodes()
    {
        return $this->_nodes;
    }
}
?>
