COIN-OR::LEMON - Graph Library

Changeset 1267:a93f94dbe3d3 in lemon-0.x for src/lemon/array_map.h


Ignore:
Timestamp:
03/26/05 00:31:57 (19 years ago)
Author:
Balazs Dezso
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1694
Message:

First version of iterable maps.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/lemon/array_map.h

    r1164 r1267  
    1919
    2020#include <memory>
     21#include <lemon/map_iterator.h>
    2122
    2223///\ingroup graphmaps
     
    3637   *  the container functionality.
    3738   *
    38    *  The template parameter is the MapRegistry that the maps
     39   *  The template parameter is the AlterationNotifier that the maps
    3940   *  will belong to and the Value.
    4041   */
     
    4243  template <typename _Graph,
    4344            typename _Item,
    44             typename _ItemIt,
    4545            typename _Value>
    4646  class ArrayMap : public AlterationNotifier<_Item>::ObserverBase {
    4747
     48    typedef _Item Item;
    4849  public:
    4950               
     
    5556    typedef AlterationNotifier<_Item> Registry;
    5657
    57   private:
    58     /// The iterator to iterate on the keys.
    59     typedef _ItemIt KeyIt;
    60 
    6158    /// The MapBase of the Map which imlements the core regisitry function.
    6259    typedef typename Registry::ObserverBase Parent;
    6360               
    64    
    65   public:
    66 
    6761    /// The value type of the map.
    6862    typedef _Value Value;
    69     /// The reference type of the map;
    70     typedef Value& Reference;
    71     /// The pointer type of the map;
    72     typedef Value* Pointer;
    73 
    74     /// The const value type of the map.
    75     typedef const Value ConstValue;
    76     /// The const reference type of the map;
    77     typedef const Value& ConstReference;
    78     /// The pointer type of the map;
    79     typedef const Value* ConstPointer;
    8063
    8164
     
    8972     */
    9073    ArrayMap(const Graph& _g) : graph(&_g) {
     74      Item it;
     75      attach(_g.getNotifier(Item()));
     76      allocate_memory();
     77      for (graph->first(it); it != INVALID; graph->next(it)) {
     78        int id = graph->id(it);;
     79        allocator.construct(&(values[id]), Value());
     80      }                                                         
     81    }
     82
     83    /// Constructor to use default value to initialize the map.
     84
     85    /// It constrates a map and initialize all of the the map.
     86
     87    ArrayMap(const Graph& _g, const Value& _v) : graph(&_g) {
     88      Item it;
    9189      attach(_g.getNotifier(_Item()));
    9290      allocate_memory();
    93       for (KeyIt it(*graph); it != INVALID; ++it) {
    94         int id = graph->id(it);;
    95         allocator.construct(&(values[id]), Value());
    96       }                                                         
    97     }
    98 
    99     /// Constructor to use default value to initialize the map.
    100 
    101     /// It constrates a map and initialize all of the the map.
    102 
    103     ArrayMap(const Graph& _g, const Value& _v) : graph(&_g) {
    104       attach(_g.getNotifier(_Item()));
    105       allocate_memory();
    106       for (KeyIt it(*graph); it != INVALID; ++it) {
     91      for (graph->first(it); it != INVALID; graph->next(it)) {
    10792        int id = graph->id(it);;
    10893        allocator.construct(&(values[id]), _v);
     
    119104      if (capacity == 0) return;
    120105      values = allocator.allocate(capacity);
    121       for (KeyIt it(*graph); it != INVALID; ++it) {
     106      Item it;
     107      for (graph->first(it); it != INVALID; graph->next(it)) {
    122108        int id = graph->id(it);;
    123109        allocator.construct(&(values[id]), copy.values[id]);
     
    147133      }
    148134
    149       for (KeyIt it(*graph); it != INVALID; ++it) {
     135      Item it;
     136      for (graph->first(it); it != INVALID; graph->next(it)) {
    150137        int id = graph->id(it);;
    151138        allocator.construct(&(values[id]), copy.values[id]);
     
    169156     * actual keys of the graph.
    170157     */
    171     Reference operator[](const Key& key) {
     158    Value& operator[](const Key& key) {
    172159      int id = graph->id(key);
    173160      return values[id];
     
    178165     * actual keys of the graph.
    179166     */
    180     ConstReference operator[](const Key& key) const {
     167    const Value& operator[](const Key& key) const {
    181168      int id = graph->id(key);
    182169      return values[id];
     
    200187        }
    201188        Value* new_values = allocator.allocate(new_capacity);
    202         for (KeyIt it(*graph); it != INVALID; ++it) {
     189        Item it;
     190        for (graph->first(it); it != INVALID; graph->next(it)) {
    203191          int jd = graph->id(it);;
    204192          if (id != jd) {
     
    223211    void build() {
    224212      allocate_memory();
    225       for (KeyIt it(*graph); it != INVALID; ++it) {
     213      Item it;
     214      for (graph->first(it); it != INVALID; graph->next(it)) {
    226215        int id = graph->id(it);;
    227216        allocator.construct(&(values[id]), Value());
     
    231220    void clear() {     
    232221      if (capacity != 0) {
    233         for (KeyIt it(*graph); it != INVALID; ++it) {
     222        Item it;
     223        for (graph->first(it); it != INVALID; graph->next(it)) {
    234224          int id = graph->id(it);;
    235225          allocator.destroy(&(values[id]));
     
    314304    Allocator allocator;
    315305
    316   public:
    317 //     // STL  compatibility typedefs.
    318 //     typedef Iterator iterator;
    319 //     typedef ConstIterator const_iterator;
    320 //     typedef typename Iterator::PairValue value_type;
    321 //     typedef typename Iterator::Key key_type;
    322 //     typedef typename Iterator::Value data_type;
    323 //     typedef typename Iterator::PairReference reference;
    324 //     typedef typename Iterator::PairPointer pointer;
    325 //     typedef typename ConstIterator::PairReference const_reference;
    326 //     typedef typename ConstIterator::PairPointer const_pointer;
    327 //     typedef int difference_type;             
    328306  };           
    329307
     
    346324
    347325    template <typename _Value>
    348     class NodeMap : public ArrayMap<Graph, Node, NodeIt, _Value> {
     326    class NodeMap
     327      : public IterableMapExtender<ArrayMap<Graph, Node, _Value> > {
    349328    public:
    350329      typedef ArrayMappableGraphExtender<_Base> Graph;
     
    353332      typedef typename Graph::NodeIt NodeIt;
    354333
    355       typedef ArrayMap<Graph, Node, NodeIt, _Value> Parent;
     334      typedef IterableMapExtender<ArrayMap<Graph, Node, _Value> > Parent;
    356335
    357336      //typedef typename Parent::Graph Graph;
     
    366345
    367346    template <typename _Value>
    368     class EdgeMap : public ArrayMap<Graph, Edge, EdgeIt, _Value> {
     347    class EdgeMap
     348      : public IterableMapExtender<ArrayMap<Graph, Edge, _Value> > {
    369349    public:
    370350      typedef ArrayMappableGraphExtender<_Base> Graph;
     
    373353      typedef typename Graph::EdgeIt EdgeIt;
    374354
    375       typedef ArrayMap<Graph, Edge, EdgeIt, _Value> Parent;
     355      typedef IterableMapExtender<ArrayMap<Graph, Edge, _Value> > Parent;
    376356
    377357      //typedef typename Parent::Graph Graph;
Note: See TracChangeset for help on using the changeset viewer.