# HG changeset patch # User deba # Date 1095105913 0 # Node ID 9bf990cb066d38ef04ff19ce3c5872744ff76918 # Parent d56fad02dc557297dc08dd79d9f36bfe16e31281 Bug fix in the symmetric maps. Faster map initialization. Iterators and Containers STL compatible. diff -r d56fad02dc55 -r 9bf990cb066d src/hugo/Makefile.am --- a/src/hugo/Makefile.am Mon Sep 13 18:00:26 2004 +0000 +++ b/src/hugo/Makefile.am Mon Sep 13 20:05:13 2004 +0000 @@ -17,6 +17,7 @@ map_defines.h \ map_iterator.h \ map_registry.h \ + map_bits.h \ maps.h \ mincostflows.h \ minlengthpaths.h \ diff -r d56fad02dc55 -r 9bf990cb066d src/hugo/array_map.h --- a/src/hugo/array_map.h Mon Sep 13 18:00:26 2004 +0000 +++ b/src/hugo/array_map.h Mon Sep 13 20:05:13 2004 +0000 @@ -5,6 +5,7 @@ #include #include +#include ///\ingroup graphmaps ///\file @@ -71,7 +72,7 @@ ArrayMap(const Graph& g, MapRegistry& r) : MapBase(g, r) { allocate_memory(); for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) { - int id = MapBase::getGraph()->id(it); + int id = KeyInfo::id(*MapBase::getGraph(), it); allocator.construct(&(values[id]), Value()); } } @@ -82,7 +83,7 @@ : MapBase(g, r) { allocate_memory(); for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) { - int id = MapBase::getGraph()->id(it); + int id = KeyInfo::id(*MapBase::getGraph(), it); allocator.construct(&(values[id]), v); } } @@ -94,7 +95,7 @@ if (capacity == 0) return; values = allocator.allocate(capacity); for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) { - int id = MapBase::getGraph()->id(it); + int id = KeyInfo::id(*MapBase::getGraph(), it); allocator.construct(&(values[id]), copy.values[id]); } } @@ -123,7 +124,7 @@ if (capacity == 0) return *this; values = allocator.allocate(capacity); for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) { - int id = MapBase::getGraph()->id(it); + int id = KeyInfo::id(*MapBase::getGraph(), it); allocator.construct(&(values[id]), copy.values[id]); } return *this; @@ -132,9 +133,10 @@ /** Assign operator to copy a map an other map type. */ template ArrayMap& operator=(const CMap& copy) { - if (MapBase::getGraph()) { + if (capacity != 0) { MapBase::destroy(); - } + allocator.deallocate(values, capacity); + } MapBase::operator=(copy); if (MapBase::getGraph()) { allocate_memory(); @@ -160,7 +162,7 @@ * actual keys of the graph. */ ReferenceType operator[](const KeyType& key) { - int id = MapBase::getGraph()->id(key); + int id = KeyInfo::id(*MapBase::getGraph(), key); return values[id]; } @@ -169,7 +171,7 @@ * actual keys of the graph. */ ConstReferenceType operator[](const KeyType& key) const { - int id = MapBase::getGraph()->id(key); + int id = KeyInfo::id(*MapBase::getGraph(), key); return values[id]; } @@ -177,14 +179,14 @@ * This is a compatibility feature with the not dereferable maps. */ void set(const KeyType& key, const ValueType& val) { - int id = MapBase::getGraph()->id(key); + int id = KeyInfo::id(*MapBase::getGraph(), key); values[id] = val; } /** Add a new key to the map. It called by the map registry. */ void add(const KeyType& key) { - int id = MapBase::getGraph()->id(key); + int id = KeyInfo::id(*MapBase::getGraph(), key); if (id >= capacity) { int new_capacity = (capacity == 0 ? 1 : capacity); while (new_capacity <= id) { @@ -192,7 +194,7 @@ } Value* new_values = allocator.allocate(new_capacity);; for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) { - int jd = MapBase::getGraph()->id(it); + int jd = KeyInfo::id(*MapBase::getGraph(), it); if (id != jd) { allocator.construct(&(new_values[jd]), values[jd]); allocator.destroy(&(values[jd])); @@ -208,7 +210,7 @@ /** Erase a key from the map. It called by the map registry. */ void erase(const KeyType& key) { - int id = MapBase::getGraph()->id(key); + int id = KeyInfo::id(*MapBase::getGraph(), key); allocator.destroy(&(values[id])); } @@ -278,13 +280,7 @@ private: void allocate_memory() { - int max_id = -1; - for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) { - int id = MapBase::getGraph()->id(it); - if (id > max_id) { - max_id = id; - } - } + int max_id = KeyInfo::maxId(*MapBase::getGraph()); if (max_id == -1) { capacity = 0; values = 0; @@ -300,6 +296,19 @@ int capacity; Value* values; Allocator allocator; + + public: + // STL compatibility typedefs. + typedef Iterator iterator; + typedef ConstIterator const_iterator; + typedef typename Iterator::PairValueType value_type; + typedef typename Iterator::KeyType key_type; + typedef typename Iterator::ValueType data_type; + typedef typename Iterator::PairReferenceType reference; + typedef typename Iterator::PairPointerType pointer; + typedef typename ConstIterator::PairReferenceType const_reference; + typedef typename ConstIterator::PairPointerType const_pointer; + typedef int difference_type; }; /// @} diff -r d56fad02dc55 -r 9bf990cb066d src/hugo/graph_wrapper.h --- a/src/hugo/graph_wrapper.h Mon Sep 13 18:00:26 2004 +0000 +++ b/src/hugo/graph_wrapper.h Mon Sep 13 20:05:13 2004 +0000 @@ -1388,7 +1388,7 @@ void erase(const Edge& e) const { Node n=tail(e); - typename Graph::OutEdgeIt f(*graph, n); + typename Graph::OutEdgeIt f(*Parent::graph, n); ++f; first_out_edges->set(n, f); } diff -r d56fad02dc55 -r 9bf990cb066d src/hugo/list_graph.h --- a/src/hugo/list_graph.h Mon Sep 13 18:00:26 2004 +0000 +++ b/src/hugo/list_graph.h Mon Sep 13 20:05:13 2004 +0000 @@ -1114,7 +1114,10 @@ OutEdgeIt(const EdgeSet& _G,const Node v) : Edge(_G.nodes[v].first_out), G(&_G) { } - OutEdgeIt &operator++() { n = G->edges[n].next_out; return *this; } + OutEdgeIt &operator++() { + Edge::n = G->edges[Edge::n].next_out; + return *this; + } }; class InEdgeIt : public Edge { @@ -1126,7 +1129,10 @@ InEdgeIt(const EdgeSet& _G, Edge e) : Edge(e), G(&_G) { } InEdgeIt(const EdgeSet& _G,Node v) : Edge(_G.nodes[v].first_in), G(&_G) { } - InEdgeIt &operator++() { n=G->edges[n].next_in; return *this; } + InEdgeIt &operator++() { + Edge::n = G->edges[Edge::n].next_in; + return *this; + } }; }; diff -r d56fad02dc55 -r 9bf990cb066d src/hugo/map_bits.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/hugo/map_bits.h Mon Sep 13 20:05:13 2004 +0000 @@ -0,0 +1,52 @@ +// -*- c++ -*- +#ifndef MAP_BITS_H +#define MAP_BITS_H + +///\ingroup graphmaps +///\file +///\brief Some utils to help implement maps. + +namespace hugo { + + + /// \addtogroup graphmaps + /// @{ + + /// Helper class to get information about the key type. + template + struct KeyInfo {}; + + template + struct KeyInfo { + static int maxId(const Graph& graph) { + return graph.maxNodeId(); + } + static int id(const Graph& graph, const typename Graph::Node& node) { + return graph.id(node); + } + }; + + template + struct KeyInfo { + static int maxId(const Graph& graph) { + return graph.maxEdgeId(); + } + static int id(const Graph& graph, const typename Graph::Edge& edge) { + return graph.id(edge); + } + }; + + template + struct KeyInfo { + static int maxId(const Graph& graph) { + return graph.maxEdgeId() >> 1; + } + static int id(const Graph& graph, const typename Graph::Edge& edge) { + return graph.id(edge) >> 1; + } + }; + + /// @} +} + +#endif diff -r d56fad02dc55 -r 9bf990cb066d src/hugo/map_defines.h --- a/src/hugo/map_defines.h Mon Sep 13 18:00:26 2004 +0000 +++ b/src/hugo/map_defines.h Mon Sep 13 20:05:13 2004 +0000 @@ -96,7 +96,7 @@ #define CREATE_SYM_EDGE_MAP_REGISTRY \ typedef SymEdgeIt SymEdgeIt; \ typedef MapRegistry SymEdgeMapRegistry; \ -mutable EdgeMapRegistry sym_edge_maps; +mutable SymEdgeMapRegistry sym_edge_maps; /** Creates a map from a template map. The import method is diff -r d56fad02dc55 -r 9bf990cb066d src/hugo/map_iterator.h --- a/src/hugo/map_iterator.h Mon Sep 13 18:00:26 2004 +0000 +++ b/src/hugo/map_iterator.h Mon Sep 13 20:05:13 2004 +0000 @@ -2,6 +2,8 @@ #ifndef MAP_ITERATOR_H #define MAP_ITERATOR_H +#include + #include ///\ingroup graphmaps @@ -22,6 +24,7 @@ class MapIteratorBase { public: + /// The key type of the iterator. typedef typename Map::KeyType KeyType; /// The iterator to iterate on the keys. @@ -79,8 +82,12 @@ friend class MapConstIterator; + public: + /// The iterator base class. + typedef MapIteratorBase Base; + /// The key type of the iterator. typedef typename Map::KeyType KeyType; /// The iterator to iterate on the keys. @@ -102,6 +109,10 @@ public: + /// The value type of the iterator. + typedef extended_pair PairValueType; + /// The reference type of the iterator. typedef extended_pair PairReferenceType; @@ -111,12 +122,11 @@ /// Constructor to initalize the iterators returned /// by the begin() and end(). - MapIterator(Map& pmap, const KeyIt& pit) - : MapIteratorBase(pit), map(&pmap) {} + MapIterator(Map& pmap, const KeyIt& pit) : Base(pit), map(&pmap) {} /// Dereference operator for the iterator. PairReferenceType operator*() { - return PairReferenceType(it, (*map)[it]); + return PairReferenceType(Base::it, (*map)[Base::it]); } /// The pointer type of the iterator. @@ -132,24 +142,32 @@ /// Arrow operator for the iterator. PairPointerType operator->() { - return PairPointerType(it, ((*map)[it])); + return PairPointerType(Base::it, ((*map)[Base::it])); } /// The pre increment operator of the iterator. MapIterator& operator++() { - increment(); + Base::increment(); return *this; } /// The post increment operator of the iterator. MapIterator operator++(int) { - MapIterator tmp(it); - increment(); + MapIterator tmp(*this); + Base::increment(); return tmp; } private: Map* map; + + public: + // STL compatibility typedefs. + typedef std::forward_iterator_tag iterator_category; + typedef int difference_type; + typedef PairValueType value_type; + typedef PairReferenceType reference; + typedef PairPointerType pointer; }; /** Compatible iterator with the stl maps' iterators. @@ -160,6 +178,9 @@ public: + /// The iterator base class. + typedef MapIteratorBase Base; + /// The key type of the iterator. typedef typename Map::KeyType KeyType; /// The iterator to iterate on the keys. @@ -187,21 +208,25 @@ /// Constructor to initalize the the iterators returned /// by the begin() and end(). MapConstIterator(const Map& pmap, const KeyIt& pit) - : MapIteratorBase(pit), map(&pmap) {} + : Base(pit), map(&pmap) {} /// Constructor to create const iterator from a non const. MapConstIterator(const MapIterator& pit) { - it = pit.it; + Base::it = pit.Base::it; map = pit.map; } + /// The value type of the iterator. + typedef extended_pair PairValueType; + /// The reference type of map. typedef extended_pair PairReferenceType; /// Dereference operator for the iterator. PairReferenceType operator*() { - return PairReferenceType(it, (*map)[it]); + return PairReferenceType(Base::it, (*map)[Base::it]); } /// The pointer type of the iterator. @@ -217,24 +242,32 @@ /// Arrow operator for the iterator. PairPointerType operator->() { - return PairPointerType(it, ((*map)[it])); + return PairPointerType(Base::it, (*map)[Base::it]); } /// The pre increment operator of the iterator. MapConstIterator& operator++() { - increment(); + Base::increment(); return *this; } /// The post increment operator of the iterator. MapConstIterator operator++(int) { - MapConstIterator tmp(it); - increment(); + MapConstIterator tmp(*this); + Base::increment(); return tmp; } private: const Map* map; + + public: + // STL compatibility typedefs. + typedef std::input_iterator_tag iterator_category; + typedef int difference_type; + typedef PairValueType value_type; + typedef PairReferenceType reference; + typedef PairPointerType pointer; }; /** The class makes the KeyIt to an stl compatible iterator @@ -245,6 +278,9 @@ public: + /// The iterator base class. + typedef MapIteratorBase Base; + /// The key type of the iterator. typedef typename Map::KeyType KeyType; /// The iterator to iterate on the keys. @@ -256,29 +292,40 @@ MapKeyIterator() {} /// KeyIt initialized iterator. - MapKeyIterator(const KeyIt& pit) : MapIteratorBase(pit) {} + MapKeyIterator(const KeyIt& pit) : Base(pit) {} /// The pre increment operator of the iterator. MapKeyIterator& operator++() { - increment(); + Base::increment(); return *this; } /// The post increment operator of the iterator. MapKeyIterator operator++(int) { MapKeyIterator tmp(*this); - increment(); + Base::increment(); return tmp; } /// The dereferencing operator of the iterator. KeyType operator*() const { - return static_cast(it); + return static_cast(Base::it); } + + public: + // STL compatibility typedefs. + typedef std::input_iterator_tag iterator_category; + typedef int difference_type; + typedef KeyType value_type; + typedef const KeyType& reference; + typedef const KeyType* pointer; }; template class MapConstValueIterator; + /** MapValueIterator creates an stl compatible iterator + * for the values. + */ template class MapValueIterator : public MapIteratorBase { @@ -286,6 +333,9 @@ public: + /// The iterator base class. + typedef MapIteratorBase Base; + /// The key type of the iterator. typedef typename Map::KeyType KeyType; /// The iterator to iterate on the keys. @@ -317,25 +367,25 @@ /// Map and KeyIt initialized iterator. MapValueIterator(Map& pmap, const KeyIt& pit) - : MapIteratorBase(pit), map(&pmap) {} + : Base(pit), map(&pmap) {} /// The pre increment operator of the iterator. MapValueIterator& operator++() { - increment(); + Base::increment(); return *this; } /// The post increment operator of the iterator. MapValueIterator operator++(int) { MapValueIterator tmp(*this); - increment(); + Base::increment(); return tmp; } /// The dereferencing operator of the iterator. ReferenceType operator*() const { - return (*map)[it]; + return (*map)[Base::it]; } /// The arrow operator of the iterator. @@ -343,20 +393,32 @@ return &(operator*()); } + public: + // STL compatibility typedefs. + typedef std::forward_iterator_tag iterator_category; + typedef int difference_type; + typedef ValueType value_type; + typedef ReferenceType reference; + typedef PointerType pointer; }; + /** MapValueIterator creates an stl compatible iterator + * for the const values. + */ template class MapConstValueIterator : public MapIteratorBase { public: + /// The iterator base class. + typedef MapIteratorBase Base; + /// The key type of the iterator. typedef typename Map::KeyType KeyType; /// The iterator to iterate on the keys. typedef typename Map::KeyIt KeyIt; - /// The value type of the iterator. typedef typename Map::ValueType ValueType; /// The reference type of the iterator. @@ -382,30 +444,30 @@ /// Constructor to create const iterator from a non const. MapConstValueIterator(const MapValueIterator& pit) { - it = pit.it; + Base::it = pit.Base::it; map = pit.map; } /// Map and KeyIt initialized iterator. MapConstValueIterator(const Map& pmap, const KeyIt& pit) - : MapIteratorBase(pit), map(&pmap) {} + : Base(pit), map(&pmap) {} /// The pre increment operator of the iterator. MapConstValueIterator& operator++() { - increment(); + Base::increment(); return *this; } /// The post increment operator of the iterator. MapConstValueIterator operator++(int) { MapConstValueIterator tmp(*this); - increment(); + Base::increment(); return tmp; } /// The dereferencing operator of the iterator. ConstReferenceType operator*() const { - return (*map)[it]; + return (*map)[Base::it]; } /// The arrow operator of the iterator. @@ -413,6 +475,13 @@ return &(operator*()); } + public: + // STL compatibility typedefs. + typedef std::input_iterator_tag iterator_category; + typedef int difference_type; + typedef ValueType value_type; + typedef ConstReferenceType reference; + typedef ConstPointerType pointer; }; @@ -431,6 +500,21 @@ /// The iterator to iterate on the keys. typedef typename Map::KeyIt KeyIt; + + /// The value type of the iterator. + typedef typename Map::ValueType ValueType; + /// The reference type of the iterator. + typedef typename Map::ReferenceType ReferenceType; + /// The pointer type of the iterator. + typedef typename Map::PointerType PointerType; + + /// The const value type of the iterator. + typedef typename Map::ConstValueType ConstValueType; + /// The const reference type of the iterator. + typedef typename Map::ConstReferenceType ConstReferenceType; + /// The pointer type of the iterator. + typedef typename Map::ConstPointerType ConstPointerType; + /// The map initialized const key set. MapConstKeySet(const Map& pmap) : map(&pmap) {} @@ -446,6 +530,14 @@ ConstIterator end() const { return ConstIterator(KeyIt(INVALID)); } + + public: + // STL compatibility typedefs. + typedef ValueType value_type; + typedef ConstIterator const_iterator; + typedef ConstReferenceType const_reference; + typedef ConstPointerType const_pointer; + typedef int difference_type; }; /** This class makes from a map an iteratable set @@ -464,6 +556,21 @@ /// The iterator to iterate on the keys. typedef typename Map::KeyIt KeyIt; + + /// The value type of the iterator. + typedef typename Map::ValueType ValueType; + /// The reference type of the iterator. + typedef typename Map::ReferenceType ReferenceType; + /// The pointer type of the iterator. + typedef typename Map::PointerType PointerType; + + /// The const value type of the iterator. + typedef typename Map::ConstValueType ConstValueType; + /// The const reference type of the iterator. + typedef typename Map::ConstReferenceType ConstReferenceType; + /// The pointer type of the iterator. + typedef typename Map::ConstPointerType ConstPointerType; + /// The map initialized const value set. MapConstValueSet(const Map& pmap) : map(&pmap) {} @@ -479,6 +586,14 @@ ConstIterator end() const { return ConstIterator(*map, KeyIt(INVALID)); } + + public: + // STL compatibility typedefs. + typedef ValueType value_type; + typedef ConstIterator const_iterator; + typedef ConstReferenceType const_reference; + typedef ConstPointerType const_pointer; + typedef int difference_type; }; @@ -498,6 +613,21 @@ /// The iterator to iterate on the keys. typedef typename Map::KeyIt KeyIt; + + /// The value type of the iterator. + typedef typename Map::ValueType ValueType; + /// The reference type of the iterator. + typedef typename Map::ReferenceType ReferenceType; + /// The pointer type of the iterator. + typedef typename Map::PointerType PointerType; + + /// The const value type of the iterator. + typedef typename Map::ConstValueType ConstValueType; + /// The const reference type of the iterator. + typedef typename Map::ConstReferenceType ConstReferenceType; + /// The pointer type of the iterator. + typedef typename Map::ConstPointerType ConstPointerType; + /// The map initialized value set. MapValueSet(Map& pmap) : map(&pmap) {} @@ -527,6 +657,17 @@ return Iterator(*map, KeyIt(INVALID)); } + public: + // STL compatibility typedefs. + typedef ValueType value_type; + typedef Iterator iterator; + typedef ConstIterator const_iterator; + typedef ReferenceType reference; + typedef ConstReferenceType const_reference; + typedef PointerType pointer; + typedef ConstPointerType const_pointer; + typedef int difference_type; + }; /// @} diff -r d56fad02dc55 -r 9bf990cb066d src/hugo/sym_map.h --- a/src/hugo/sym_map.h Mon Sep 13 18:00:26 2004 +0000 +++ b/src/hugo/sym_map.h Mon Sep 13 20:05:13 2004 +0000 @@ -17,6 +17,7 @@ * has different parity. */ + template class SymEdgeIt : public EdgeIt { public: @@ -30,7 +31,7 @@ */ SymEdgeIt(const Graph& graph) : EdgeIt(graph) { - while ( (n & 1) && n != -1) { + while ( (EdgeIt::n & 1) && EdgeIt::n != -1) { EdgeIt::operator++(); } } @@ -44,7 +45,7 @@ */ SymEdgeIt(const Graph& graph, const Edge& edge) : EdgeIt(graph, edge) { - while ( (n & 1) && n != -1) { + while ( (EdgeIt::n & 1) && EdgeIt::n != -1) { EdgeIt::operator++(); } } @@ -53,7 +54,7 @@ */ SymEdgeIt& operator++() { EdgeIt::operator++(); - while ( (n & 1) && n != -1) { + while ( (EdgeIt::n & 1) && EdgeIt::n != -1) { EdgeIt::operator++(); } return *this; @@ -121,32 +122,6 @@ return *this; } - /** - * The subscript operator. The map can be subscripted by the - * actual keys of the graph. - */ - typename MapImpl::ReferenceType operator[](const KeyType& key) { - int id = MapImpl::getGraph()->id(key); - return MapImpl::operator[](id >> 1); - } - - /** - * The const subscript operator. The map can be subscripted by the - * actual keys of the graph. - */ - typename MapImpl::ConstReferenceType operator[](const KeyType& key) const { - int id = MapImpl::getGraph()->id(key); - return MapImpl::operator[](id >> 1); - } - - /** Setter function of the map. Equivalent with map[key] = val. - * This is a compatibility feature with the not dereferable maps. - */ - void set(const KeyType& key, const typename MapImpl::ValueType& val) { - int id = MapImpl::getGraph()->id(key); - MapImpl::operator[](id >> 1) = val; - } - /** Add a new key to the map. It called by the map registry. */ void add(const KeyType& key) { diff -r d56fad02dc55 -r 9bf990cb066d src/hugo/vector_map.h --- a/src/hugo/vector_map.h Mon Sep 13 18:00:26 2004 +0000 +++ b/src/hugo/vector_map.h Mon Sep 13 20:05:13 2004 +0000 @@ -5,6 +5,7 @@ #include #include +#include ///\ingroup graphmaps ///\file @@ -73,32 +74,20 @@ /** Graph and Registry initialized map constructor. */ - VectorMap(const Graph& g, MapRegistry& r) : MapBase(g, r) { - init(); - } + VectorMap(const Graph& g, MapRegistry& r) + : MapBase(g, r), container(KeyInfo::maxId(g)+1) {} /** Constructor to use default value to initialize the map. */ VectorMap(const Graph& g, MapRegistry& r, const Value& v) - : MapBase(g, r) { - for (KeyIt it(*getGraph()); it != INVALID; ++it) { - int id = getGraph()->id(it); - if (id >= (int)container.size()) { - container.resize(id + 1); - } - set(it, v); - } - } + : MapBase(g, r), container(KeyInfo::maxId(g)+1, v) {} /** Constructor to copy a map of an other map type. */ template VectorMap(const CMap& copy) : MapBase(copy) { - if (getGraph()) { - for (KeyIt it(*getGraph()); it != INVALID; ++it) { - int id = getGraph()->id(it); - if (id >= (int)container.size()) { - container.resize(id + 1); - } + if (MapBase::getGraph()) { + container.resize(KeyInfo::maxId(*MapBase::getGraph())+1); + for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) { set(it, copy[it]); } } @@ -107,16 +96,11 @@ /** Assign operator to copy a map an other map type. */ template VectorMap& operator=(const CMap& copy) { - if (getGraph()) { - destroy(); - } + container.clear(); this->MapBase::operator=(copy); - if (getGraph()) { - for (KeyIt it(*getGraph()); it != INVALID; ++it) { - int id = getGraph()->id(it); - if (id >= (int)container.size()) { - container.resize(id + 1); - } + if (MapBase::getGraph()) { + container.resize(KeyInfo::maxId(*MapBase::getGraph())+1); + for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) { set(it, copy[it]); } } @@ -133,7 +117,7 @@ * actual keys of the graph. */ ReferenceType operator[](const KeyType& key) { - int id = getGraph()->id(key); + int id = KeyInfo::id(*MapBase::getGraph(), key); return container[id]; } @@ -142,7 +126,7 @@ * actual keys of the graph. */ ConstReferenceType operator[](const KeyType& key) const { - int id = getGraph()->id(key); + int id = KeyInfo::id(*MapBase::getGraph(), key); return container[id]; } @@ -150,14 +134,14 @@ * This is a compatibility feature with the not dereferable maps. */ void set(const KeyType& key, const ValueType& val) { - int id = getGraph()->id(key); + int id = KeyInfo::id(*MapBase::getGraph(), key); container[id] = val; } /** Add a new key to the map. It called by the map registry. */ void add(const KeyType& key) { - int id = getGraph()->id(key); + int id = KeyInfo::id(*MapBase::getGraph(), key); if (id >= (int)container.size()) { container.resize(id + 1); } @@ -231,7 +215,18 @@ Container container; - + public: + // STL compatibility typedefs. + typedef Iterator iterator; + typedef ConstIterator const_iterator; + typedef typename Iterator::PairValueType value_type; + typedef typename Iterator::KeyType key_type; + typedef typename Iterator::ValueType data_type; + typedef typename Iterator::PairReferenceType reference; + typedef typename Iterator::PairPointerType pointer; + typedef typename ConstIterator::PairReferenceType const_reference; + typedef typename ConstIterator::PairPointerType const_pointer; + typedef int difference_type; }; /// @} diff -r d56fad02dc55 -r 9bf990cb066d src/test/test_tools.h --- a/src/test/test_tools.h Mon Sep 13 18:00:26 2004 +0000 +++ b/src/test/test_tools.h Mon Sep 13 20:05:13 2004 +0000 @@ -1,3 +1,4 @@ +// -*- c++ -*- #ifndef HUGO_TEST_TEST_TOOLS_H #define HUGO_TEST_TEST_TOOLS_H