21template <
class Elem,
int Num>
29template <
class Elem,
int Num>
33 StackPart <Elem, Num> *TopPart, *TopFreePart;
37 Stack() { TopPart = TopFreePart = NULL; UsedInTop = Num; SSize = 0; }
39 int Size()
const {
return SSize; }
55template <
class Elem,
int Num>
58 StackPart <Elem, Num> *aux;
61 if (TopFreePart == NULL)
63 aux =
new StackPart <Elem, Num>;
67 TopFreePart = (aux = TopFreePart)->Prev;
77template <
class Elem,
int Num>
80 StackPart <Elem, Num> *aux;
83 TopPart = (aux = TopPart)->Prev;
84 aux->
Prev = TopFreePart;
89 return TopPart->
Elements[--UsedInTop];
92template <
class Elem,
int Num>
95 StackPart <Elem, Num> *aux;
96 while (TopPart != NULL)
98 TopPart = (aux = TopPart)->Prev;
101 while (TopFreePart != NULL)
103 TopFreePart = (aux = TopFreePart)->Prev;
110template <
class Elem,
int Num>
119template <
class Elem,
int Num>
123 StackPart <Elem, Num> *aux = TopPart;
126 used_mem +=
sizeof(StackPart <Elem, Num>);
132 used_mem +=
sizeof(StackPart <Elem, Num>);
140template <
class Elem,
int Num>
144 MemAllocNode <Elem, Num> *
Prev;
148template <
class Elem,
int Num>
152 MemAllocNode <Elem, Num> *Last;
154 Stack <Elem *, Num> UsedMem;
165template <
class Elem,
int Num>
168 MemAllocNode <Elem, Num> *aux;
169 if (UsedMem.Size() > 0)
171 return UsedMem.Pop();
173 if (AllocatedInLast == Num)
176 Last =
new MemAllocNode <Elem, Num>;
180 return &(Last->Elements[AllocatedInLast++]);
183template <
class Elem,
int Num>
189template <
class Elem,
int Num>
192 MemAllocNode <Elem, Num> *aux;
199 AllocatedInLast = Num;
203template <
class Elem,
int Num>
207 mfem::Swap(AllocatedInLast, other.AllocatedInLast);
208 UsedMem.Swap(other.UsedMem);
211template <
class Elem,
int Num>
214 size_t used_mem = UsedMem.MemoryUsage();
215 MemAllocNode <Elem, Num> *aux = Last;
218 used_mem +=
sizeof(MemAllocNode <Elem, Num>);
MemAllocNode< Elem, Num > * Prev
void Swap(MemAlloc< Elem, Num > &other)
size_t MemoryUsage() const
StackPart< Elem, Num > * Prev
void Push(Elem E)
Push element 'E' on the stack.
void Swap(Stack< Elem, Num > &other)
Swap the data in this stack with the data in other.
Stack()
Construct an empty stack.
void Clear()
Clear the elements off the stack.
int Size() const
Return the number of elements on the stack.
size_t MemoryUsage() const
Return the number of bytes used by the stack.
Elem Pop()
Pop an element off the stack and return it.
void Swap(Array< T > &, Array< T > &)