nrnhash.h File Reference
#include <ivstream.h>
#include <vector.h>
#include <map.h>
Go to the source code of this file.
Define Documentation
#define __NrnHashEntry |
( |
Table |
|
) |
Table##_Entry |
#define __NrnHashLT |
( |
Table |
|
) |
nrnhash_lt_##Table |
#define declareNrnHash |
( |
Table, |
|
|
Key, |
|
|
Value |
|
) |
|
Value:struct NrnHashLT(Table) { \
int operator() (Key i, Key j) const { \
return ((unsigned long)i) < ((unsigned long)j); \
} \
}; \
\
class NrnHashEntry(Table) : public std::map <Key, Value, NrnHashLT(Table)>{}; \
\
class Table : public vector<NrnHashEntry(Table)> { \
public: \
Table(long size); \
virtual ~Table(); \
boolean find(Key, Value&)const; \
NrnHashEntry(Table)& at(unsigned long bucket){ return *(begin() + bucket); } \
Value& operator[](Key key) { return at(hash(key))[key]; } \
void remove(Key); \
unsigned long hash(Key key)const { return ((unsigned long)key)%size_; } \
long size_; \
};
#define implementNrnHash |
( |
Table, |
|
|
Key, |
|
|
Value |
|
) |
|
Value:Table::Table(long size) { \
resize(size+1); \
size_ = size; \
} \
\
Table::~Table() {} \
\
boolean Table::find(Key key, Value& ps)const { \
NrnHashEntry(Table)::const_iterator itr; \
const NrnHashEntry(Table)& gm = ((Table*)this)->at(hash(key)); \
if ((itr = gm.find(key)) == gm.end()) { \
return false; \
} \
ps = itr->second; \
return true; \
}\
\
void Table::remove(Key key) { \
NrnHashEntry(Table)& gm = ((Table*)this)->at(hash(key)); \
gm.erase(key); \
}
#define NrnHashEntry |
( |
Table |
|
) |
__NrnHashEntry(Table) |
#define NrnHashIterate |
( |
Table, |
|
|
table, |
|
|
Value, |
|
|
value |
|
) |
|
#define NrnHashLT |
( |
Table |
|
) |
__NrnHashLT(Table) |