COIN-OR::LEMON - Graph Library

Ticket #402: diff.txt

File diff.txt, 4.5 KB (added by Charles Wilcox, 10 years ago)

'diff -u' showing local code changes to get the observed behavior to match the expected behavior.

Line 
1--- ./array_map.h       2010-12-07 11:51:05.000000000 -0500
2+++ wip/array_map.h     2010-12-07 11:50:46.000000000 -0500
3@@ -81,21 +81,23 @@
4     // \brief Graph initialized map constructor.
5     //
6     // Graph initialized map constructor.
7-    explicit ArrayMap(const GraphType& graph) {
8+    explicit ArrayMap(const GraphType& graph)
9+      : initval(Value()), capacity(0), values(NULL), allocator() {
10       Parent::attach(graph.notifier(Item()));
11       allocate_memory();
12       Notifier* nf = Parent::notifier();
13       Item it;
14       for (nf->first(it); it != INVALID; nf->next(it)) {
15         int id = nf->id(it);;
16-        allocator.construct(&(values[id]), Value());
17+        allocator.construct(&(values[id]), initval);
18       }
19     }
20 
21     // \brief Constructor to use default value to initialize the map.
22     //
23     // It constructs a map and initialize all of the the map.
24-    ArrayMap(const GraphType& graph, const Value& value) {
25+    ArrayMap(const GraphType& graph, const Value& value)
26+      : initval(value), capacity(0), values(NULL), allocator() {
27       Parent::attach(graph.notifier(Item()));
28       allocate_memory();
29       Notifier* nf = Parent::notifier();
30@@ -226,7 +228,7 @@
31         values = new_values;
32         capacity = new_capacity;
33       }
34-      allocator.construct(&(values[id]), Value());
35+      allocator.construct(&(values[id]), initval);
36     }
37 
38     // \brief Adds more new keys to the map.
39@@ -269,7 +271,7 @@
40       }
41       for (int i = 0; i < int(keys.size()); ++i) {
42         int id = nf->id(keys[i]);
43-        allocator.construct(&(values[id]), Value());
44+        allocator.construct(&(values[id]), initval);
45       }
46     }
47 
48@@ -303,7 +305,7 @@
49       Item it;
50       for (nf->first(it); it != INVALID; nf->next(it)) {
51         int id = nf->id(it);;
52-        allocator.construct(&(values[id]), Value());
53+        allocator.construct(&(values[id]), initval);
54       }
55     }
56 
57@@ -340,6 +342,7 @@
58       values = allocator.allocate(capacity);
59     }
60 
61+    const Value initval;
62     int capacity;
63     Value* values;
64     Allocator allocator;
65--- ./vector_map.h      2010-12-07 11:51:05.000000000 -0500
66+++ wip/vector_map.h    2010-12-07 11:44:19.000000000 -0500
67@@ -89,7 +89,8 @@
68     //
69     // It constructs a map and attachs it into the notifier.
70     // It adds all the items of the graph to the map.
71-    VectorMap(const GraphType& graph) {
72+    VectorMap(const GraphType& graph)
73+      : initval(Value()), container() {
74       Parent::attach(graph.notifier(Item()));
75       container.resize(Parent::notifier()->maxId() + 1);
76     }
77@@ -98,9 +99,10 @@
78     //
79     // It constructs a map uses a given value to initialize the map.
80     // It adds all the items of the graph to the map.
81-    VectorMap(const GraphType& graph, const Value& value) {
82+    VectorMap(const GraphType& graph, const Value& value)
83+      : initval(value), container() {
84       Parent::attach(graph.notifier(Item()));
85-      container.resize(Parent::notifier()->maxId() + 1, value);
86+      container.resize(Parent::notifier()->maxId() + 1, initval);
87     }
88 
89   private:
90@@ -178,7 +180,7 @@
91     virtual void add(const Key& key) {
92       int id = Parent::notifier()->id(key);
93       if (id >= int(container.size())) {
94-        container.resize(id + 1);
95+        container.resize(id + 1, initval);
96       }
97     }
98 
99@@ -194,7 +196,7 @@
100           max = id;
101         }
102       }
103-      container.resize(max + 1);
104+      container.resize(max + 1, initval);
105     }
106 
107     // \brief Erase a key from the map.
108@@ -202,7 +204,7 @@
109     // Erase a key from the map. It is called by the observer notifier
110     // and it overrides the erase() member function of the observer base.
111     virtual void erase(const Key& key) {
112-      container[Parent::notifier()->id(key)] = Value();
113+      container[Parent::notifier()->id(key)] = initval;
114     }
115 
116     // \brief Erase more keys from the map.
117@@ -211,7 +213,7 @@
118     // and it overrides the erase() member function of the observer base.
119     virtual void erase(const std::vector<Key>& keys) {
120       for (int i = 0; i < int(keys.size()); ++i) {
121-        container[Parent::notifier()->id(keys[i])] = Value();
122+        container[Parent::notifier()->id(keys[i])] = initval;
123       }
124     }
125 
126@@ -222,7 +224,7 @@
127     virtual void build() {
128       int size = Parent::notifier()->maxId() + 1;
129       container.reserve(size);
130-      container.resize(size);
131+      container.resize(size, initval);
132     }
133 
134     // \brief Clear the map.
135@@ -235,6 +237,7 @@
136 
137   private:
138 
139+    const Value initval;
140     Container container;
141 
142   };