libMesh
Classes | Public Types | Public Member Functions | List of all members
libMesh::chunked_mapvector< Val, index_t, N > Class Template Reference

This chunked_mapvector templated class is intended to provide the asymptotic performance characteristics of a std::map with an interface more closely resembling that of a std::vector, for use with DistributedMesh. More...

#include <chunked_mapvector.h>

Inheritance diagram for libMesh::chunked_mapvector< Val, index_t, N >:
[legend]

Classes

class  const_reverse_veclike_iterator
 
class  const_veclike_iterator
 
class  veclike_iterator
 
class  veclike_iterator_base
 

Public Types

typedef std::map< index_t, std::array< Val, N > > maptype
 
typedef unsigned int iter_t
 

Public Member Functions

veclike_iterator find (const index_t &k)
 
const_veclike_iterator find (const index_t &k) const
 
Val & operator[] (const index_t &k)
 
Val operator[] (const index_t &k) const
 
void erase (index_t i)
 
veclike_iterator erase (const veclike_iterator &pos)
 
veclike_iterator begin ()
 
const_veclike_iterator begin () const
 
veclike_iterator end ()
 
const_veclike_iterator end () const
 
const_reverse_veclike_iterator rbegin () const
 
const_reverse_veclike_iterator rend () const
 

Detailed Description

template<typename Val, typename index_t = unsigned int, unsigned int N = 16>
class libMesh::chunked_mapvector< Val, index_t, N >

This chunked_mapvector templated class is intended to provide the asymptotic performance characteristics of a std::map with an interface more closely resembling that of a std::vector, for use with DistributedMesh.

The intermediate array "chunks" give better constants on performance, for the typical sparsity structure we see on meshes in practice, where large swaths of ids are contiguous.

Author
Roy H. Stogner

Definition at line 43 of file chunked_mapvector.h.

Member Typedef Documentation

◆ iter_t

template<typename Val , typename index_t = unsigned int, unsigned int N = 16>
typedef unsigned int libMesh::chunked_mapvector< Val, index_t, N >::iter_t

Definition at line 48 of file chunked_mapvector.h.

◆ maptype

template<typename Val , typename index_t = unsigned int, unsigned int N = 16>
typedef std::map<index_t, std::array<Val,N> > libMesh::chunked_mapvector< Val, index_t, N >::maptype

Definition at line 46 of file chunked_mapvector.h.

Member Function Documentation

◆ begin() [1/2]

template<typename Val , typename index_t = unsigned int, unsigned int N = 16>
veclike_iterator libMesh::chunked_mapvector< Val, index_t, N >::begin ( )
inline

Definition at line 249 of file chunked_mapvector.h.

250  {
251  return veclike_iterator(maptype::begin(), 0);
252  }

◆ begin() [2/2]

template<typename Val , typename index_t = unsigned int, unsigned int N = 16>
const_veclike_iterator libMesh::chunked_mapvector< Val, index_t, N >::begin ( ) const
inline

Definition at line 254 of file chunked_mapvector.h.

255  {
256  return const_veclike_iterator(maptype::begin(), 0);
257  }

◆ end() [1/2]

template<typename Val , typename index_t = unsigned int, unsigned int N = 16>
veclike_iterator libMesh::chunked_mapvector< Val, index_t, N >::end ( )
inline

Definition at line 259 of file chunked_mapvector.h.

Referenced by libMesh::chunked_mapvector< Val, index_t, N >::find(), and libMesh::chunked_mapvector< Val, index_t, N >::operator[]().

260  {
261  return veclike_iterator(maptype::end(), 0);
262  }

◆ end() [2/2]

template<typename Val , typename index_t = unsigned int, unsigned int N = 16>
const_veclike_iterator libMesh::chunked_mapvector< Val, index_t, N >::end ( ) const
inline

Definition at line 264 of file chunked_mapvector.h.

265  {
266  return const_veclike_iterator(maptype::end(), 0);
267  }

◆ erase() [1/2]

template<typename Val , typename index_t = unsigned int, unsigned int N = 16>
void libMesh::chunked_mapvector< Val, index_t, N >::erase ( index_t  i)
inline

Definition at line 214 of file chunked_mapvector.h.

215  {
216  typename maptype::iterator it = maptype::find(i/N);
217  if (it == maptype::end())
218  return;
219 
220  (it->second)[i%N] = Val();
221  for (auto v : it->second)
222  if (v != Val())
223  return;
224 
225  maptype::erase(it);
226  }

◆ erase() [2/2]

template<typename Val , typename index_t = unsigned int, unsigned int N = 16>
veclike_iterator libMesh::chunked_mapvector< Val, index_t, N >::erase ( const veclike_iterator pos)
inline

Definition at line 228 of file chunked_mapvector.h.

229  {
230  if (pos.it == maptype::end())
231  return pos;
232  *pos = Val();
233 
234  veclike_iterator newpos = pos;
235  do {
236  ++newpos;
237  } while (newpos.it == pos.it &&
238  *newpos == Val());
239 
240  for (auto v : pos.it->second)
241  if (v != Val())
242  return newpos;
243 
244  maptype::erase(pos.it);
245 
246  return newpos;
247  }

◆ find() [1/2]

template<typename Val , typename index_t = unsigned int, unsigned int N = 16>
veclike_iterator libMesh::chunked_mapvector< Val, index_t, N >::find ( const index_t &  k)
inline

Definition at line 179 of file chunked_mapvector.h.

References libMesh::chunked_mapvector< Val, index_t, N >::end().

180  {
181  auto sub_it = maptype::find(k/N);
182  if (sub_it == maptype::end())
183  return veclike_iterator(sub_it, 0);
184 
185  veclike_iterator it {sub_it, iter_t(k%N)};
186  if (*it)
187  return it;
188  return this->end();
189  }

◆ find() [2/2]

template<typename Val , typename index_t = unsigned int, unsigned int N = 16>
const_veclike_iterator libMesh::chunked_mapvector< Val, index_t, N >::find ( const index_t &  k) const
inline

Definition at line 191 of file chunked_mapvector.h.

References libMesh::chunked_mapvector< Val, index_t, N >::end().

192  {
193  auto sub_it = maptype::find(k/N);
194  if (sub_it == maptype::end())
195  return const_veclike_iterator(sub_it, 0);
196 
197  const_veclike_iterator it {sub_it, iter_t(k%N)};
198  if (*it)
199  return it;
200  return this->end();
201  }

◆ operator[]() [1/2]

template<typename Val , typename index_t = unsigned int, unsigned int N = 16>
Val& libMesh::chunked_mapvector< Val, index_t, N >::operator[] ( const index_t &  k)
inline

Definition at line 203 of file chunked_mapvector.h.

204  {
205  return maptype::operator[](k/N)[k%N];
206  }

◆ operator[]() [2/2]

template<typename Val , typename index_t = unsigned int, unsigned int N = 16>
Val libMesh::chunked_mapvector< Val, index_t, N >::operator[] ( const index_t &  k) const
inline

Definition at line 208 of file chunked_mapvector.h.

References libMesh::chunked_mapvector< Val, index_t, N >::end().

209  {
210  typename maptype::const_iterator it = maptype::find(k/N);
211  return it == this->end().it? Val() : (it->second)[k%N];
212  }

◆ rbegin()

template<typename Val , typename index_t = unsigned int, unsigned int N = 16>
const_reverse_veclike_iterator libMesh::chunked_mapvector< Val, index_t, N >::rbegin ( ) const
inline

Definition at line 269 of file chunked_mapvector.h.

270  {
271  return const_reverse_veclike_iterator(maptype::rbegin(), N-1);
272  }

◆ rend()

template<typename Val , typename index_t = unsigned int, unsigned int N = 16>
const_reverse_veclike_iterator libMesh::chunked_mapvector< Val, index_t, N >::rend ( ) const
inline

Definition at line 274 of file chunked_mapvector.h.

275  {
276  return const_reverse_veclike_iterator(maptype::rend(), N-1);
277  }

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