Changeset 891:74589d20dbc3 in lemon-0.x for src/hugo/array_map.h
- Timestamp:
- 09/21/04 00:57:48 (20 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1199
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/hugo/array_map.h
r844 r891 66 66 /** Default constructor for the map. 67 67 */ 68 ArrayMap() : values(0), capacity(0) {}68 ArrayMap() : capacity(0), values(0) {} 69 69 70 70 /** Graph and Registry initialized map constructor. … … 91 91 /** Constructor to copy a map of the same map type. 92 92 */ 93 ArrayMap(const ArrayMap& copy) : MapBase( *copy.graph, *copy.registry) {93 ArrayMap(const ArrayMap& copy) : MapBase(copy) { 94 94 capacity = copy.capacity; 95 95 if (capacity == 0) return; … … 103 103 /** Constructor to copy a map of an other map type. 104 104 */ 105 template <typename CMap> ArrayMap(const CMap& copy) 106 : MapBase(copy), capacity(0), values(0) { 107 if (MapBase::getGraph()) { 108 allocate_memory(); 109 for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) { 110 set(it, copy[it]); 111 } 105 template <typename TT> 106 ArrayMap(const ArrayMap<MapRegistry, TT>& copy) 107 : MapBase(copy) { 108 capacity = copy.capacity; 109 if (capacity == 0) return; 110 values = allocator.allocate(capacity); 111 for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) { 112 int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it); 113 allocator.construct(&(values[id]), copy.values[id]); 112 114 } 113 115 } … … 117 119 ArrayMap& operator=(const ArrayMap& copy) { 118 120 if (© == this) return *this; 121 119 122 if (capacity != 0) { 120 123 MapBase::destroy(); 121 124 allocator.deallocate(values, capacity); 122 125 } 126 127 MapBase::operator=(copy); 128 123 129 capacity = copy.capacity; 124 130 if (capacity == 0) return *this; 125 131 values = allocator.allocate(capacity); 132 126 133 for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) { 127 134 int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it); 128 135 allocator.construct(&(values[id]), copy.values[id]); 129 136 } 137 130 138 return *this; 131 139 } 132 140 133 /** Assign operator to copy a map an other map type. 134 */ 135 template <typename CMap> ArrayMap& operator=(const CMap& copy) { 141 /** Assign operator to copy a map of an other map type. 142 */ 143 template <typename TT> 144 ArrayMap& operator=(const ArrayMap<MapRegistry, TT>& copy) { 136 145 if (capacity != 0) { 137 146 MapBase::destroy(); 138 147 allocator.deallocate(values, capacity); 139 148 } 149 140 150 MapBase::operator=(copy); 141 if (MapBase::getGraph()) { 142 allocate_memory(); 143 for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) { 144 set(it, copy[it]); 145 } 146 } 151 152 capacity = copy.capacity; 153 if (capacity == 0) return *this; 154 values = allocator.allocate(capacity); 155 156 for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) { 157 int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it); 158 allocator.construct(&(values[id]), copy.values[id]); 159 } 160 147 161 return *this; 148 162 }
Note: See TracChangeset
for help on using the changeset viewer.