File indexing completed on 2026-04-04 08:15:00
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef GTL_NE_MAP_H
0010 #define GTL_NE_MAP_H
0011
0012 #include <GTL/GTL.h>
0013
0014 #include <vector>
0015 #include <cassert>
0016
0017
0018
0019
0020
0021 __GTL_BEGIN_NAMESPACE
0022
0023
0024
0025
0026
0027
0028
0029
0030 template <class Key, class Value, class Graph, class Alloc = allocator<Value> >
0031 class ne_map
0032 {
0033 protected:
0034
0035
0036
0037
0038
0039
0040
0041 ne_map();
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054 explicit ne_map(const Graph &g, Value def=Value());
0055
0056
0057
0058 public:
0059
0060
0061
0062
0063
0064
0065
0066
0067 void init(const Graph &, Value def=Value());
0068
0069
0070
0071
0072 #if defined(__GTL_MSVCC) && _MSC_VER < 1310
0073 typedef Value& value_reference;
0074 #else
0075 typedef typename vector<Value, Alloc>::reference value_reference;
0076 #endif
0077
0078
0079
0080
0081 #if defined(__GTL_MSVCC) && _MSC_VER < 1310
0082 typedef const Value& const_value_reference;
0083 #else
0084 typedef typename vector<Value, Alloc>::const_reference const_value_reference;
0085 #endif
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104 value_reference operator[](Key key);
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121 const_value_reference operator[](Key key) const;
0122
0123
0124
0125
0126 void clear ();
0127
0128
0129
0130 private:
0131 vector<Value, Alloc> data;
0132 };
0133
0134
0135
0136 template <class Key, class Value, class Graph, class Alloc>
0137 ne_map<Key,Value,Graph,Alloc>::ne_map()
0138 {
0139 }
0140
0141 template <class Key, class Value, class Graph, class Alloc>
0142 ne_map<Key,Value,Graph,Alloc>::ne_map(const Graph &g, Value t2) :
0143 data(g.number_of_ids(Key()), t2)
0144 {
0145 }
0146
0147 template <class Key, class Value, class Graph, class Alloc>
0148 void ne_map<Key,Value,Graph,Alloc>::init(const Graph &g, Value t2)
0149 {
0150 int n = g.number_of_ids(Key());
0151 data.resize(n);
0152 fill_n(data.begin(), n, t2);
0153 }
0154
0155 template <class Key, class Value, class Graph, class Alloc>
0156 typename ne_map<Key,Value,Graph,Alloc>::value_reference ne_map<Key,Value,Graph,Alloc>::operator[](Key t1)
0157 {
0158 if(t1.id() >= (signed)data.size())
0159 {
0160 if (t1.id() >= (signed)data.capacity()) {
0161 data.reserve((6 * t1.id()) / 5 + 1);
0162 }
0163
0164 data.insert(data.end(), t1.id()+1-data.size(), Value());
0165 }
0166 return data.operator[](t1.id());
0167 }
0168
0169 template <class Key, class Value, class Graph, class Alloc>
0170 typename ne_map<Key,Value,Graph,Alloc>::const_value_reference ne_map<Key,Value,Graph,Alloc>::operator[](Key t1) const
0171 {
0172 assert(t1.id() < (signed)data.size());
0173 return data.operator[](t1.id());
0174 }
0175
0176 template <class Key, class Value, class Graph, class Alloc>
0177 void ne_map<Key,Value,Graph,Alloc>::clear ()
0178 {
0179 data.clear();
0180 }
0181
0182
0183
0184 __GTL_END_NAMESPACE
0185
0186 #endif
0187
0188
0189
0190