1.1 --- a/src/hugo/array_map.h Mon Sep 13 18:00:26 2004 +0000
1.2 +++ b/src/hugo/array_map.h Mon Sep 13 20:05:13 2004 +0000
1.3 @@ -5,6 +5,7 @@
1.4 #include <memory>
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 @@ -71,7 +72,7 @@
1.12 ArrayMap(const Graph& g, MapRegistry& r) : MapBase(g, r) {
1.13 allocate_memory();
1.14 for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
1.15 - int id = MapBase::getGraph()->id(it);
1.16 + int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
1.17 allocator.construct(&(values[id]), Value());
1.18 }
1.19 }
1.20 @@ -82,7 +83,7 @@
1.21 : MapBase(g, r) {
1.22 allocate_memory();
1.23 for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
1.24 - int id = MapBase::getGraph()->id(it);
1.25 + int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
1.26 allocator.construct(&(values[id]), v);
1.27 }
1.28 }
1.29 @@ -94,7 +95,7 @@
1.30 if (capacity == 0) return;
1.31 values = allocator.allocate(capacity);
1.32 for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
1.33 - int id = MapBase::getGraph()->id(it);
1.34 + int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
1.35 allocator.construct(&(values[id]), copy.values[id]);
1.36 }
1.37 }
1.38 @@ -123,7 +124,7 @@
1.39 if (capacity == 0) return *this;
1.40 values = allocator.allocate(capacity);
1.41 for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
1.42 - int id = MapBase::getGraph()->id(it);
1.43 + int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
1.44 allocator.construct(&(values[id]), copy.values[id]);
1.45 }
1.46 return *this;
1.47 @@ -132,9 +133,10 @@
1.48 /** Assign operator to copy a map an other map type.
1.49 */
1.50 template <typename CMap> ArrayMap& operator=(const CMap& copy) {
1.51 - if (MapBase::getGraph()) {
1.52 + if (capacity != 0) {
1.53 MapBase::destroy();
1.54 - }
1.55 + allocator.deallocate(values, capacity);
1.56 + }
1.57 MapBase::operator=(copy);
1.58 if (MapBase::getGraph()) {
1.59 allocate_memory();
1.60 @@ -160,7 +162,7 @@
1.61 * actual keys of the graph.
1.62 */
1.63 ReferenceType operator[](const KeyType& key) {
1.64 - int id = MapBase::getGraph()->id(key);
1.65 + int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
1.66 return values[id];
1.67 }
1.68
1.69 @@ -169,7 +171,7 @@
1.70 * actual keys of the graph.
1.71 */
1.72 ConstReferenceType operator[](const KeyType& key) const {
1.73 - int id = MapBase::getGraph()->id(key);
1.74 + int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
1.75 return values[id];
1.76 }
1.77
1.78 @@ -177,14 +179,14 @@
1.79 * This is a compatibility feature with the not dereferable maps.
1.80 */
1.81 void set(const KeyType& key, const ValueType& val) {
1.82 - int id = MapBase::getGraph()->id(key);
1.83 + int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
1.84 values[id] = val;
1.85 }
1.86
1.87 /** Add a new key to the map. It called by the map registry.
1.88 */
1.89 void add(const KeyType& key) {
1.90 - int id = MapBase::getGraph()->id(key);
1.91 + int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
1.92 if (id >= capacity) {
1.93 int new_capacity = (capacity == 0 ? 1 : capacity);
1.94 while (new_capacity <= id) {
1.95 @@ -192,7 +194,7 @@
1.96 }
1.97 Value* new_values = allocator.allocate(new_capacity);;
1.98 for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
1.99 - int jd = MapBase::getGraph()->id(it);
1.100 + int jd = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
1.101 if (id != jd) {
1.102 allocator.construct(&(new_values[jd]), values[jd]);
1.103 allocator.destroy(&(values[jd]));
1.104 @@ -208,7 +210,7 @@
1.105 /** Erase a key from the map. It called by the map registry.
1.106 */
1.107 void erase(const KeyType& key) {
1.108 - int id = MapBase::getGraph()->id(key);
1.109 + int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
1.110 allocator.destroy(&(values[id]));
1.111 }
1.112
1.113 @@ -278,13 +280,7 @@
1.114 private:
1.115
1.116 void allocate_memory() {
1.117 - int max_id = -1;
1.118 - for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
1.119 - int id = MapBase::getGraph()->id(it);
1.120 - if (id > max_id) {
1.121 - max_id = id;
1.122 - }
1.123 - }
1.124 + int max_id = KeyInfo<Graph, KeyIt>::maxId(*MapBase::getGraph());
1.125 if (max_id == -1) {
1.126 capacity = 0;
1.127 values = 0;
1.128 @@ -300,6 +296,19 @@
1.129 int capacity;
1.130 Value* values;
1.131 Allocator allocator;
1.132 +
1.133 + public:
1.134 + // STL compatibility typedefs.
1.135 + typedef Iterator iterator;
1.136 + typedef ConstIterator const_iterator;
1.137 + typedef typename Iterator::PairValueType value_type;
1.138 + typedef typename Iterator::KeyType key_type;
1.139 + typedef typename Iterator::ValueType data_type;
1.140 + typedef typename Iterator::PairReferenceType reference;
1.141 + typedef typename Iterator::PairPointerType pointer;
1.142 + typedef typename ConstIterator::PairReferenceType const_reference;
1.143 + typedef typename ConstIterator::PairPointerType const_pointer;
1.144 + typedef int difference_type;
1.145 };
1.146
1.147 /// @}