1.1 --- a/src/lemon/array_map.h Wed Nov 10 21:59:59 2004 +0000
1.2 +++ b/src/lemon/array_map.h Thu Nov 11 09:31:55 2004 +0000
1.3 @@ -44,7 +44,6 @@
1.4 template <typename _Graph,
1.5 typename _Item,
1.6 typename _ItemIt,
1.7 - typename _IdMap,
1.8 typename _Value>
1.9 class ArrayMap : public AlterationObserverRegistry<_Item>::ObserverBase {
1.10
1.11 @@ -61,8 +60,6 @@
1.12 /// The iterator to iterate on the keys.
1.13 typedef _ItemIt KeyIt;
1.14
1.15 - typedef _IdMap IdMap;
1.16 -
1.17 typedef _Value Value;
1.18
1.19 /// The MapBase of the Map which imlements the core regisitry function.
1.20 @@ -94,11 +91,11 @@
1.21
1.22 /** Graph and Registry initialized map constructor.
1.23 */
1.24 - ArrayMap(const Graph& _g, Registry& _r) : graph(&_g) {
1.25 - attach(_r);
1.26 + ArrayMap(const Graph& _g) : graph(&_g) {
1.27 + attach(_g.getObserverRegistry(_Item()));
1.28 allocate_memory();
1.29 for (KeyIt it(*graph); it != INVALID; ++it) {
1.30 - int id = IdMap(*graph)[it];
1.31 + int id = graph->id(it);;
1.32 allocator.construct(&(values[id]), Value());
1.33 }
1.34 }
1.35 @@ -107,11 +104,11 @@
1.36
1.37 /// It constrates a map and initialize all of the the map.
1.38
1.39 - ArrayMap(const Graph& _g, Registry& _r, const Value& _v) : graph(&_g) {
1.40 - attach(_r);
1.41 + ArrayMap(const Graph& _g, const Value& _v) : graph(&_g) {
1.42 + attach(_g.getObserverRegistry(_Item()));
1.43 allocate_memory();
1.44 for (KeyIt it(*graph); it != INVALID; ++it) {
1.45 - int id = IdMap(*graph)[it];
1.46 + int id = graph->id(it);;
1.47 allocator.construct(&(values[id]), _v);
1.48 }
1.49 }
1.50 @@ -126,7 +123,7 @@
1.51 if (capacity == 0) return;
1.52 values = allocator.allocate(capacity);
1.53 for (KeyIt it(*graph); it != INVALID; ++it) {
1.54 - int id = IdMap(*graph)[it];
1.55 + int id = graph->id(it);;
1.56 allocator.construct(&(values[id]), copy.values[id]);
1.57 }
1.58 }
1.59 @@ -154,7 +151,7 @@
1.60 }
1.61
1.62 for (KeyIt it(*graph); it != INVALID; ++it) {
1.63 - int id = IdMap(*graph)[it];
1.64 + int id = graph->id(it);;
1.65 allocator.construct(&(values[id]), copy.values[id]);
1.66 }
1.67
1.68 @@ -176,7 +173,7 @@
1.69 * actual keys of the graph.
1.70 */
1.71 ReferenceType operator[](const KeyType& key) {
1.72 - int id = IdMap(*graph)[key];
1.73 + int id = graph->id(key);
1.74 return values[id];
1.75 }
1.76
1.77 @@ -185,7 +182,7 @@
1.78 * actual keys of the graph.
1.79 */
1.80 ConstReferenceType operator[](const KeyType& key) const {
1.81 - int id = IdMap(*graph)[key];
1.82 + int id = graph->id(key);
1.83 return values[id];
1.84 }
1.85
1.86 @@ -199,7 +196,7 @@
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 = IdMap(*graph)[key];
1.91 + int id = graph->id(key);
1.92 if (id >= capacity) {
1.93 int new_capacity = (capacity == 0 ? 1 : capacity);
1.94 while (new_capacity <= id) {
1.95 @@ -207,7 +204,7 @@
1.96 }
1.97 Value* new_values = allocator.allocate(new_capacity);
1.98 for (KeyIt it(*graph); it != INVALID; ++it) {
1.99 - int jd = IdMap(*graph)[it];
1.100 + int jd = graph->id(it);;
1.101 if (id != jd) {
1.102 allocator.construct(&(new_values[jd]), values[jd]);
1.103 allocator.destroy(&(values[jd]));
1.104 @@ -223,14 +220,14 @@
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 = IdMap(*graph)[key];
1.109 + int id = graph->id(key);
1.110 allocator.destroy(&(values[id]));
1.111 }
1.112
1.113 void build() {
1.114 allocate_memory();
1.115 for (KeyIt it(*graph); it != INVALID; ++it) {
1.116 - int id = IdMap(*graph)[it];
1.117 + int id = graph->id(it);;
1.118 allocator.construct(&(values[id]), Value());
1.119 }
1.120 }
1.121 @@ -238,7 +235,7 @@
1.122 void clear() {
1.123 if (capacity != 0) {
1.124 for (KeyIt it(*graph); it != INVALID; ++it) {
1.125 - int id = IdMap(*graph)[it];
1.126 + int id = graph->id(it);;
1.127 allocator.destroy(&(values[id]));
1.128 }
1.129 allocator.deallocate(values, capacity);
1.130 @@ -302,7 +299,7 @@
1.131 private:
1.132
1.133 void allocate_memory() {
1.134 - int max_id = IdMap(*graph).maxId();
1.135 + int max_id = graph->maxId(_Item());
1.136 if (max_id == -1) {
1.137 capacity = 0;
1.138 values = 0;
1.139 @@ -343,55 +340,51 @@
1.140
1.141 typedef typename Parent::Node Node;
1.142 typedef typename Parent::NodeIt NodeIt;
1.143 - typedef typename Parent::NodeIdMap NodeIdMap;
1.144 typedef typename Parent::NodeObserverRegistry NodeObserverRegistry;
1.145
1.146 typedef typename Parent::Edge Edge;
1.147 typedef typename Parent::EdgeIt EdgeIt;
1.148 - typedef typename Parent::EdgeIdMap EdgeIdMap;
1.149 typedef typename Parent::EdgeObserverRegistry EdgeObserverRegistry;
1.150
1.151
1.152
1.153 template <typename _Value>
1.154 - class NodeMap : public ArrayMap<Graph, Node, NodeIt, NodeIdMap, _Value> {
1.155 + class NodeMap : public ArrayMap<Graph, Node, NodeIt, _Value> {
1.156 public:
1.157 typedef ArrayMappableGraphExtender<_Base> Graph;
1.158
1.159 typedef typename Graph::Node Node;
1.160 typedef typename Graph::NodeIt NodeIt;
1.161 - typedef typename Graph::NodeIdMap NodeIdMap;
1.162
1.163 - typedef ArrayMap<Graph, Node, NodeIt, NodeIdMap, _Value> Parent;
1.164 + typedef ArrayMap<Graph, Node, NodeIt, _Value> Parent;
1.165
1.166 //typedef typename Parent::Graph Graph;
1.167 typedef typename Parent::Value Value;
1.168
1.169 NodeMap(const Graph& g)
1.170 - : Parent(g, g.getNodeObserverRegistry()) {}
1.171 + : Parent(g) {}
1.172 NodeMap(const Graph& g, const Value& v)
1.173 - : Parent(g, g.getNodeObserverRegistry(), v) {}
1.174 + : Parent(g, v) {}
1.175
1.176 };
1.177
1.178 template <typename _Value>
1.179 - class EdgeMap : public ArrayMap<Graph, Edge, EdgeIt, EdgeIdMap, _Value> {
1.180 + class EdgeMap : public ArrayMap<Graph, Edge, EdgeIt, _Value> {
1.181 public:
1.182 typedef ArrayMappableGraphExtender<_Base> Graph;
1.183
1.184 typedef typename Graph::Edge Edge;
1.185 typedef typename Graph::EdgeIt EdgeIt;
1.186 - typedef typename Graph::EdgeIdMap EdgeIdMap;
1.187
1.188 - typedef ArrayMap<Graph, Edge, EdgeIt, EdgeIdMap, _Value> Parent;
1.189 + typedef ArrayMap<Graph, Edge, EdgeIt, _Value> Parent;
1.190
1.191 //typedef typename Parent::Graph Graph;
1.192 typedef typename Parent::Value Value;
1.193
1.194 EdgeMap(const Graph& g)
1.195 - : Parent(g, g.getEdgeObserverRegistry()) {}
1.196 + : Parent(g) {}
1.197 EdgeMap(const Graph& g, const Value& v)
1.198 - : Parent(g, g.getEdgeObserverRegistry(), v) {}
1.199 + : Parent(g, v) {}
1.200
1.201 };
1.202