--- ./array_map.h 2010-12-07 11:51:05.000000000 -0500 +++ wip/array_map.h 2010-12-07 11:50:46.000000000 -0500 @@ -81,21 +81,23 @@ // \brief Graph initialized map constructor. // // Graph initialized map constructor. - explicit ArrayMap(const GraphType& graph) { + explicit ArrayMap(const GraphType& graph) + : initval(Value()), capacity(0), values(NULL), allocator() { Parent::attach(graph.notifier(Item())); allocate_memory(); Notifier* nf = Parent::notifier(); Item it; for (nf->first(it); it != INVALID; nf->next(it)) { int id = nf->id(it);; - allocator.construct(&(values[id]), Value()); + allocator.construct(&(values[id]), initval); } } // \brief Constructor to use default value to initialize the map. // // It constructs a map and initialize all of the the map. - ArrayMap(const GraphType& graph, const Value& value) { + ArrayMap(const GraphType& graph, const Value& value) + : initval(value), capacity(0), values(NULL), allocator() { Parent::attach(graph.notifier(Item())); allocate_memory(); Notifier* nf = Parent::notifier(); @@ -226,7 +228,7 @@ values = new_values; capacity = new_capacity; } - allocator.construct(&(values[id]), Value()); + allocator.construct(&(values[id]), initval); } // \brief Adds more new keys to the map. @@ -269,7 +271,7 @@ } for (int i = 0; i < int(keys.size()); ++i) { int id = nf->id(keys[i]); - allocator.construct(&(values[id]), Value()); + allocator.construct(&(values[id]), initval); } } @@ -303,7 +305,7 @@ Item it; for (nf->first(it); it != INVALID; nf->next(it)) { int id = nf->id(it);; - allocator.construct(&(values[id]), Value()); + allocator.construct(&(values[id]), initval); } } @@ -340,6 +342,7 @@ values = allocator.allocate(capacity); } + const Value initval; int capacity; Value* values; Allocator allocator; --- ./vector_map.h 2010-12-07 11:51:05.000000000 -0500 +++ wip/vector_map.h 2010-12-07 11:44:19.000000000 -0500 @@ -89,7 +89,8 @@ // // It constructs a map and attachs it into the notifier. // It adds all the items of the graph to the map. - VectorMap(const GraphType& graph) { + VectorMap(const GraphType& graph) + : initval(Value()), container() { Parent::attach(graph.notifier(Item())); container.resize(Parent::notifier()->maxId() + 1); } @@ -98,9 +99,10 @@ // // It constructs a map uses a given value to initialize the map. // It adds all the items of the graph to the map. - VectorMap(const GraphType& graph, const Value& value) { + VectorMap(const GraphType& graph, const Value& value) + : initval(value), container() { Parent::attach(graph.notifier(Item())); - container.resize(Parent::notifier()->maxId() + 1, value); + container.resize(Parent::notifier()->maxId() + 1, initval); } private: @@ -178,7 +180,7 @@ virtual void add(const Key& key) { int id = Parent::notifier()->id(key); if (id >= int(container.size())) { - container.resize(id + 1); + container.resize(id + 1, initval); } } @@ -194,7 +196,7 @@ max = id; } } - container.resize(max + 1); + container.resize(max + 1, initval); } // \brief Erase a key from the map. @@ -202,7 +204,7 @@ // Erase a key from the map. It is called by the observer notifier // and it overrides the erase() member function of the observer base. virtual void erase(const Key& key) { - container[Parent::notifier()->id(key)] = Value(); + container[Parent::notifier()->id(key)] = initval; } // \brief Erase more keys from the map. @@ -211,7 +213,7 @@ // and it overrides the erase() member function of the observer base. virtual void erase(const std::vector& keys) { for (int i = 0; i < int(keys.size()); ++i) { - container[Parent::notifier()->id(keys[i])] = Value(); + container[Parent::notifier()->id(keys[i])] = initval; } } @@ -222,7 +224,7 @@ virtual void build() { int size = Parent::notifier()->maxId() + 1; container.reserve(size); - container.resize(size); + container.resize(size, initval); } // \brief Clear the map. @@ -235,6 +237,7 @@ private: + const Value initval; Container container; };