| 1 | // -*- C++ -*-cxx . . $ `<file>/vendor/Heap-Layers/heaps/special/nestedheap.h`/ |
| 2 | |
| 3 | /* |
| 4 | |
| 5 | Heap Layers: An Extensible Memory Allocation Infrastructure |
| 6 | |
| 7 | Copyright (C) 2000-2020 by Emery Berger |
| 8 | http://www.emeryberger.com |
| 9 | [email protected] |
| 10 | |
| 11 | Heap Layers is distributed under the terms of the Apache 2.0 license. |
| 12 | |
| 13 | You may obtain a copy of the License at |
| 14 | http://www.apache.org/licenses/LICENSE-2.0 |
| 15 | |
| 16 | */ |
| 17 | |
| 18 | #ifndef HL_NESTEDHEAP_H_ |
| 19 | #define HL_NESTEDHEAP_H_cxx . . $ `vendor/Heap-Layers/heaps/special/nestedheap.h:19:9`! |
| 20 | |
| 21 | #include <assert.h> |
| 22 | |
| 23 | /** |
| 24 | * @class NestedHeap |
| 25 | * @brief Hierarchical heaps. |
| 26 | * @author Emery Berger <http://www.cs.umass.edu/~emery> |
| 27 | */ |
| 28 | |
| 29 | namespace HLcxx . . $ HL/ { |
| 30 | |
| 31 | template <class SuperHeap> |
| 32 | class NestedHeapcxx . . $ HL/NestedHeap# : public SuperHeap { |
| 33 | public: |
| 34 | |
| 35 | NestedHeapcxx . . $ HL/NestedHeap#`NestedHeap<SuperHeap>`(49f6e7a06ebc5aa8).() |
| 36 | : parentcxx . . $ HL/NestedHeap#parent. (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!), |
| 37 | childcxx . . $ HL/NestedHeap#child. (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!), |
| 38 | prevcxx . . $ HL/NestedHeap#prev. (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!), |
| 39 | nextcxx . . $ HL/NestedHeap#next. (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) |
| 40 | { |
| 41 | } |
| 42 | |
| 43 | ~cxx . . $ HL/NestedHeap#`~NestedHeap<SuperHeap>`(49f6e7a06ebc5aa8).NestedHeap() |
| 44 | { |
| 45 | clearcxx . . $ HL/NestedHeap#clear(49f6e7a06ebc5aa8).(); |
| 46 | if (parentcxx . . $ HL/NestedHeap#parent. !=cxx . . $ HL/`operator!=`(fef5daa2f5cf3d2). NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) { |
| 47 | parentcxx . . $ HL/NestedHeap#parent.->removeChildcxx . . $ HL/NestedHeap#removeChild(acc5e0348ac6aaf5). (this); |
| 48 | } |
| 49 | removeSiblingcxx . . $ HL/NestedHeap#removeSibling(acc5e0348ac6aaf5). (this); |
| 50 | } |
| 51 | |
| 52 | inline void clearcxx . . $ HL/NestedHeap#clear(49f6e7a06ebc5aa8).() { |
| 53 | |
| 54 | // Clear this heap. |
| 55 | SuperHeap::clear(); |
| 56 | |
| 57 | #if 0 |
| 58 | // |
| 59 | // Iterate through all children and delete them. |
| 60 | // |
| 61 | |
| 62 | if (child != NULL) { |
| 63 | NestedHeap<SuperHeap> * nextChild = child->next; |
| 64 | while (child != NULL) { |
| 65 | NestedHeap<SuperHeap> * prevChild = child->prev; |
| 66 | delete child; |
| 67 | child = prevChild; |
| 68 | } |
| 69 | child = nextChild; |
| 70 | while (child != NULL) { |
| 71 | nextChild = child->next; |
| 72 | delete child; |
| 73 | child = nextChild; |
| 74 | } |
| 75 | } |
| 76 | assert (child == NULL); |
| 77 | |
| 78 | #else // clear all the children. |
| 79 | |
| 80 | NestedHeapcxx . . $ HL/NestedHeap#<SuperHeap> * ch = childcxx . . $ HL/NestedHeap#child.; |
| 81 | while (ch !=cxx . . $ HL/`operator!=`(fef5daa2f5cf3d2). NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) { |
| 82 | NestedHeapcxx . . $ HL/NestedHeap#<SuperHeap> * nextChild = ch->nextcxx . . $ HL/NestedHeap#next.; |
| 83 | ch->clearcxx . . $ HL/NestedHeap#clear(49f6e7a06ebc5aa8).(); |
| 84 | ch = nextChild; |
| 85 | } |
| 86 | #endif |
| 87 | |
| 88 | } |
| 89 | |
| 90 | void addChildcxx . . $ HL/NestedHeap#addChild(acc5e0348ac6aaf5). (NestedHeapcxx . . $ HL/NestedHeap#<SuperHeap> * ch) |
| 91 | { |
| 92 | if (childcxx . . $ HL/NestedHeap#child. ==cxx . . $ HL/`operator==`(fef5daa2f5cf3d2). NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) { |
| 93 | childcxx . . $ HL/NestedHeap#child. = ch; |
| 94 | childcxx . . $ HL/NestedHeap#child.->prevcxx . . $ HL/NestedHeap#prev. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 95 | childcxx . . $ HL/NestedHeap#child.->nextcxx . . $ HL/NestedHeap#next. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 96 | } else { |
| 97 | assertcxx . . $ `/usr/include/assert.h:50:10`! (child->prev == NULL); |
| 98 | assertcxx . . $ `/usr/include/assert.h:50:10`! (ch->next == NULL); |
| 99 | ch->prevcxx . . $ HL/NestedHeap#prev. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 100 | ch->nextcxx . . $ HL/NestedHeap#next. = childcxx . . $ HL/NestedHeap#child.; |
| 101 | childcxx . . $ HL/NestedHeap#child.->prevcxx . . $ HL/NestedHeap#prev. = ch; |
| 102 | childcxx . . $ HL/NestedHeap#child. = ch; |
| 103 | } |
| 104 | childcxx . . $ HL/NestedHeap#child.->parentcxx . . $ HL/NestedHeap#parent. = this; |
| 105 | } |
| 106 | |
| 107 | private: |
| 108 | |
| 109 | void removeChildcxx . . $ HL/NestedHeap#removeChild(acc5e0348ac6aaf5). (NestedHeapcxx . . $ HL/NestedHeap#<SuperHeap> * ch) |
| 110 | { |
| 111 | assertcxx . . $ `/usr/include/assert.h:50:10`! (ch != NULL); |
| 112 | if (childcxx . . $ HL/NestedHeap#child. ==cxx . . $ HL/`operator==`(fef5daa2f5cf3d2). ch) { |
| 113 | if (ch->prevcxx . . $ HL/NestedHeap#prev.) { |
| 114 | childcxx . . $ HL/NestedHeap#child. = ch->prevcxx . . $ HL/NestedHeap#prev.; |
| 115 | } else if (ch->nextcxx . . $ HL/NestedHeap#next.) { |
| 116 | childcxx . . $ HL/NestedHeap#child. = ch->nextcxx . . $ HL/NestedHeap#next.; |
| 117 | } else { |
| 118 | childcxx . . $ HL/NestedHeap#child. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 119 | } |
| 120 | } |
| 121 | removeSiblingcxx . . $ HL/NestedHeap#removeSibling(acc5e0348ac6aaf5). (ch); |
| 122 | } |
| 123 | |
| 124 | inline static void removeSiblingcxx . . $ HL/NestedHeap#removeSibling(acc5e0348ac6aaf5). (NestedHeapcxx . . $ HL/NestedHeap#<SuperHeap> * sib) |
| 125 | { |
| 126 | if (sib->prevcxx . . $ HL/NestedHeap#prev.) { |
| 127 | sib->prevcxx . . $ HL/NestedHeap#prev.->nextcxx . . $ HL/NestedHeap#next. = sib->nextcxx . . $ HL/NestedHeap#next.; |
| 128 | } |
| 129 | if (sib->nextcxx . . $ HL/NestedHeap#next.) { |
| 130 | sib->nextcxx . . $ HL/NestedHeap#next.->prevcxx . . $ HL/NestedHeap#prev. = sib->prevcxx . . $ HL/NestedHeap#prev.; |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | NestedHeapcxx . . $ HL/NestedHeap#<SuperHeap> * parentcxx . . $ HL/NestedHeap#parent.; |
| 135 | NestedHeapcxx . . $ HL/NestedHeap#<SuperHeap> * childcxx . . $ HL/NestedHeap#child.; |
| 136 | NestedHeapcxx . . $ HL/NestedHeap#<SuperHeap> * prevcxx . . $ HL/NestedHeap#prev.; |
| 137 | NestedHeapcxx . . $ HL/NestedHeap#<SuperHeap> * nextcxx . . $ HL/NestedHeap#next.; |
| 138 | |
| 139 | }; |
| 140 | |
| 141 | } |
| 142 | |
| 143 | #endif |