|
cgma
|
#include <ArrayBasedContainer.hpp>
Public Member Functions | |
| ArrayBasedContainer (int size) | |
| ArrayBasedContainer (const ArrayBasedContainer ©_from) | |
| virtual | ~ArrayBasedContainer () |
| int | size () const |
| void | clean_out () |
| void | shrink (int k) |
| ArrayBasedContainer & | operator= (const ArrayBasedContainer &) |
| ArrayBasedContainer & | operator+= (const ArrayBasedContainer &) |
| ArrayBasedContainer & | operator-= (const ArrayBasedContainer &) |
| virtual void | compress () |
Static Public Member Functions | |
| static unsigned int | current_allocated_memory () |
| static unsigned int | maximum_allocated_memory () |
Protected Member Functions | |
| void | lengthen_list () |
Protected Attributes | |
| void ** | listArray |
| int | itemCount |
| int | listLength |
| Bit | poolAllocated: 1 |
| Bit | listIsSorted: 1 |
| Bit | listIncrement: 30 |
Static Private Attributes | |
| static unsigned int | currentAllocatedMemory = 0 |
| static unsigned int | maxAllocatedMemory = 0 |
Definition at line 21 of file ArrayBasedContainer.hpp.
| ArrayBasedContainer::ArrayBasedContainer | ( | int | size | ) |
Definition at line 24 of file ArrayBasedContainer.cpp.
{
if ( increment > 0)
{
listIncrement = increment;
}
else
{
listIncrement = INCREMENT;
}
itemCount = 0;
listLength = 0;
listArray = 0;
poolAllocated = CUBIT_FALSE;
listIsSorted = CUBIT_FALSE;
}
| ArrayBasedContainer::ArrayBasedContainer | ( | const ArrayBasedContainer & | copy_from | ) |
Definition at line 43 of file ArrayBasedContainer.cpp.
{
listLength = from.listLength;
listIncrement = from.listIncrement;
poolAllocated = from.poolAllocated;
listIsSorted = from.listIsSorted;
listArray = NULL;
if (listLength)
{
if (listLength == INCREMENT && (int)listIncrement == INCREMENT) {
listArray = (void **)new ArrayMemory;
poolAllocated = CUBIT_TRUE;
}
else {
listArray = new void* [listLength];
poolAllocated = CUBIT_FALSE;
currentAllocatedMemory += listLength;
if (currentAllocatedMemory > maxAllocatedMemory)
maxAllocatedMemory = currentAllocatedMemory;
}
assert(listArray != 0);
}
itemCount = from.itemCount;
if (itemCount)
memcpy (listArray, from.listArray, itemCount*sizeof(void*));
}
| ArrayBasedContainer::~ArrayBasedContainer | ( | ) | [virtual] |
Definition at line 73 of file ArrayBasedContainer.cpp.
{
if ( listLength )
{
if (poolAllocated) {
delete ((ArrayMemory*) listArray);
}
else {
delete [] listArray;
currentAllocatedMemory -= listLength;
}
listArray = NULL;
}
}
| void ArrayBasedContainer::clean_out | ( | ) | [inline] |
| void ArrayBasedContainer::compress | ( | ) | [virtual] |
| unsigned int ArrayBasedContainer::current_allocated_memory | ( | ) | [static] |
Definition at line 239 of file ArrayBasedContainer.cpp.
{
return currentAllocatedMemory;
}
| void ArrayBasedContainer::lengthen_list | ( | ) | [protected] |
Definition at line 89 of file ArrayBasedContainer.cpp.
{
void **tempArray = 0;
if (listLength == 0 && (int)listIncrement == INCREMENT)
{
poolAllocated = CUBIT_TRUE;
listArray = (void **)new ArrayMemory;
assert(listArray != 0);
listLength = listIncrement;
return;
}
// Normal allocation from here to end.
tempArray = new void* [listLength + listIncrement];
currentAllocatedMemory += (listLength + listIncrement);
if (currentAllocatedMemory > maxAllocatedMemory)
maxAllocatedMemory = currentAllocatedMemory;
assert(tempArray != 0);
// copy the old stuff into the new array
if (listLength)
{
memcpy ( tempArray, listArray, listLength*sizeof(void*) );
// delete the old array
if (poolAllocated)
{
delete ((ArrayMemory*) listArray);
}
else {
delete [] listArray;
currentAllocatedMemory -= listLength;
}
}
// set the new equal to the old
listArray = tempArray;
// update data
poolAllocated = CUBIT_FALSE;
listLength += listIncrement;
listIncrement *= 2;
listIncrement = listIncrement > 1000000 ? 1000000 : listIncrement;
}
| unsigned int ArrayBasedContainer::maximum_allocated_memory | ( | ) | [static] |
Definition at line 244 of file ArrayBasedContainer.cpp.
{
return maxAllocatedMemory;
}
| ArrayBasedContainer & ArrayBasedContainer::operator+= | ( | const ArrayBasedContainer & | from | ) |
Definition at line 182 of file ArrayBasedContainer.cpp.
{
int tmp_itemCount = itemCount + from.itemCount;
if (tmp_itemCount >= listLength)
{
if ((listLength + (int)listIncrement) < tmp_itemCount)
{
listIncrement = tmp_itemCount - listLength;
}
lengthen_list();
}
if (from.itemCount == 1)
{
listArray[itemCount] = from.listArray[0];
}
else
{
if (from.itemCount)
memcpy (&listArray[itemCount], from.listArray,
from.itemCount*sizeof(void*));
}
itemCount += from.itemCount;
listIsSorted = listIsSorted && from.listIsSorted;
return *this;
}
| ArrayBasedContainer & ArrayBasedContainer::operator-= | ( | const ArrayBasedContainer & | from | ) |
Definition at line 209 of file ArrayBasedContainer.cpp.
| ArrayBasedContainer & ArrayBasedContainer::operator= | ( | const ArrayBasedContainer & | from | ) |
Definition at line 135 of file ArrayBasedContainer.cpp.
{
if (this == &from)
return *this;
// See if the existing listArray length is equal to the from listArray
// length. If it is, we can reuse it without deleting and newing.
if (listLength != from.listLength) {
if (listLength) {
if (poolAllocated) {
delete ((ArrayMemory*) listArray);
} else {
delete [] listArray;
currentAllocatedMemory -= listLength;
}
}
listLength = from.listLength;
if (listLength)
{
if (listLength == INCREMENT && (int)listIncrement == INCREMENT)
{
listArray = (void **)new ArrayMemory;
poolAllocated = CUBIT_TRUE;
}
else
{
listArray = new void* [listLength];
poolAllocated = CUBIT_FALSE;
currentAllocatedMemory += listLength;
if (currentAllocatedMemory > maxAllocatedMemory)
maxAllocatedMemory = currentAllocatedMemory;
}
assert(listArray != 0);
}
}
itemCount = from.itemCount;
listIncrement = from.listIncrement;
listIsSorted = from.listIsSorted;
if (itemCount)
memcpy (listArray, from.listArray, itemCount*sizeof(void*));
return *this;
}
| void ArrayBasedContainer::shrink | ( | int | k | ) | [inline] |
| int ArrayBasedContainer::size | ( | ) | const [inline] |
Definition at line 99 of file ArrayBasedContainer.hpp.
{ return itemCount; }
unsigned int ArrayBasedContainer::currentAllocatedMemory = 0 [static, private] |
Definition at line 84 of file ArrayBasedContainer.hpp.
int ArrayBasedContainer::itemCount [protected] |
Definition at line 73 of file ArrayBasedContainer.hpp.
void** ArrayBasedContainer::listArray [protected] |
Definition at line 72 of file ArrayBasedContainer.hpp.
Bit ArrayBasedContainer::listIncrement [protected] |
Definition at line 78 of file ArrayBasedContainer.hpp.
Bit ArrayBasedContainer::listIsSorted [protected] |
Definition at line 77 of file ArrayBasedContainer.hpp.
int ArrayBasedContainer::listLength [protected] |
Definition at line 74 of file ArrayBasedContainer.hpp.
unsigned int ArrayBasedContainer::maxAllocatedMemory = 0 [static, private] |
Definition at line 85 of file ArrayBasedContainer.hpp.
Bit ArrayBasedContainer::poolAllocated [protected] |
Definition at line 75 of file ArrayBasedContainer.hpp.