hashtable cleanup

git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@2544 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
Lee Salzman
2008-09-12 09:17:33 +00:00
parent 9da700bb9c
commit c521ccf993
3 changed files with 20 additions and 24 deletions
+6 -6
View File
@@ -55,7 +55,7 @@ ident *newident(const char *name)
if(!id)
{
ident init(ID_ALIAS, newstring(name), newstring(""), persistidents, IEXC_CORE);
id = idents->access(init.name, &init);
id = &idents->access(init.name, init);
}
return id;
}
@@ -85,7 +85,7 @@ void alias(const char *name, const char *action)
if(!b)
{
ident b(ID_ALIAS, newstring(name), newstring(action), persistidents, execcontext);
idents->access(b.name, &b);
idents->access(b.name, b);
}
else if(b->type==ID_ALIAS)
{
@@ -104,7 +104,7 @@ int variable(const char *name, int minval, int cur, int maxval, int *storage, vo
{
if(!idents) idents = new hashtable<const char *, ident>;
ident v(ID_VAR, name, minval, maxval, storage, fun, persist, IEXC_CORE);
idents->access(name, &v);
idents->access(name, v);
return cur;
}
@@ -112,7 +112,7 @@ float fvariable(const char *name, float cur, float *storage, void (*fun)(), bool
{
if(!idents) idents = new hashtable<const char *, ident>;
ident v(ID_FVAR, name, storage, fun, persist, IEXC_CORE);
idents->access(name, &v);
idents->access(name, v);
return cur;
}
@@ -120,7 +120,7 @@ char *svariable(const char *name, const char *cur, char **storage, void (*fun)()
{
if(!idents) idents = new hashtable<const char *, ident>;
ident v(ID_SVAR, name, storage, fun, persist, IEXC_CORE);
idents->access(name, &v);
idents->access(name, v);
return newstring(cur);
}
@@ -151,7 +151,7 @@ bool addcommand(const char *name, void (*fun)(), int narg)
{
if(!idents) idents = new hashtable<const char *, ident>;
ident c(ID_COMMAND, name, fun, narg, IEXC_CORE);
idents->access(name, &c);
idents->access(name, c);
return false;
}
+1 -1
View File
@@ -107,7 +107,7 @@ model *loadmodel(const char *name, int i)
}
}
loadingmodel = NULL;
mdllookup.access(m->name(), &m);
mdllookup.access(m->name(), m);
}
if(mapmodels.inrange(i) && !mapmodels[i].m) mapmodels[i].m = m;
return m;
+13 -17
View File
@@ -430,35 +430,31 @@ template <class K, class T> struct hashtable
return c;
}
chain *find(const K &key, bool doinsert)
{
uint h = hthash(key)&(size-1);
for(chain *c = table[h]; c; c = c->next)
{
if(htcmp(key, c->key)) return c;
}
if(doinsert) return insert(key, h);
return NULL;
}
#define HTFIND(success, fail) \
uint h = hthash(key)&(size-1); \
for(chain *c = table[h]; c; c = c->next) \
{ \
if(htcmp(key, c->key)) return (success); \
} \
return (fail);
T *access(const K &key, const T *data = NULL)
T *access(const K &key)
{
chain *c = find(key, data != NULL);
if(data) c->data = *data;
if(c) return &c->data;
return NULL;
HTFIND(&c->data, NULL);
}
T &access(const K &key, const T &data)
{
return *access(key, &data);
HTFIND(c->data, insert(key, h)->data = data);
}
T &operator[](const K &key)
{
return find(key, true)->data;
HTFIND(c->data, insert(key, h)->data);
}
#undef HTFIND
bool remove(const K &key)
{
uint h = hthash(key)&(size-1);