COPASI API  4.16.103
Public Member Functions | Private Attributes | List of all members
CKeyFactory::HashTable Class Reference
Collaboration diagram for CKeyFactory::HashTable:
Collaboration graph
[legend]

Public Member Functions

size_t add (CCopasiObject *pObject)
 
bool addFix (const size_t &index, CCopasiObject *pObject)
 
CCopasiObjectget (const size_t &index)
 
 HashTable ()
 
 HashTable (const HashTable &src)
 
bool remove (const size_t &index)
 
 ~HashTable ()
 

Private Attributes

size_t mBeyond
 
std::stack< size_t > mFree
 
size_t mSize
 
CVector< CCopasiObject * > mTable
 

Detailed Description

Definition at line 38 of file CKeyFactory.h.

Constructor & Destructor Documentation

CKeyFactory::HashTable::HashTable ( )

Definition at line 75 of file CKeyFactory.cpp.

References CVectorCore< CType >::array(), mSize, and mTable.

75  :
76  mBeyond(0),
77  mSize(128),
78  mTable(128),
79  mFree()
80 {memset(mTable.array(), 0, mSize * sizeof(CCopasiObject *));}
CVector< CCopasiObject * > mTable
Definition: CKeyFactory.h:43
std::stack< size_t > mFree
Definition: CKeyFactory.h:44
CType * array()
Definition: CVector.h:139
CKeyFactory::HashTable::HashTable ( const HashTable src)

Definition at line 82 of file CKeyFactory.cpp.

82  :
83  mBeyond(src.mBeyond),
84  mSize(src.mSize),
85  mTable(src.mTable),
86  mFree(src.mFree)
87 {}
CVector< CCopasiObject * > mTable
Definition: CKeyFactory.h:43
std::stack< size_t > mFree
Definition: CKeyFactory.h:44
CKeyFactory::HashTable::~HashTable ( )

Definition at line 89 of file CKeyFactory.cpp.

89 {}

Member Function Documentation

size_t CKeyFactory::HashTable::add ( CCopasiObject pObject)

Definition at line 91 of file CKeyFactory.cpp.

92 {
93  size_t index;
94 
95  if (!mFree.empty())
96  {
97  index = mFree.top();
98  mFree.pop();
99  }
100  else
101  {
102  index = mBeyond;
103 
104  mBeyond++;
105 
106  if (mBeyond > mSize)
107  {
108  mTable.resize(mSize * 2, true);
109  memset(mTable.array() + mSize, 0, mSize * sizeof(CCopasiObject *));
110  mSize *= 2;
111  }
112  }
113 
114  mTable[index] = pObject;
115  return index;
116 }
CVector< CCopasiObject * > mTable
Definition: CKeyFactory.h:43
void resize(size_t size, const bool &copy=false)
Definition: CVector.h:301
std::stack< size_t > mFree
Definition: CKeyFactory.h:44
CType * array()
Definition: CVector.h:139
bool CKeyFactory::HashTable::addFix ( const size_t &  index,
CCopasiObject pObject 
)

Definition at line 118 of file CKeyFactory.cpp.

120 {
121  while (index >= mSize)
122  {
123  mTable.resize(mSize * 2, true);
124  memset(mTable.array() + mSize, 0,
125  mSize * sizeof(CCopasiObject *));
126  mSize *= 2;
127  }
128 
129  if (mTable[index]) return false;
130 
131  mTable[index] = pObject;
132  return true;
133 }
CVector< CCopasiObject * > mTable
Definition: CKeyFactory.h:43
void resize(size_t size, const bool &copy=false)
Definition: CVector.h:301
CType * array()
Definition: CVector.h:139
CCopasiObject * CKeyFactory::HashTable::get ( const size_t &  index)

Definition at line 135 of file CKeyFactory.cpp.

136 {
137  if (index < mSize) return mTable[index];
138 
139  return NULL;
140 }
CVector< CCopasiObject * > mTable
Definition: CKeyFactory.h:43
bool CKeyFactory::HashTable::remove ( const size_t &  index)

Definition at line 142 of file CKeyFactory.cpp.

143 {
144  if (index < mSize)
145  {
146  if (!mTable[index]) return false;
147 
148  mTable[index] = NULL;
149  mFree.push(index);
150 
151  return true;
152  }
153 
154  return false;
155 }
CVector< CCopasiObject * > mTable
Definition: CKeyFactory.h:43
std::stack< size_t > mFree
Definition: CKeyFactory.h:44

Member Data Documentation

size_t CKeyFactory::HashTable::mBeyond
private

Definition at line 41 of file CKeyFactory.h.

std::stack< size_t > CKeyFactory::HashTable::mFree
private

Definition at line 44 of file CKeyFactory.h.

size_t CKeyFactory::HashTable::mSize
private

Definition at line 42 of file CKeyFactory.h.

Referenced by HashTable().

CVector< CCopasiObject * > CKeyFactory::HashTable::mTable
private

Definition at line 43 of file CKeyFactory.h.

Referenced by HashTable().


The documentation for this class was generated from the following files: