MFEM
v3.0
|
#include <hash.hpp>
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... | |
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.
mfem::HashTable< ItemT >::HashTable | ( | int | init_size = 32*1024 | ) |
mfem::HashTable< ItemT >::~HashTable | ( | ) |
void mfem::HashTable< ItemT >::Delete | ( | ItemT * | item | ) |
ItemT * mfem::HashTable< ItemT >::Get | ( | int | p1, |
int | p2 | ||
) |
ItemT * mfem::HashTable< ItemT >::Get | ( | int | p1, |
int | p2, | ||
int | p3, | ||
int | p4 | ||
) |
|
inline |
|
inline |
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
protected |
long mfem::HashTable< ItemT >::MemoryUsage | ( | ) | const |
ItemT * mfem::HashTable< ItemT >::Peek | ( | int | p1, |
int | p2 | ||
) | const |
ItemT * mfem::HashTable< ItemT >::Peek | ( | int | p1, |
int | p2, | ||
int | p3, | ||
int | p4 | ||
) | const |
|
inline |
|
inline |
|
inline |
|
protected |
void mfem::HashTable< ItemT >::Reparent | ( | ItemT * | item, |
int | new_p1, | ||
int | new_p2 | ||
) |
void mfem::HashTable< ItemT >::Reparent | ( | ItemT * | item, |
int | new_p1, | ||
int | new_p2, | ||
int | new_p3, | ||
int | new_p4 | ||
) |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |