28 #ifndef _util_container_avlmmap_h
29 #define _util_container_avlmmap_h
41 template <
class K,
class T>
44 std::pair<K,T> keyval;
50 AVLMMapNode(
const std::pair<K,T> &kv): keyval(kv) {}
51 AVLMMapNode(
const K& k,
const T&v): keyval(std::make_pair(k,v)) {}
52 K& key() {
return keyval.first; }
53 const K& key()
const {
return keyval.first; }
54 T& val() {
return keyval.second; }
55 const T& val()
const {
return keyval.second; }
60 enum {default_chunksize = 4096};
66 chunk(
int _chunksize,
int datasize) {
67 data =
new char[_chunksize*datasize];
70 chunksize = _chunksize;
81 head =
new chunk(default_chunksize,
sizeof(T));
85 std::cout <<
"chunks remain: " << total << std::endl;
88 for (chunk *i = head; i;) {
89 chunk *next = i->next;
96 std::cout <<
"reinit: chunks remain: " << total << std::endl;
99 for (chunk *i = head; i;) {
100 chunk *next = i->next;
104 head =
new chunk(default_chunksize,
sizeof(T));
109 void deallocate(T*d,
int n) {
116 if (head->current == head->chunksize) {
117 chunk *newhead =
new chunk(default_chunksize,
sizeof(T));
118 newhead->next = head;
121 T *r = &((T*)head->data)[head->current];
127 chunk *newchunk =
new chunk(n,
sizeof(T));
128 newchunk->next = head->next;
129 head->next = newchunk;
131 return (T*)newchunk->data;
142 bool operator()(
const T&a,
const T&b)
const {
145 int compare(
const T&a,
const T&b)
const {
146 if (a < b)
return -1;
147 else if (a > b)
return 1;
152 template <
class K,
class T,
class C = tristate_less<K>,
153 class A = chunk_allocator<AVLMMapNode<K,T> > >
173 int compare(
const K&n,
const K&m)
const {
174 return key_comp_.compare(n,m);
185 typedef C key_compare;
186 typedef std::pair<K,T> value_type;
195 void operator++(
int) { operator++(); }
197 {
return node == i.node; }
199 {
return node != i.node; }
202 const K &key()
const {
return node->key(); }
203 std::pair<K,T> & operator *() {
return node->keyval; }
204 std::pair<K,T> * operator->() {
return &node->keyval; }
215 void operator++(
int) { operator++(); }
217 {
return node == i.node; }
219 {
return node != i.node; }
222 const K &key()
const {
return node->key(); }
223 const std::pair<K,T> & operator *() {
return node->keyval; }
224 const std::pair<K,T> * operator->() {
return &node->keyval; }
230 const std::pair<K,T> &ipair);
238 key_compare key_comp()
const {
return key_comp_; }
249 new((
void*)&alloc_)A;
253 iterator insert_new(
const iterator &hint,
const std::pair<K,T> &ipair);
262 iterator insert_equal(
const iterator &hint,
const std::pair<K,T> &ipair);
264 iterator insert_new(
const std::pair<K,T> &ipair);
267 iterator insert_equal(
const std::pair<K,T> &ipair);
271 iterator insert_unique(
const std::pair<K,T> &ipair);
273 iterator insert(
const std::pair<K,T> &ipair) {
return insert_equal(ipair); }
275 iterator insert(
const iterator &hint,
const std::pair<K,T> &ipair) {
return insert_equal(hint, ipair); }
278 void insert(
const const_iterator &b,
const const_iterator &e) {
279 for (const_iterator i = b; i != e; i++) insert(*i);
282 void remove(AVLMMapNode<K,T>*);
283 iterator find(
const K&);
284 const_iterator find(
const K&)
const;
285 iterator find(
const iterator &hint,
const K&);
286 const_iterator find(
const const_iterator &hint,
const K&)
const;
288 void erase(
const iterator &i) { remove(i.node); }
290 int height(AVLMMapNode<K,T>* node);
291 int height() {
return height(root_); }
293 void check_node(AVLMMapNode<K,T>*)
const;
295 AVLMMapNode<K,T>* start()
const {
return start_; }
296 static void next(
const AVLMMapNode<K,T>*&);
297 static void next(AVLMMapNode<K,T>*&);
299 iterator begin() {
return iterator(start()); }
300 const_iterator begin()
const {
return const_iterator(start()); }
302 iterator end() {
return iterator(0); }
303 const_iterator end()
const {
return const_iterator(0); }
305 const_iterator lower_bound(
const K& k)
const;
306 const_iterator upper_bound(
const K& k)
const;
307 std::pair<const_iterator,const_iterator> equal_range(
const K& k)
const;
309 void print(std::ostream &o = std::cout)
const;
310 size_t size()
const {
return length_; }
311 int depth(AVLMMapNode<K,T>*)
const;
314 template <
class K,
class T,
class C,
class A>
315 std::pair<typename AVLMMap<K,T,C,A>::const_iterator,
316 typename AVLMMap<K,T,C,A>::const_iterator>
317 AVLMMap<K,T,C,A>::equal_range(
const K& __k)
const
321 link_type __x = root_;
324 int cmp = compare(key(__x), __k);
330 else if (cmp == -1) {
335 link_type __saved_x = __x;
337 __lb = __x, __x = llink(__x);
339 if (!key_comp_(key(__x), __k))
340 __lb = __x, __x = llink(__x);
347 if (key_comp_(__k, key(__x)))
348 __ub = __x, __x = llink(__x);
354 typedef typename AVLMMap<K,T,C,A>::const_iterator iterator;
355 return std::pair<iterator,iterator>(__lb, __ub);
358 template <
class K,
class T,
class C,
class A>
359 typename AVLMMap<K,T,C,A>::const_iterator
360 AVLMMap<K,T,C,A>::lower_bound(
const K& __k)
const
364 link_type __x = root_;
367 if (!key_comp_(key(__x), __k))
368 __y = __x, __x = llink(__x);
372 return const_iterator(__y);
375 template <
class K,
class T,
class C,
class A>
376 typename AVLMMap<K,T,C,A>::const_iterator
377 AVLMMap<K,T,C,A>::upper_bound(
const K& __k)
const
381 link_type __x = root_;
384 if (key_comp_(__k, key(__x)))
385 __y = __x, __x = llink(__x);
389 return const_iterator(__y);
392 template <
class K,
class T,
class C,
class A>
393 inline typename AVLMMap<K,T,C,A>::iterator
394 AVLMMap<K,T,C,A>::find(
const K& k)
396 return subtree_find_(root_,k);
399 template <
class K,
class T,
class C,
class A>
400 inline typename AVLMMap<K,T,C,A>::const_iterator
401 AVLMMap<K,T,C,A>::find(
const K& k)
const
403 return subtree_find_(root_,k);
406 template <
class K,
class T,
class C,
class A>
407 inline typename AVLMMap<K,T,C,A>::iterator
408 AVLMMap<K,T,C,A>::find(
const iterator &hint,
const K& k)
410 AVLMMapNode<K,T> *x = hint.node;
411 if (x == 0)
return subtree_find_(root_,k);
412 AVLMMapNode<K,T> *y = uplink(x);
414 int cmp = compare(k, key(x));
415 if (cmp == 0)
return x;
416 int cmp2 = compare(k, key(y));
417 if (cmp2 == 0)
return y;
418 if (cmp == -1 && cmp2 == 1) {
419 return subtree_find_(llink(x), k);
421 else if (cmp == 1 && cmp2 == -1) {
422 return subtree_find_(rlink(x), k);
428 return subtree_find_(x,k);
431 template <
class K,
class T,
class C,
class A>
432 inline typename AVLMMap<K,T,C,A>::const_iterator
433 AVLMMap<K,T,C,A>::find(
const const_iterator &hint,
const K& k)
const
435 const AVLMMapNode<K,T> *x = hint.node;
436 if (x == 0)
return subtree_find_(root_,k);
437 const AVLMMapNode<K,T> *y = uplink(x);
439 int cmp = compare(k, key(x));
440 if (cmp == 0)
return x;
441 int cmp2 = compare(k, key(y));
442 if (cmp2 == 0)
return y;
443 if (cmp == -1 && cmp2 == 1) {
444 return subtree_find_(llink(x), k);
446 else if (cmp == 1 && cmp2 == -1) {
447 return subtree_find_(rlink(x), k);
453 return subtree_find_(x,k);
456 template <
class K,
class T,
class C,
class A>
457 typename AVLMMap<K,T,C,A>::iterator
458 AVLMMap<K,T,C,A>::subtree_find_(AVLMMapNode<K,T> *root,
const K& k)
460 AVLMMapNode<K,T>* n = root;
463 int cmp = compare(key(n), k);
464 if (cmp < 0) n = rlink(n);
465 else if (cmp > 0) n = llink(n);
466 else return iterator(n);
472 template <
class K,
class T,
class C,
class A>
473 typename AVLMMap<K,T,C,A>::const_iterator
474 AVLMMap<K,T,C,A>::subtree_find_(
const AVLMMapNode<K,T> *root,
const K& k)
const
476 const AVLMMapNode<K,T>* n = root;
479 int cmp = compare(key(n), k);
480 if (cmp < 0) n = rlink(n);
481 else if (cmp > 0) n = llink(n);
482 else return const_iterator(n);
485 return const_iterator(0);
488 template <
class K,
class T,
class C,
class A>
490 AVLMMap<K,T,C,A>::remove(AVLMMapNode<K,T>* node)
496 if (node == start_) {
500 AVLMMapNode<K,T> *rebalance_point;
503 if (llink(node) == 0) {
505 rebalance_point = uplink(node);
507 if (q) uplink(q) = rebalance_point;
509 if (rebalance_point) {
510 if (rlink(rebalance_point) == node) rlink(rebalance_point) = q;
511 else llink(rebalance_point) = q;
515 else if (rlink(node) == 0) {
517 rebalance_point = uplink(node);
519 if (q) uplink(q) = rebalance_point;
521 if (rebalance_point) {
522 if (rlink(rebalance_point) == node) rlink(rebalance_point) = q;
523 else llink(rebalance_point) = q;
528 AVLMMapNode<K,T> *r = node;
531 if (r == 0 || llink(r) != 0) {
532 throw std::runtime_error(
"AVLMMap::remove: inconsistency");
535 if (r == rlink(node)) {
536 llink(r) = llink(node);
537 if (llink(r)) uplink(llink(r)) = r;
538 balance(r) = balance(node);
545 rebalance_point = uplink(r);
547 if (llink(rebalance_point) == r) llink(rebalance_point) = q;
548 else rlink(rebalance_point) = q;
550 if (q) uplink(q) = rebalance_point;
552 balance(r) = balance(node);
553 rlink(r) = rlink(node);
554 llink(r) = llink(node);
555 if (rlink(r)) uplink(rlink(r)) = r;
556 if (llink(r)) uplink(llink(r)) = r;
559 AVLMMapNode<K,T>* up = uplink(node);
562 if (rlink(up) == node) rlink(up) = r;
565 if (up == 0) root_ = r;
571 if (rebalance_point &&
572 llink(rebalance_point) == 0 && rlink(rebalance_point) == 0) {
573 balance(rebalance_point) = 0;
575 rebalance_point = uplink(rebalance_point);
577 adjust_balance_remove(rebalance_point, q);
579 alloc_.destroy(node);
580 alloc_.deallocate(node,1);
583 template <
class K,
class T,
class C,
class A>
585 AVLMMap<K,T,C,A>::print(std::ostream &o)
const
587 std::cout <<
"--------------------------" << std::endl;
588 for (AVLMMapNode<K,T>*n=start(); n; next(n)) {
589 int d = depth(n) + 1;
590 for (
int i=0; i<d; i++) o <<
" ";
591 if (balance(n) == 1) o <<
" (+) " << key(n) << std::endl;
592 else if (balance(n) == -1) o <<
" (-) " << key(n) << std::endl;
593 else if (balance(n) == 0) o <<
" (.) " << key(n) << std::endl;
594 else o <<
" (" << balance(n) <<
") " << key(n) << std::endl;
598 template <
class K,
class T,
class C,
class A>
600 AVLMMap<K,T,C,A>::depth(AVLMMapNode<K,T>*node)
const
610 template <
class K,
class T,
class C,
class A>
612 AVLMMap<K,T,C,A>::check_node(AVLMMapNode<K,T>*n)
const
614 if (uplink(n) && uplink(n) == n) abort();
615 if (llink(n) && llink(n) == n) abort();
616 if (rlink(n) && rlink(n) == n) abort();
617 if (rlink(n) && rlink(n) == llink(n)) abort();
618 if (uplink(n) && uplink(n) == llink(n)) abort();
619 if (uplink(n) && uplink(n) == rlink(n)) abort();
620 if (uplink(n) && !(llink(uplink(n)) == n
621 || rlink(uplink(n)) == n)) abort();
624 template <
class K,
class T,
class C,
class A>
626 AVLMMap<K,T,C,A>::clear(AVLMMapNode<K,T>*n)
632 alloc_.deallocate(n,1);
635 template <
class K,
class T,
class C,
class A>
637 AVLMMap<K,T,C,A>::height(AVLMMapNode<K,T>* node)
640 int rh = height(rlink(node)) + 1;
641 int lh = height(llink(node)) + 1;
645 template <
class K,
class T,
class C,
class A>
647 AVLMMap<K,T,C,A>::check()
649 AVLMMapNode<K,T>* node;
650 AVLMMapNode<K,T>* prev=0;
651 size_t computed_length = 0;
652 for (node = start(); node; next(node)) {
654 if (prev && compare(key(prev),key(node)) > 0) {
655 throw std::runtime_error(
"nodes out of order");
660 for (node = start(); node; next(node)) {
661 if (balance(node) != height(rlink(node)) - height(llink(node))) {
662 throw std::runtime_error(
"balance inconsistency");
664 if (balance(node) < -1 || balance(node) > 1) {
665 throw std::runtime_error(
"balance out of range");
668 if (length_ != computed_length) {
669 throw std::runtime_error(
"length error");
673 template <
class K,
class T,
class C,
class A>
675 AVLMMap<K,T,C,A>::next(
const AVLMMapNode<K,T>*& node)
677 const AVLMMapNode<K,T>* r;
678 if ((r = rlink(node))) {
680 while ((r = llink(node))) node = r;
683 while ((r = uplink(node))) {
684 if (node == llink(r)) {
693 template <
class K,
class T,
class C,
class A>
695 AVLMMap<K,T,C,A>::next(AVLMMapNode<K,T>*& node)
698 if ((r = rlink(node))) {
700 while ((r = llink(node))) node = r;
703 while ((r = uplink(node))) {
704 if (node == llink(r)) {
713 template <
class K,
class T,
class C,
class A>
714 typename AVLMMap<K,T,C,A>::iterator
715 AVLMMap<K,T,C,A>::insert_equal(
const iterator &hint,
const std::pair<K,T> &ipair)
717 AVLMMapNode<K,T>* n = alloc_.allocate(1);
718 new((
void*)n)AVLMMapNode<K,T>(ipair);
724 AVLMMapNode<K,T> *x = hint.node;
725 if (x == 0)
return subtree_insert_equal_(root_,n);
726 AVLMMapNode<K,T> *y = uplink(x);
728 int cmp = compare(key(n), key(x));
729 if (cmp == 0)
return subtree_insert_equal_(x, n);
730 int cmp2 = compare(key(n), key(y));
731 if (cmp2 == 0)
return subtree_insert_equal_(y, n);
732 if (cmp == -1 && cmp2 == 1) {
734 if (y != 0)
return subtree_insert_equal_(y, n);
738 adjust_balance_insert(x,n);
742 else if (cmp == 1 && cmp2 == -1) {
744 if (y != 0)
return subtree_insert_equal_(y, n);
748 adjust_balance_insert(x,n);
756 return subtree_insert_equal_(x, n);
759 template <
class K,
class T,
class C,
class A>
760 typename AVLMMap<K,T,C,A>::iterator
761 AVLMMap<K,T,C,A>::insert_new(
const iterator &hint,
const std::pair<K,T> &ipair)
763 AVLMMapNode<K,T>* n = alloc_.allocate(1);
764 new((
void*)n)AVLMMapNode<K,T>(ipair);
770 AVLMMapNode<K,T> *x = hint.node;
771 if (x == 0)
return subtree_insert_new_(root_,n);
772 AVLMMapNode<K,T> *y = uplink(x);
774 bool cmp = key_comp_(key(n), key(x));
775 bool cmp2 = key_comp_(key(n), key(y));
778 if (y != 0)
return subtree_insert_new_(y, n);
782 adjust_balance_insert(x,n);
786 else if (!cmp && cmp2) {
788 if (y != 0)
return subtree_insert_new_(y, n);
792 adjust_balance_insert(x,n);
800 return subtree_insert_new_(x, n);
803 template <
class K,
class T,
class C,
class A>
804 inline typename AVLMMap<K,T,C,A>::iterator
805 AVLMMap<K,T,C,A>::insert_equal(
const std::pair<K,T> &ipair)
807 AVLMMapNode<K,T>* n = alloc_.allocate(1);
808 new((
void*)n)AVLMMapNode<K,T>(ipair);
810 return subtree_insert_equal_(root_, n);
813 template <
class K,
class T,
class C,
class A>
814 inline typename AVLMMap<K,T,C,A>::iterator
815 AVLMMap<K,T,C,A>::insert_unique(
const std::pair<K,T> &ipair)
817 return subtree_insert_unique_(root_, ipair);
820 template <
class K,
class T,
class C,
class A>
821 inline typename AVLMMap<K,T,C,A>::iterator
822 AVLMMap<K,T,C,A>::insert_new(
const std::pair<K,T> &ipair)
824 AVLMMapNode<K,T>* n = alloc_.allocate(1);
825 new((
void*)n)AVLMMapNode<K,T>(ipair);
833 return subtree_insert_new_(root_, n);
836 template <
class K,
class T,
class C,
class A>
837 typename AVLMMap<K,T,C,A>::iterator
838 AVLMMap<K,T,C,A>::subtree_insert_equal_(AVLMMapNode<K,T> *root,
856 AVLMMapNode<K,T>* p = root;
857 AVLMMapNode<K,T>* prev_p = 0;
864 cmp = compare(key(n),key(p));
865 if (cmp < 0) p = llink(p);
876 if (prev_p == start_) start_ = n;
878 else rlink(prev_p) = n;
883 adjust_balance_insert(prev_p, n);
889 template <
class K,
class T,
class C,
class A>
890 typename AVLMMap<K,T,C,A>::iterator
891 AVLMMap<K,T,C,A>::subtree_insert_unique_(AVLMMapNode<K,T> *root,
892 const std::pair<K,T> &ipair)
896 AVLMMapNode<K,T>* n = alloc_.allocate(1);
897 new((
void*)n)AVLMMapNode<K,T>(ipair);
911 AVLMMapNode<K,T>* p = root;
912 AVLMMapNode<K,T>* prev_p = 0;
916 cmp = compare(ipair.first,key(p));
917 if (cmp < 0) p = llink(p);
927 AVLMMapNode<K,T>* n = alloc_.allocate(1);
928 new((
void*)n)AVLMMapNode<K,T>(ipair);
941 if (prev_p == start_) start_ = n;
943 else rlink(prev_p) = n;
948 adjust_balance_insert(prev_p, n);
954 template <
class K,
class T,
class C,
class A>
955 typename AVLMMap<K,T,C,A>::iterator
956 AVLMMap<K,T,C,A>::subtree_insert_new_(AVLMMapNode<K,T> *root,
968 AVLMMapNode<K,T>* p = root;
969 AVLMMapNode<K,T>* prev_p = 0;
973 cmp = key_comp_(key(n),key(p));
974 if (cmp) p = llink(p);
985 if (prev_p == start_) start_ = n;
987 else rlink(prev_p) = n;
992 adjust_balance_insert(prev_p, n);
998 template <
class K,
class T,
class C,
class Alloc>
1000 AVLMMap<K,T,C,Alloc>::adjust_balance_insert(AVLMMapNode<K,T>* A, AVLMMapNode<K,T>* child)
1004 if (llink(A) == child) adjustment = -1;
1005 else adjustment = 1;
1006 int bal = balance(A) + adjustment;
1010 else if (bal == -1 || bal == 1) {
1012 adjust_balance_insert(uplink(A), A);
1014 else if (bal == 2) {
1015 AVLMMapNode<K,T>* B = rlink(A);
1016 if (balance(B) == 1) {
1019 rlink(A) = llink(B);
1021 uplink(B) = uplink(A);
1023 if (rlink(A)) uplink(rlink(A)) = A;
1024 if (llink(B)) uplink(llink(B)) = B;
1025 if (uplink(B) == 0) root_ = B;
1027 if (rlink(uplink(B)) == A) rlink(uplink(B)) = B;
1028 else llink(uplink(B)) = B;
1032 AVLMMapNode<K,T>* X = llink(B);
1033 rlink(A) = llink(X);
1034 llink(B) = rlink(X);
1037 if (balance(X) == 1) {
1041 else if (balance(X) == -1) {
1050 uplink(X) = uplink(A);
1053 if (rlink(A)) uplink(rlink(A)) = A;
1054 if (llink(B)) uplink(llink(B)) = B;
1055 if (uplink(X) == 0) root_ = X;
1057 if (rlink(uplink(X)) == A) rlink(uplink(X)) = X;
1058 else llink(uplink(X)) = X;
1062 else if (bal == -2) {
1063 AVLMMapNode<K,T>* B = llink(A);
1064 if (balance(B) == -1) {
1067 llink(A) = rlink(B);
1069 uplink(B) = uplink(A);
1071 if (llink(A)) uplink(llink(A)) = A;
1072 if (rlink(B)) uplink(rlink(B)) = B;
1073 if (uplink(B) == 0) root_ = B;
1075 if (llink(uplink(B)) == A) llink(uplink(B)) = B;
1076 else rlink(uplink(B)) = B;
1080 AVLMMapNode<K,T>* X = rlink(B);
1081 llink(A) = rlink(X);
1082 rlink(B) = llink(X);
1085 if (balance(X) == -1) {
1089 else if (balance(X) == 1) {
1098 uplink(X) = uplink(A);
1101 if (llink(A)) uplink(llink(A)) = A;
1102 if (rlink(B)) uplink(rlink(B)) = B;
1103 if (uplink(X) == 0) root_ = X;
1105 if (llink(uplink(X)) == A) llink(uplink(X)) = X;
1106 else rlink(uplink(X)) = X;
1112 template <
class K,
class T,
class C,
class Alloc>
1114 AVLMMap<K,T,C,Alloc>::adjust_balance_remove(AVLMMapNode<K,T>* A, AVLMMapNode<K,T>* child)
1118 if (llink(A) == child) adjustment = 1;
1119 else adjustment = -1;
1120 int bal = balance(A) + adjustment;
1123 adjust_balance_remove(uplink(A), A);
1125 else if (bal == -1 || bal == 1) {
1128 else if (bal == 2) {
1129 AVLMMapNode<K,T>* B = rlink(A);
1130 if (balance(B) == 0) {
1133 rlink(A) = llink(B);
1135 uplink(B) = uplink(A);
1137 if (rlink(A)) uplink(rlink(A)) = A;
1138 if (llink(B)) uplink(llink(B)) = B;
1139 if (uplink(B) == 0) root_ = B;
1141 if (rlink(uplink(B)) == A) rlink(uplink(B)) = B;
1142 else llink(uplink(B)) = B;
1145 else if (balance(B) == 1) {
1148 rlink(A) = llink(B);
1150 uplink(B) = uplink(A);
1152 if (rlink(A)) uplink(rlink(A)) = A;
1153 if (llink(B)) uplink(llink(B)) = B;
1154 if (uplink(B) == 0) root_ = B;
1156 if (rlink(uplink(B)) == A) rlink(uplink(B)) = B;
1157 else llink(uplink(B)) = B;
1159 adjust_balance_remove(uplink(B), B);
1162 AVLMMapNode<K,T>* X = llink(B);
1163 rlink(A) = llink(X);
1164 llink(B) = rlink(X);
1167 if (balance(X) == 0) {
1171 else if (balance(X) == 1) {
1180 uplink(X) = uplink(A);
1183 if (rlink(A)) uplink(rlink(A)) = A;
1184 if (llink(B)) uplink(llink(B)) = B;
1185 if (uplink(X) == 0) root_ = X;
1187 if (rlink(uplink(X)) == A) rlink(uplink(X)) = X;
1188 else llink(uplink(X)) = X;
1190 adjust_balance_remove(uplink(X), X);
1193 else if (bal == -2) {
1194 AVLMMapNode<K,T>* B = llink(A);
1195 if (balance(B) == 0) {
1198 llink(A) = rlink(B);
1200 uplink(B) = uplink(A);
1202 if (llink(A)) uplink(llink(A)) = A;
1203 if (rlink(B)) uplink(rlink(B)) = B;
1204 if (uplink(B) == 0) root_ = B;
1206 if (llink(uplink(B)) == A) llink(uplink(B)) = B;
1207 else rlink(uplink(B)) = B;
1210 else if (balance(B) == -1) {
1213 llink(A) = rlink(B);
1215 uplink(B) = uplink(A);
1217 if (llink(A)) uplink(llink(A)) = A;
1218 if (rlink(B)) uplink(rlink(B)) = B;
1219 if (uplink(B) == 0) root_ = B;
1221 if (llink(uplink(B)) == A) llink(uplink(B)) = B;
1222 else rlink(uplink(B)) = B;
1224 adjust_balance_remove(uplink(B), B);
1227 AVLMMapNode<K,T>* X = rlink(B);
1228 llink(A) = rlink(X);
1229 rlink(B) = llink(X);
1232 if (balance(X) == 0) {
1236 else if (balance(X) == -1) {
1245 uplink(X) = uplink(A);
1248 if (llink(A)) uplink(llink(A)) = A;
1249 if (rlink(B)) uplink(rlink(B)) = B;
1250 if (uplink(X) == 0) root_ = X;
1252 if (llink(uplink(X)) == A) llink(uplink(X)) = X;
1253 else rlink(uplink(X)) = X;
1255 adjust_balance_remove(uplink(X), X);
1260 template <
class K,
class T,
class C,
class A>
1262 AVLMMap<K,T,C,A>::AVLMMap()
1267 template <
class K,
class T,
class C,
class A>
1269 AVLMMap<K,T,C,A>::AVLMMap(
const C &c):
1275 template <
class K,
class T,
class C,
class A>
1277 AVLMMap<K,T,C,A>::AVLMMap(
const AVLMMap<K,T,C,A>&m)
1280 insert(m.begin(), m.end());
1283 template <
class K,
class T,
class C,
class A>
1285 AVLMMap<K,T,C,A>::initialize()