MFEM  v3.1
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
mfem::HashTable< ItemT > Class Template Reference

#include <hash.hpp>

Collaboration diagram for mfem::HashTable< ItemT >:
[legend]

Classes

class  Iterator
 Iterator over items contained in the HashTable. More...
 

Public Member Functions

 HashTable (int init_size=32 *1024)
 
 HashTable (const HashTable &other)
 
 ~HashTable ()
 
ItemT * Get (int p1, int p2)
 Get an item whose parents are p1, p2... Create it if it doesn't exist. More...
 
ItemT * Get (int p1, int p2, int p3, int p4)
 
ItemT * Peek (int p1, int p2) const
 Get an item whose parents are p1, p2... Return NULL if it doesn't exist. More...
 
ItemT * Peek (int p1, int p2, int p3, int p4) const
 
template<typename OtherT >
ItemT * Get (OtherT *i1, OtherT *i2)
 
template<typename OtherT >
ItemT * Get (OtherT *i1, OtherT *i2, OtherT *i3, OtherT *i4)
 
template<typename OtherT >
ItemT * Peek (OtherT *i1, OtherT *i2) const
 
template<typename OtherT >
ItemT * Peek (OtherT *i1, OtherT *i2, OtherT *i3, OtherT *i4) const
 
ItemT * Peek (int id) const
 Obtains an item given its ID. More...
 
void Delete (ItemT *item)
 Remove an item from the hash table and also delete the item itself. More...
 
void Reparent (ItemT *item, int new_p1, int new_p2)
 Make an item hashed under different parent IDs. More...
 
void Reparent (ItemT *item, int new_p1, int new_p2, int new_p3, int new_p4)
 
long MemoryUsage () const
 Return total size of allocated memory (tables plus items), in bytes. More...
 
void PrintMemoryDetail () const
 

Protected Member Functions

int hash (int p1, int p2) const
 
int hash (int p1, int p2, int p3) const
 
int hash (const Hashed2< ItemT > *item) const
 
int hash (const Hashed4< ItemT > *item) const
 
ItemT * SearchList (ItemT *item, int p1, int p2) const
 
ItemT * SearchList (ItemT *item, int p1, int p2, int p3) const
 
void Insert (int idx, ItemT *item)
 
void Unlink (ItemT *item)
 
void Rehash ()
 Check table load and resize if necessary. More...
 

Protected Attributes

ItemT ** table
 
int mask
 
int num_items
 
IdGenerator id_gen
 id generator for new items More...
 
Array< ItemT * > id_to_item
 mapping table for the Peek(id) method More...
 

Detailed Description

template<typename ItemT>
class mfem::HashTable< ItemT >

HashTable is a container for items that require associative access through pairs (or quadruples) of indices:

(p1, p2) -> item (p1, p2, p3, p4) -> item

An example of this are edges and faces in a mesh. Each edge is uniquely identified by two parent vertices and so can be easily accessed from different elements using this class. Similarly for faces.

The order of the p1, p2, ... indices is not relevant as they are sorted each time this class is invoked.

There are two main methods this class provides. The Get(...) method always returns an item given the two or four indices. If the item didn't previously exist, the methods creates a new one. The Peek(...) method, on the other hand, just returns NULL if the item doesn't exist.

Each new item is automatically assigned a unique ID. The IDs may (but need not) be used as p1, p2, ... of other items.

The item type (ItemT) needs to follow either the Hashed2 or the Hashed4 concept. It is easiest to just inherit from these structs.

All items in the container can also be accessed sequentially using the provided iterator.

Definition at line 117 of file hash.hpp.

Constructor & Destructor Documentation

template<typename ItemT >
mfem::HashTable< ItemT >::HashTable ( int  init_size = 32*1024)

Definition at line 222 of file hash.hpp.

template<typename ItemT >
mfem::HashTable< ItemT >::HashTable ( const HashTable< ItemT > &  other)

Definition at line 237 of file hash.hpp.

template<typename ItemT >
mfem::HashTable< ItemT >::~HashTable ( )

Definition at line 256 of file hash.hpp.

Member Function Documentation

template<typename ItemT>
void mfem::HashTable< ItemT >::Delete ( ItemT *  item)

Remove an item from the hash table and also delete the item itself.

Definition at line 438 of file hash.hpp.

template<typename ItemT >
ItemT * mfem::HashTable< ItemT >::Get ( int  p1,
int  p2 
)

Get an item whose parents are p1, p2... Create it if it doesn't exist.

Definition at line 310 of file hash.hpp.

template<typename ItemT >
ItemT * mfem::HashTable< ItemT >::Get ( int  p1,
int  p2,
int  p3,
int  p4 
)

Definition at line 338 of file hash.hpp.

template<typename ItemT>
template<typename OtherT >
ItemT* mfem::HashTable< ItemT >::Get ( OtherT *  i1,
OtherT *  i2 
)
inline

Definition at line 134 of file hash.hpp.

template<typename ItemT>
template<typename OtherT >
ItemT* mfem::HashTable< ItemT >::Get ( OtherT *  i1,
OtherT *  i2,
OtherT *  i3,
OtherT *  i4 
)
inline

Definition at line 138 of file hash.hpp.

template<typename ItemT>
int mfem::HashTable< ItemT >::hash ( int  p1,
int  p2 
) const
inlineprotected

Definition at line 192 of file hash.hpp.

template<typename ItemT>
int mfem::HashTable< ItemT >::hash ( int  p1,
int  p2,
int  p3 
) const
inlineprotected

Definition at line 195 of file hash.hpp.

template<typename ItemT>
int mfem::HashTable< ItemT >::hash ( const Hashed2< ItemT > *  item) const
inlineprotected

Definition at line 199 of file hash.hpp.

template<typename ItemT>
int mfem::HashTable< ItemT >::hash ( const Hashed4< ItemT > *  item) const
inlineprotected

Definition at line 202 of file hash.hpp.

template<typename ItemT>
void mfem::HashTable< ItemT >::Insert ( int  idx,
ItemT *  item 
)
protected

Definition at line 301 of file hash.hpp.

template<typename ItemT >
long mfem::HashTable< ItemT >::MemoryUsage ( ) const

Return total size of allocated memory (tables plus items), in bytes.

Definition at line 497 of file hash.hpp.

template<typename ItemT >
ItemT * mfem::HashTable< ItemT >::Peek ( int  p1,
int  p2 
) const

Get an item whose parents are p1, p2... Return NULL if it doesn't exist.

Definition at line 287 of file hash.hpp.

template<typename ItemT >
ItemT * mfem::HashTable< ItemT >::Peek ( int  p1,
int  p2,
int  p3,
int  p4 
) const

Definition at line 294 of file hash.hpp.

template<typename ItemT>
template<typename OtherT >
ItemT* mfem::HashTable< ItemT >::Peek ( OtherT *  i1,
OtherT *  i2 
) const
inline

Definition at line 142 of file hash.hpp.

template<typename ItemT>
template<typename OtherT >
ItemT* mfem::HashTable< ItemT >::Peek ( OtherT *  i1,
OtherT *  i2,
OtherT *  i3,
OtherT *  i4 
) const
inline

Definition at line 146 of file hash.hpp.

template<typename ItemT>
ItemT* mfem::HashTable< ItemT >::Peek ( int  id) const
inline

Obtains an item given its ID.

Definition at line 150 of file hash.hpp.

template<typename ItemT >
void mfem::HashTable< ItemT >::PrintMemoryDetail ( ) const

Definition at line 504 of file hash.hpp.

template<typename ItemT >
void mfem::HashTable< ItemT >::Rehash ( )
protected

Check table load and resize if necessary.

Definition at line 389 of file hash.hpp.

template<typename ItemT>
void mfem::HashTable< ItemT >::Reparent ( ItemT *  item,
int  new_p1,
int  new_p2 
)

Make an item hashed under different parent IDs.

Definition at line 453 of file hash.hpp.

template<typename ItemT>
void mfem::HashTable< ItemT >::Reparent ( ItemT *  item,
int  new_p1,
int  new_p2,
int  new_p3,
int  new_p4 
)

Definition at line 467 of file hash.hpp.

template<typename ItemT>
ItemT * mfem::HashTable< ItemT >::SearchList ( ItemT *  item,
int  p1,
int  p2 
) const
protected

Definition at line 367 of file hash.hpp.

template<typename ItemT>
ItemT * mfem::HashTable< ItemT >::SearchList ( ItemT *  item,
int  p1,
int  p2,
int  p3 
) const
protected

Definition at line 378 of file hash.hpp.

template<typename ItemT>
void mfem::HashTable< ItemT >::Unlink ( ItemT *  item)
protected

Definition at line 420 of file hash.hpp.

Member Data Documentation

template<typename ItemT>
IdGenerator mfem::HashTable< ItemT >::id_gen
protected

id generator for new items

Definition at line 214 of file hash.hpp.

template<typename ItemT>
Array<ItemT*> mfem::HashTable< ItemT >::id_to_item
protected

mapping table for the Peek(id) method

Definition at line 215 of file hash.hpp.

template<typename ItemT>
int mfem::HashTable< ItemT >::mask
protected

Definition at line 188 of file hash.hpp.

template<typename ItemT>
int mfem::HashTable< ItemT >::num_items
protected

Definition at line 189 of file hash.hpp.

template<typename ItemT>
ItemT** mfem::HashTable< ItemT >::table
protected

Definition at line 187 of file hash.hpp.


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