63 template<
typename _recordtype>
66 typedef typename _recordtype::linetype
linetype;
68 typedef typename _recordtype::inittype
inittype;
76 friend class PartIterator;
82 mutable typename std::list<_recordtype>::iterator value;
83 AddrRange(
linetype l) : subsort(
false) { last = l; }
86 bool operator<(
const AddrRange &op2)
const {
87 if (last != op2.last)
return (last < op2.last);
88 return (subsort < op2.subsort);
90 typename std::list<_recordtype>::iterator getValue(
void)
const {
return value; }
100 typename std::multiset<AddrRange>::const_iterator iter;
103 PartIterator(
typename std::multiset<AddrRange>::const_iterator i) { iter=i; }
104 _recordtype &operator*(
void) {
return *(*iter).value; }
105 PartIterator &operator++(
void) { ++iter;
return *
this; }
108 PartIterator &operator--(
void) { --iter;
return *
this; }
112 iter = op2.iter;
return *
this;
115 return (iter==op2.iter);
118 return (iter!=op2.iter);
120 typename std::list<_recordtype>::iterator getValueIter(
void)
const {
121 return (*iter).getValue(); }
127 std::multiset<AddrRange> tree;
128 std::list<_recordtype> record;
130 void zip(
linetype i,
typename std::multiset<AddrRange>::iterator iter);
131 void unzip(
linetype i,
typename std::multiset<AddrRange>::iterator iter);
133 bool empty(
void)
const {
return record.empty(); }
134 void clear(
void) { tree.clear(); record.clear(); }
135 typename std::list<_recordtype>::const_iterator begin_list(
void)
const {
return record.begin(); }
136 typename std::list<_recordtype>::const_iterator end_list(
void)
const {
return record.end(); }
137 typename std::list<_recordtype>::iterator begin_list(
void) {
return record.begin(); }
138 typename std::list<_recordtype>::iterator end_list(
void) {
return record.end(); }
140 const_iterator begin(
void)
const {
return PartIterator(tree.begin()); }
141 const_iterator end(
void)
const {
return PartIterator(tree.end()); }
144 std::pair<const_iterator,const_iterator>
find(
linetype a)
const;
147 std::pair<const_iterator,const_iterator>
163 void erase(
typename std::list<_recordtype>::iterator v);
174 template<
typename _recordtype>
178 linetype f = (*iter).first;
179 while((*iter).last == i)
182 while((iter!=tree.end())&&((*iter).first==i)) {
193 template<
typename _recordtype>
197 typename std::multiset<AddrRange>::iterator hint = iter;
198 if ((*iter).last == i)
return;
200 linetype plus1 = i+1;
201 while((iter!=tree.end())&&((*iter).first<=i)) {
203 (*iter).first = plus1;
204 typename std::multiset<AddrRange>::iterator newiter;
205 newiter = tree.
insert(hint,AddrRange(i,(*iter).subsort));
206 const AddrRange &newrange( *newiter );
208 newrange.a = (*iter).a;
209 newrange.b = (*iter).b;
210 newrange.value = (*iter).value;
219 template<
typename _recordtype>
220 typename std::list<_recordtype>::iterator
225 typename std::list<_recordtype>::iterator liter;
226 typename std::multiset<AddrRange>::iterator low = tree.lower_bound(AddrRange(f));
228 if (low != tree.end()) {
229 if ((*low).first < f)
233 record.emplace_front( data, a, b );
234 liter = record.begin();
236 AddrRange addrrange(b,(*liter).getSubsort());
239 addrrange.value = liter;
240 typename std::multiset<AddrRange>::iterator spot = tree.lower_bound(addrrange);
242 record.splice( (spot==tree.end()) ? record.end():(*spot).value,
245 while((low != tree.end())&&((*low).first<=b)) {
246 if (f <= (*low).last) {
247 if (f < (*low).first) {
250 addrrange.last = (*low).first-1;
251 tree.insert(low,addrrange);
254 if ((*low).last <= b) {
256 addrrange.last = (*low).last;
257 tree.insert(low,addrrange);
258 if ((*low).last==b)
break;
261 else if (b < (*low).last) {
271 tree.insert(addrrange);
278 template<
typename _recordtype>
285 bool rightsew =
true;
286 bool rightoverlap =
false;
287 bool leftoverlap =
false;
288 typename std::multiset<AddrRange>::iterator low = tree.lower_bound(AddrRange(a));
289 typename std::multiset<AddrRange>::iterator uplow = low;
292 while (uplow != tree.begin()) {
294 if ((*uplow).last != aminus1)
break;
295 if ((*uplow).b == aminus1) {
301 if ((*low).value == v)
306 else if ((*low).a == a)
310 else if ((*low).b == b)
314 }
while ((low != tree.end())&&((*low).first<=b));
315 if (low != tree.end()) {
319 if (leftsew&&leftoverlap)
320 zip(a-1,tree.lower_bound(AddrRange(a-1)));
321 if (rightsew&&rightoverlap)
322 zip(b,tree.lower_bound(AddrRange(b)));
328 template<
typename _recordtype>
333 AddrRange addrrange(point);
334 typename std::multiset<AddrRange>::const_iterator iter1,iter2;
336 iter1 = tree.lower_bound(addrrange);
338 if ((iter1==tree.end())||(point < (*iter1).first))
339 return std::pair<PartIterator,PartIterator>(PartIterator(iter1),PartIterator(iter1));
341 AddrRange addrend((*iter1).last,
subsorttype(
true));
342 iter2 = tree.upper_bound(addrend);
344 return std::pair<PartIterator,PartIterator>(PartIterator(iter1),PartIterator(iter2));
351 template<
typename _recordtype>
356 AddrRange addrrange(point,sub1);
357 typename std::multiset<AddrRange>::const_iterator iter1,iter2;
359 iter1 = tree.lower_bound(addrrange);
360 if ((iter1==tree.end())||(point < (*iter1).first))
361 return std::pair<PartIterator,PartIterator>(PartIterator(iter1),PartIterator(iter1));
363 AddrRange addrend((*iter1).last,sub2);
364 iter2 = tree.upper_bound(addrend);
366 return std::pair<PartIterator,PartIterator>(PartIterator(iter1),PartIterator(iter2));
371 template<
typename _recordtype>
376 AddrRange addrrange(point);
377 typename std::multiset<AddrRange>::const_iterator iter;
379 iter = tree.lower_bound(addrrange);
385 template<
typename _recordtype>
391 typename std::multiset<AddrRange>::const_iterator iter;
393 iter = tree.upper_bound(addrend);
394 if ((iter==tree.end())||(point < (*iter).first))
400 AddrRange addrbeyond((*iter).last,
subsorttype(
true));
401 return tree.upper_bound(addrbeyond);
407 template<
typename _recordtype>
412 AddrRange addrrange(point);
413 typename std::multiset<AddrRange>::const_iterator iter;
416 iter = tree.lower_bound(addrrange);
417 if (iter==tree.end())
return iter;
418 if ((*iter).first<=end)