COIN-OR::LEMON - Graph Library

Ticket #68: 68-4-a3de05c56e7e.patch

File 68-4-a3de05c56e7e.patch, 3.0 KB (added by Peter Kovacs, 15 years ago)
  • lemon/static_graph.h

    # HG changeset patch
    # User Peter Kovacs <kpeter@inf.elte.hu>
    # Date 1251216059 -7200
    # Node ID a3de05c56e7e87f6c030016f32ba7ef664519f70
    # Parent  6cab2ab9d8e7df5a77ddbadbb4dabb920f9a913e
    Remove the outgoing arc list from StaticDigraph (#68)
    to save one int value for each arc.
    
    The list was used only by the basic iteration interface, i.e.
    the nextOut(Arc&) function, but it can be implemented easily
    and efficiently without the outgoing arc list, as well.
    
    diff --git a/lemon/static_graph.h b/lemon/static_graph.h
    a b  
    3434    StaticDigraphBase()
    3535      : built(false), node_num(0), arc_num(0),
    3636        node_first_out(NULL), node_first_in(NULL),
    37         arc_source(NULL), arc_target(NULL),
    38         arc_next_in(NULL), arc_next_out(NULL) {}
     37        arc_source(NULL), arc_target(NULL), arc_next_in(NULL) {}
    3938   
    4039    ~StaticDigraphBase() {
    4140      if (built) {
     
    4342        delete[] node_first_in;
    4443        delete[] arc_source;
    4544        delete[] arc_target;
    46         delete[] arc_next_out;
    4745        delete[] arc_next_in;
    4846      }
    4947    }
     
    8785      e.id = node_first_out[n.id] != node_first_out[n.id + 1] ?
    8886        node_first_out[n.id] : -1;
    8987    }
    90     void nextOut(Arc& e) const { e.id = arc_next_out[e.id]; }
     88    void nextOut(Arc& e) const {
     89      e.id = e.id + 1 != node_first_out[arc_source[e.id] + 1] ?
     90        e.id + 1 : -1;
     91    }
    9192
    9293    void firstIn(Arc& e, const Node& n) const { e.id = node_first_in[n.id]; }
    9394    void nextIn(Arc& e) const { e.id = arc_next_in[e.id]; }
     
    134135        delete[] node_first_in;
    135136        delete[] arc_source;
    136137        delete[] arc_target;
    137         delete[] arc_next_out;
    138138        delete[] arc_next_in;
    139139      }
    140140      built = false;
     
    157157
    158158      arc_source = new int[arc_num];
    159159      arc_target = new int[arc_num];
    160       arc_next_out = new int[arc_num];
    161160      arc_next_in = new int[arc_num];
    162161
    163162      int node_index = 0;
     
    187186            arc_target[arc_index] = target;
    188187            arc_next_in[arc_index] = node_first_in[target];
    189188            node_first_in[target] = arc_index;
    190             arc_next_out[arc_index] = arc_index + 1;
    191189            ++arc_index;
    192190          }
    193           arc_next_out[arc_index - 1] = -1;
    194191        } else {
    195192          node_first_out[source] = arc_index;
    196193        }
     
    220217    int *arc_source;
    221218    int *arc_target;
    222219    int *arc_next_in;
    223     int *arc_next_out;
    224220  };
    225221
    226222  typedef DigraphExtender<StaticDigraphBase> ExtendedStaticDigraphBase;
     
    232228  ///
    233229  /// \ref StaticDigraph is a highly efficient digraph implementation,
    234230  /// but it is fully static.
    235   /// It stores only two \c int values for each node and only four \c int
     231  /// It stores only two \c int values for each node and only three \c int
    236232  /// values for each arc. Moreover it provides faster item iteration than
    237233  /// \ref ListDigraph and \ref SmartDigraph, especially using \c OutArcIt
    238234  /// iterators, since its arcs are stored in an appropriate order.