1.1 --- a/src/hugo/vector_map.h Mon Sep 13 18:00:26 2004 +0000
1.2 +++ b/src/hugo/vector_map.h Mon Sep 13 20:05:13 2004 +0000
1.3 @@ -5,6 +5,7 @@
1.4 #include <vector>
1.5
1.6 #include <hugo/map_iterator.h>
1.7 +#include <hugo/map_bits.h>
1.8
1.9 ///\ingroup graphmaps
1.10 ///\file
1.11 @@ -73,32 +74,20 @@
1.12
1.13 /** Graph and Registry initialized map constructor.
1.14 */
1.15 - VectorMap(const Graph& g, MapRegistry& r) : MapBase(g, r) {
1.16 - init();
1.17 - }
1.18 + VectorMap(const Graph& g, MapRegistry& r)
1.19 + : MapBase(g, r), container(KeyInfo<Graph, KeyIt>::maxId(g)+1) {}
1.20
1.21 /** Constructor to use default value to initialize the map.
1.22 */
1.23 VectorMap(const Graph& g, MapRegistry& r, const Value& v)
1.24 - : MapBase(g, r) {
1.25 - for (KeyIt it(*getGraph()); it != INVALID; ++it) {
1.26 - int id = getGraph()->id(it);
1.27 - if (id >= (int)container.size()) {
1.28 - container.resize(id + 1);
1.29 - }
1.30 - set(it, v);
1.31 - }
1.32 - }
1.33 + : MapBase(g, r), container(KeyInfo<Graph, KeyIt>::maxId(g)+1, v) {}
1.34
1.35 /** Constructor to copy a map of an other map type.
1.36 */
1.37 template <typename CMap> VectorMap(const CMap& copy) : MapBase(copy) {
1.38 - if (getGraph()) {
1.39 - for (KeyIt it(*getGraph()); it != INVALID; ++it) {
1.40 - int id = getGraph()->id(it);
1.41 - if (id >= (int)container.size()) {
1.42 - container.resize(id + 1);
1.43 - }
1.44 + if (MapBase::getGraph()) {
1.45 + container.resize(KeyInfo<Graph, KeyIt>::maxId(*MapBase::getGraph())+1);
1.46 + for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
1.47 set(it, copy[it]);
1.48 }
1.49 }
1.50 @@ -107,16 +96,11 @@
1.51 /** Assign operator to copy a map an other map type.
1.52 */
1.53 template <typename CMap> VectorMap& operator=(const CMap& copy) {
1.54 - if (getGraph()) {
1.55 - destroy();
1.56 - }
1.57 + container.clear();
1.58 this->MapBase::operator=(copy);
1.59 - if (getGraph()) {
1.60 - for (KeyIt it(*getGraph()); it != INVALID; ++it) {
1.61 - int id = getGraph()->id(it);
1.62 - if (id >= (int)container.size()) {
1.63 - container.resize(id + 1);
1.64 - }
1.65 + if (MapBase::getGraph()) {
1.66 + container.resize(KeyInfo<Graph, KeyIt>::maxId(*MapBase::getGraph())+1);
1.67 + for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
1.68 set(it, copy[it]);
1.69 }
1.70 }
1.71 @@ -133,7 +117,7 @@
1.72 * actual keys of the graph.
1.73 */
1.74 ReferenceType operator[](const KeyType& key) {
1.75 - int id = getGraph()->id(key);
1.76 + int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
1.77 return container[id];
1.78 }
1.79
1.80 @@ -142,7 +126,7 @@
1.81 * actual keys of the graph.
1.82 */
1.83 ConstReferenceType operator[](const KeyType& key) const {
1.84 - int id = getGraph()->id(key);
1.85 + int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
1.86 return container[id];
1.87 }
1.88
1.89 @@ -150,14 +134,14 @@
1.90 * This is a compatibility feature with the not dereferable maps.
1.91 */
1.92 void set(const KeyType& key, const ValueType& val) {
1.93 - int id = getGraph()->id(key);
1.94 + int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
1.95 container[id] = val;
1.96 }
1.97
1.98 /** Add a new key to the map. It called by the map registry.
1.99 */
1.100 void add(const KeyType& key) {
1.101 - int id = getGraph()->id(key);
1.102 + int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
1.103 if (id >= (int)container.size()) {
1.104 container.resize(id + 1);
1.105 }
1.106 @@ -231,7 +215,18 @@
1.107
1.108 Container container;
1.109
1.110 -
1.111 + public:
1.112 + // STL compatibility typedefs.
1.113 + typedef Iterator iterator;
1.114 + typedef ConstIterator const_iterator;
1.115 + typedef typename Iterator::PairValueType value_type;
1.116 + typedef typename Iterator::KeyType key_type;
1.117 + typedef typename Iterator::ValueType data_type;
1.118 + typedef typename Iterator::PairReferenceType reference;
1.119 + typedef typename Iterator::PairPointerType pointer;
1.120 + typedef typename ConstIterator::PairReferenceType const_reference;
1.121 + typedef typename ConstIterator::PairPointerType const_pointer;
1.122 + typedef int difference_type;
1.123 };
1.124
1.125 /// @}