MFEM  v3.0
 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 ()
 
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...
 

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 112 of file hash.hpp.

Constructor & Destructor Documentation

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

Definition at line 214 of file hash.hpp.

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

Definition at line 227 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 403 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 279 of file hash.hpp.

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

Definition at line 306 of file hash.hpp.

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

Definition at line 128 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 132 of file hash.hpp.

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

Definition at line 184 of file hash.hpp.

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

Definition at line 187 of file hash.hpp.

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

Definition at line 191 of file hash.hpp.

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

Definition at line 194 of file hash.hpp.

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

Definition at line 270 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 462 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 256 of file hash.hpp.

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

Definition at line 263 of file hash.hpp.

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

Definition at line 136 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 140 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 144 of file hash.hpp.

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

Check table load and resize if necessary.

Definition at line 356 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 418 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 432 of file hash.hpp.

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

Definition at line 334 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 345 of file hash.hpp.

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

Definition at line 385 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 206 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 207 of file hash.hpp.

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

Definition at line 180 of file hash.hpp.

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

Definition at line 181 of file hash.hpp.

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

Definition at line 179 of file hash.hpp.


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