5 #include <ext/hash_map>
6 #define stdext __gnu_cxx
11 template <
class CellT,
unsigned int DimT>
38 template <
class CellT>
47 operator const CellT&()
const
62 template <
class CellT,
unsigned int DimT>
67 m_extent(extent), m_array(array)
82 unsigned int* m_extent;
86 template <
class CellT>
109 template <
class CellT,
unsigned int DimT>
127 template <
class CellT>
135 operator const CellT&()
const
144 template <
class CellT,
unsigned int DimT>
150 for (
unsigned int i = 0; i < DimT; ++i)
177 for (
unsigned int i = 0; i < DimT; ++i)
179 m_extent[i] = extent[i];
196 unsigned int m_extent[DimT];
199 template <
class CellT,
unsigned int DimT>
203 HashGridAccessor(
const size_t* factors,
size_t hashKey, stdext::hash_map<size_t, CellT>& hash) :
204 m_factors(factors), m_hashKey(hashKey), m_hash(hash)
212 m_factors + 1, m_hashKey + (*m_factors) * i, m_hash);
216 const size_t* m_factors;
218 stdext::hash_map<size_t, CellT>& m_hash;
221 template <
class CellT>
226 m_hashKey(hashKey), m_hash(hash)
233 return m_hash[m_hashKey] =
c;
238 return m_hash[m_hashKey];
244 return m_hash[m_hashKey];
250 return &m_hash[m_hashKey];
255 stdext::hash_map<size_t, CellT>& m_hash;
258 template <
class CellT,
unsigned int DimT>
264 const stdext::hash_map<size_t, CellT>& hash) :
265 m_factors(factors), m_hashKey(hashKey), m_hash(hash)
273 m_factors + 1, m_hashKey + (*m_factors) * i, m_hash);
277 const size_t* m_factors;
279 const stdext::hash_map<size_t, CellT>& m_hash;
282 template <
class CellT>
288 const stdext::hash_map<size_t, CellT>& hash) :
289 m_hashKey(hashKey), m_hash(hash)
293 operator const CellT*()
295 typename stdext::hash_map<size_t, CellT>::const_iterator i = m_hash.find(m_hashKey);
296 if (i != m_hash.end())
305 const stdext::hash_map<size_t, CellT>& m_hash;
308 template <
class CellT,
unsigned int DimT>
312 typedef typename stdext::hash_map<size_t, CellT>::iterator
iterator;
317 for (
unsigned int i = 0; i < DimT; ++i)
329 template <
class ExtentT>
333 m_factors[DimT - 1] = 1;
334 for (
unsigned int i = DimT - 1; i != 0; --i)
336 m_factors[i - 1] = m_factors[i] * extent[i];
352 template <
class IndexT>
356 return m_hash[HashKey(
index)];
362 return m_hash[hashKey];
366 at(
size_t hashKey)
const
368 return m_hash[hashKey];
371 template <
class IndexT>
376 if (i != m_hash.end())
383 template <
class IndexT>
388 if (i != m_hash.end())
398 return m_hash.begin();
410 return m_hash.begin();
422 return m_hash.size();
426 template <
class IndexT>
428 HashKey(
const IndexT&
index)
const
430 size_t hashKey = m_factors[0] *
index[0];
431 for (
unsigned int i = 1; i < DimT; ++i)
433 hashKey += m_factors[i] *
index[i];
439 size_t m_factors[DimT];
440 stdext::hash_map<size_t, CellT> m_hash;