[Lemon-commits] [lemon_svn] deba: r1143 - in hugo/trunk/src: hugo test
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:43:30 CET 2006
Author: deba
Date: Mon Sep 13 22:05:13 2004
New Revision: 1143
Added:
hugo/trunk/src/hugo/map_bits.h
Modified:
hugo/trunk/src/hugo/Makefile.am
hugo/trunk/src/hugo/array_map.h
hugo/trunk/src/hugo/graph_wrapper.h
hugo/trunk/src/hugo/list_graph.h
hugo/trunk/src/hugo/map_defines.h
hugo/trunk/src/hugo/map_iterator.h
hugo/trunk/src/hugo/sym_map.h
hugo/trunk/src/hugo/vector_map.h
hugo/trunk/src/test/test_tools.h
Log:
Bug fix in the symmetric maps.
Faster map initialization.
Iterators and Containers STL compatible.
Modified: hugo/trunk/src/hugo/Makefile.am
==============================================================================
--- hugo/trunk/src/hugo/Makefile.am (original)
+++ hugo/trunk/src/hugo/Makefile.am Mon Sep 13 22:05:13 2004
@@ -17,6 +17,7 @@
map_defines.h \
map_iterator.h \
map_registry.h \
+ map_bits.h \
maps.h \
mincostflows.h \
minlengthpaths.h \
Modified: hugo/trunk/src/hugo/array_map.h
==============================================================================
--- hugo/trunk/src/hugo/array_map.h (original)
+++ hugo/trunk/src/hugo/array_map.h Mon Sep 13 22:05:13 2004
@@ -5,6 +5,7 @@
#include <memory>
#include <hugo/map_iterator.h>
+#include <hugo/map_bits.h>
///\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<Graph, KeyIt>::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<Graph, KeyIt>::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<Graph, KeyIt>::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<Graph, KeyIt>::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 <typename CMap> 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<Graph, KeyIt>::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<Graph, KeyIt>::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<Graph, KeyIt>::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<Graph, KeyIt>::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<Graph, KeyIt>::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<Graph, KeyIt>::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<Graph, KeyIt>::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;
};
/// @}
Modified: hugo/trunk/src/hugo/graph_wrapper.h
==============================================================================
--- hugo/trunk/src/hugo/graph_wrapper.h (original)
+++ hugo/trunk/src/hugo/graph_wrapper.h Mon Sep 13 22:05:13 2004
@@ -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);
}
Modified: hugo/trunk/src/hugo/list_graph.h
==============================================================================
--- hugo/trunk/src/hugo/list_graph.h (original)
+++ hugo/trunk/src/hugo/list_graph.h Mon Sep 13 22:05:13 2004
@@ -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;
+ }
};
};
Added: hugo/trunk/src/hugo/map_bits.h
==============================================================================
--- (empty file)
+++ hugo/trunk/src/hugo/map_bits.h Mon Sep 13 22:05:13 2004
@@ -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 <typename Graph, typename KeyIt>
+ struct KeyInfo {};
+
+ template <typename Graph>
+ struct KeyInfo<Graph, typename Graph::NodeIt> {
+ 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 <typename Graph>
+ struct KeyInfo<Graph, typename Graph::EdgeIt> {
+ 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 <typename Graph>
+ struct KeyInfo<Graph, typename Graph::SymEdgeIt> {
+ 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
Modified: hugo/trunk/src/hugo/map_defines.h
==============================================================================
--- hugo/trunk/src/hugo/map_defines.h (original)
+++ hugo/trunk/src/hugo/map_defines.h Mon Sep 13 22:05:13 2004
@@ -96,7 +96,7 @@
#define CREATE_SYM_EDGE_MAP_REGISTRY \
typedef SymEdgeIt<Graph, Edge, EdgeIt> SymEdgeIt; \
typedef MapRegistry<Graph, Edge, SymEdgeIt> SymEdgeMapRegistry; \
-mutable EdgeMapRegistry sym_edge_maps;
+mutable SymEdgeMapRegistry sym_edge_maps;
/** Creates a map from a template map. The import method is
Modified: hugo/trunk/src/hugo/map_iterator.h
==============================================================================
--- hugo/trunk/src/hugo/map_iterator.h (original)
+++ hugo/trunk/src/hugo/map_iterator.h Mon Sep 13 22:05:13 2004
@@ -2,6 +2,8 @@
#ifndef MAP_ITERATOR_H
#define MAP_ITERATOR_H
+#include <iterator>
+
#include <hugo/extended_pair.h>
///\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<Map>;
+
public:
+ /// The iterator base class.
+ typedef MapIteratorBase<Map> 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<KeyType, const KeyType&,
+ ValueType, const ValueType&> PairValueType;
+
/// The reference type of the iterator.
typedef extended_pair<const KeyType&, const KeyType&,
ReferenceType, ReferenceType> PairReferenceType;
@@ -111,12 +122,11 @@
/// Constructor to initalize the iterators returned
/// by the begin() and end().
- MapIterator(Map& pmap, const KeyIt& pit)
- : MapIteratorBase<Map>(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<Map> 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<Map>(pit), map(&pmap) {}
+ : Base(pit), map(&pmap) {}
/// Constructor to create const iterator from a non const.
MapConstIterator(const MapIterator<Map>& pit) {
- it = pit.it;
+ Base::it = pit.Base::it;
map = pit.map;
}
+ /// The value type of the iterator.
+ typedef extended_pair<KeyType, const KeyType&,
+ ValueType, const ValueType&> PairValueType;
+
/// The reference type of map.
typedef extended_pair<const KeyType&, const KeyType&,
ConstReferenceType, ConstReferenceType> 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<Map> 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<Map> 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<Map>(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<KeyType>(it);
+ return static_cast<KeyType>(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 <typename Map> class MapConstValueIterator;
+ /** MapValueIterator creates an stl compatible iterator
+ * for the values.
+ */
template <typename Map>
class MapValueIterator : public MapIteratorBase<Map> {
@@ -286,6 +333,9 @@
public:
+ /// The iterator base class.
+ typedef MapIteratorBase<Map> 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<Map>(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 <typename Map>
class MapConstValueIterator : public MapIteratorBase<Map> {
public:
+ /// The iterator base class.
+ typedef MapIteratorBase<Map> 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<Map>& 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<Map>(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;
+
};
/// @}
Modified: hugo/trunk/src/hugo/sym_map.h
==============================================================================
--- hugo/trunk/src/hugo/sym_map.h (original)
+++ hugo/trunk/src/hugo/sym_map.h Mon Sep 13 22:05:13 2004
@@ -17,6 +17,7 @@
* has different parity.
*/
+
template <typename Graph, typename Edge, typename EdgeIt>
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) {
Modified: hugo/trunk/src/hugo/vector_map.h
==============================================================================
--- hugo/trunk/src/hugo/vector_map.h (original)
+++ hugo/trunk/src/hugo/vector_map.h Mon Sep 13 22:05:13 2004
@@ -5,6 +5,7 @@
#include <vector>
#include <hugo/map_iterator.h>
+#include <hugo/map_bits.h>
///\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<Graph, KeyIt>::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<Graph, KeyIt>::maxId(g)+1, v) {}
/** Constructor to copy a map of an other map type.
*/
template <typename CMap> 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<Graph, KeyIt>::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 <typename CMap> 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<Graph, KeyIt>::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<Graph, KeyIt>::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<Graph, KeyIt>::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<Graph, KeyIt>::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<Graph, KeyIt>::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;
};
/// @}
Modified: hugo/trunk/src/test/test_tools.h
==============================================================================
--- hugo/trunk/src/test/test_tools.h (original)
+++ hugo/trunk/src/test/test_tools.h Mon Sep 13 22:05:13 2004
@@ -1,3 +1,4 @@
+// -*- c++ -*-
#ifndef HUGO_TEST_TEST_TOOLS_H
#define HUGO_TEST_TEST_TOOLS_H
More information about the Lemon-commits
mailing list