7 #ifndef __solve_SparseArray_h__ 8 #define __solve_SparseArray_h__ 10 #define FE_SA_PREALLOC 8 11 #define FE_SA_GROW 1.5f 34 void reset(U32 prealloc=FE_SA_PREALLOC);
40 U32
size(
void)
const {
return m_used? m_maxIndex+1: 0; }
55 U32
entries(
void)
const {
return m_used; }
58 U32
index(U32 location)
const {
return m_pIndex[location]; }
61 T&
entry(U32 location) {
return m_pData[location]; }
64 T
entry(U32 location)
const {
return m_pData[location]; }
69 void initialize(U32 prealloc);
93 m_pIndex=
new U32[prealloc];
94 m_pData=
new T[prealloc];
124 initialize(prealloc);
130 for(U32 m=0;m<m_used;m++)
132 m_pData[m]=defaultByType(m_pData[0]);
139 while(m_cacheLocation &&
140 (m_cacheLocation>=m_used || m_pIndex[m_cacheLocation]>index))
142 while(m_cacheLocation<m_used && m_pIndex[m_cacheLocation]<index)
145 if(m_cacheLocation>=m_used || m_pIndex[m_cacheLocation]!=index)
147 if(m_used==m_allocated)
151 for(U32 m=m_used;m>m_cacheLocation;m--)
153 m_pIndex[m]=m_pIndex[m-1];
154 m_pData[m]=m_pData[m-1];
156 m_pIndex[m_cacheLocation]=
index;
157 m_pData[m_cacheLocation]=defaultByType(m_pData[0]);
166 return m_pData[m_cacheLocation];
173 while(location<m_used && m_pIndex[location]<index)
176 if(location<m_used && m_pIndex[location]==index)
178 return m_pData[location];
181 return defaultByType(m_pData[0]);
191 U32 count=other.m_used;
192 for(U32 i = 0; i < count; i++)
194 operator[](other.m_pIndex[i])=other.m_pData[i];
204 U32 newsize=U32(m_allocated*FE_SA_GROW);
205 U32* pNewIndex=
new U32[newsize];
206 T* pNewData=
new T[newsize];
209 for(U32 m=0;m<m_used;m++)
211 pNewIndex[m]=m_pIndex[m];
212 pNewData[m]=m_pData[m];
232 for(U32 i = 0; i <
size; i++)
244 s.
catf(
"%.6G", rhs[i]);
void clear(void)
Zero existing values, but do not remove.
Definition: SparseArray.h:128
kernel
Definition: namespace.dox:3
T entry(U32 location) const
Return the const entry at a storage location.
Definition: SparseArray.h:64
T & entry(U32 location)
Return the entry at a storage location.
Definition: SparseArray.h:61
Row-Compressed Sparse Container.
Definition: SparseArray.h:24
T & operator[](U32 index)
Return the entry at the particular index.
Definition: SparseArray.h:137
String & cat(const char *operand)
Append the current String with the given text.
Definition: String.cc:545
U32 entries(void) const
Return the number of actual stored entries.
Definition: SparseArray.h:55
Automatically reference-counted string container.
Definition: String.h:128
U32 index(U32 location) const
Return the index at a storage location.
Definition: SparseArray.h:58
String & catf(const char *fmt,...)
Populate the string as with sPrintf(), but by concatenating the results to the existing string...
Definition: String.cc:554
String print(const SparseArray< T > &rhs, BWORD sparse=FALSE)
Print to a string.
Definition: SparseArray.h:227
void reset(U32 prealloc=FE_SA_PREALLOC)
Remove all existing values.
Definition: SparseArray.h:120
U32 size(void) const
Return the largest index.
Definition: SparseArray.h:40