92template<
class TYPE>
void
96 this->uniqueElements.Clear();
97 this->tableEntries.SetSize(0, 0);
98 this->colIndexMap.Clear();
99 this->rowIndexMap.Clear();
105template<
class TYPE>
void
109 this->inSetup =
true;
112 this->uniqueElements.Reserve(numUnique);
114 this->tableEntries.SetSize(columnNames.
Size(), rowNames.
Size());
115 this->colIndexMap.Reserve(columnNames.
Size());
116 this->rowIndexMap.Reserve(rowNames.
Size());
118 this->colIndexMap.BeginBulkAdd();
120 for (i = 0; i < columnNames.
Size(); i++)
122 this->colIndexMap.Add(columnNames[i], i);
124 this->colIndexMap.EndBulkAdd();
126 this->rowIndexMap.BeginBulkAdd();
127 for (i = 0; i < rowNames.
Size(); i++)
129 this->rowIndexMap.Add(rowNames[i], i);
131 this->rowIndexMap.EndBulkAdd();
137template<
class TYPE>
void
141 TableEntry& entry = this->tableEntries.At(colIndex, rowIndex);
142 entry.
startIndex = this->uniqueElements.Size();
144 this->uniqueElements.Append(elm);
150template<
class TYPE>
void
154 TableEntry& entry = this->tableEntires.At(colIndex, rowIndex);
155 entry.
startIndex = this->uniqueElements.Size();
158 for (i = 0; i < numElms; i++)
160 this->uniqueElements.Append(firstElm[i]);
168template<
class TYPE>
void
172 n_assert((refColIndex <= colIndex) && (refRowIndex <= rowIndex));
173 TableEntry& entry = this->tableEntries.At(refColIndex, refRowIndex);
174 this->tableEntries.Set(colIndex, rowIndex, entry);
180template<
class TYPE>
void
184 TableEntry& entry = this->tableEntries.At(refColIndex, refRowIndex);
192template<
class TYPE>
void
196 this->inSetup =
false;
202template<
class TYPE>
SizeT
205 return this->colIndexMap.Size();
211template<
class TYPE>
SizeT
214 return this->rowIndexMap.Size();
220template<
class TYPE>
bool
223 return this->colIndexMap.Contains(colName);
229template<
class TYPE>
bool
232 return this->rowIndexMap.Contains(rowName);
238template<
class TYPE>
IndexT
241 return this->colIndexMap[colName];
247template<
class TYPE>
IndexT
250 return this->rowIndexMap[rowName];
256template<
class TYPE>
const TYPE*
259 const TableEntry& tableEntry = this->tableEntries.At(colIndex, rowIndex);
262 const TYPE* elm = &(this->uniqueElements[tableEntry.
startIndex]);
276template<
class TYPE>
const TYPE*
279 IndexT colIndex = this->colIndexMap[colName];
280 IndexT rowIndex = this->rowIndexMap[rowName];
281 return this->GetElements(colIndex, rowIndex, outNumElements);
Nebula's dynamic array class.
Definition array.h:60
const SizeT Size() const
get number of elements in array
Definition array.h:880
A collection of key/value pairs with quick value retrieval by key at roughly O(log n).
Definition dictionary.h:34
A fixed-size 2-dimensional array.
Definition fixedtable.h:18
A 2D sparse table where many entries may be redundant and support for multiple entries per cell.
Definition sparsetable.h:22
SizeT GetNumRows() const
get number of rows in the sparse table
Definition sparsetable.h:212
bool inSetup
Definition sparsetable.h:76
bool HasColumn(const StringAtom &colName) const
return true if column exists
Definition sparsetable.h:221
const TYPE * LookupElements(const StringAtom &colName, const StringAtom &rowName, SizeT &outNumElements) const
lookup entry by row/column names
Definition sparsetable.h:277
Dictionary< StringAtom, IndexT > rowIndexMap
Definition sparsetable.h:75
SparseTable()
constructor
Definition sparsetable.h:83
Array< TYPE > uniqueElements
Definition sparsetable.h:72
void AddSingle(IndexT colIndex, IndexT rowIndex, const TYPE &elm)
add a single new unique entry
Definition sparsetable.h:138
Dictionary< StringAtom, IndexT > colIndexMap
Definition sparsetable.h:74
FixedTable< TableEntry > tableEntries
Definition sparsetable.h:73
void BeginSetup(const Array< StringAtom > &columnNames, const Array< StringAtom > &rowNames, SizeT numUnique=0)
setup the sparse table
Definition sparsetable.h:106
void AddMultiple(IndexT colIndex, IndexT rowIndex, const TYPE *firstElm, SizeT numElements)
add a new multiple entry
Definition sparsetable.h:151
IndexT GetRowIndexByName(const StringAtom &rowName) const
return row index by name
Definition sparsetable.h:248
void AddReference(IndexT colIndex, IndexT rowIndex, IndexT refColIndex, IndexT refRowIndex)
add a reference to another column/index
Definition sparsetable.h:169
void SetEntryDirect(IndexT colIndex, IndexT rowIndex, ushort startIndex, ushort numElements)
add a direct reference using an index into the unique element array
Definition sparsetable.h:181
bool HasRow(const StringAtom &rowName) const
return true if row exists
Definition sparsetable.h:230
IndexT GetColumnIndexByName(const StringAtom &colName) const
return column index by name
Definition sparsetable.h:239
void EndSetup()
finish setting up the sparse table
Definition sparsetable.h:193
const TYPE * GetElements(IndexT colIndex, IndexT rowIndex, SizeT &outNumElements) const
get entry at given index
Definition sparsetable.h:257
SizeT GetNumColumns() const
get number of columns in the sparse table
Definition sparsetable.h:203
void Clear()
clear object
Definition sparsetable.h:93
SizeT GetNumUniqueElements() const
get current number of unique elements
A StringAtom.
Definition stringatom.h:22
#define n_assert(exp)
Definition debug.h:50
A pinned array is an array which manages its own virtual memory.
Definition String.cs:6
a table entry in the sparse table
Definition sparsetable.h:65
ushort startIndex
Definition sparsetable.h:68
TableEntry()
Definition sparsetable.h:66
ushort numElements
Definition sparsetable.h:69
int SizeT
Definition types.h:49
unsigned short ushort
Definition types.h:32
int IndexT
Definition types.h:48