78 if (start >= end)
return;
80 map<void *, void *>::iterator lb;
81 map<void *, void *>::iterator ub;
83 lb = mymap.upper_bound(start);
84 ub = mymap.upper_bound(end);
88 bool overlaps = (lb != ub);
90 if (lb != mymap.begin()) {
92 if (start <= (*lb).second) {
99 if (ub != mymap.begin()) {
101 if (end <= (*ub).second) {
127 pair<void *const, void *> *
130 map<void *, void *>::iterator up;
131 up = mymap.upper_bound(i);
132 if (up != mymap.begin()) {
134 if (i >= (*up).first && i < (*up).second)
return &(*up);
158 map<void *, void *>::iterator it;
159 cout <<
"intervals: ";
160 for (it = mymap.begin(); it != mymap.end(); it++)
161 cout <<
"[" << (*it).first <<
"," << (*it).second <<
") ";
175 test_interval_set_insert(
unsigned long start,
unsigned long end)
177 void *vstart = (
void *) start;
178 void *vend = (
void *) end;
179 cout <<
"inserting [" << vstart <<
"," << vend <<
")" << endl;
180 ranges.
insert(vstart, vend);
186 test_interval_set_contains(
unsigned long i)
188 pair<void *const, void *> *result = ranges.
contains((
void *) i);
189 cout <<
"search for " << i <<
": ";
191 cout <<
"found interval [" << result->first <<
","<< result->second <<
")";
192 else cout <<
"no interval found";
199 test_interval_set_insert(10,20);
202 test_interval_set_insert(5,7);
205 test_interval_set_insert(30,32);
208 test_interval_set_insert(20,28);
211 test_interval_set_insert(60,89);
214 test_interval_set_insert(27,45);
217 test_interval_set_insert(57,61);
220 test_interval_set_insert(41,58);
223 test_interval_set_insert(1,90);
226 test_interval_set_insert(94,99);
229 test_interval_set_insert(100,110);
232 test_interval_set_insert(115,120);
235 test_interval_set_insert(140,145);
238 test_interval_set_insert(155,165);
241 test_interval_set_insert(95,142);
244 test_interval_set_insert(93,186);
247 test_interval_set_insert(92,187);
249 test_interval_set_contains(72);
250 test_interval_set_contains(21);
251 test_interval_set_contains(33);
252 test_interval_set_contains(12);
253 test_interval_set_contains(96);
254 test_interval_set_contains(8);
255 test_interval_set_contains(0);
256 test_interval_set_contains(200);
257 test_interval_set_contains(91);
void insert(void *start, void *end)
int main(int argc, char *argv[])
std::pair< void *const, void * > * contains(void *i)