2003-04-07 16:38:34 +00:00
|
|
|
/*
|
|
|
|
bi_hash.c
|
|
|
|
|
|
|
|
QuakeC hash table api
|
|
|
|
|
2003-04-10 16:54:12 +00:00
|
|
|
Copyright (C) 2003 Bill Currie
|
2003-04-07 16:38:34 +00:00
|
|
|
|
|
|
|
Author: Bill Currie <bill@taniwha.org>
|
|
|
|
Date: 2003/4/7
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "QF/hash.h"
|
|
|
|
#include "QF/progs.h"
|
2004-01-16 07:03:58 +00:00
|
|
|
|
|
|
|
#include "rua_internal.h"
|
2003-04-07 16:38:34 +00:00
|
|
|
|
|
|
|
typedef struct bi_hashtab_s {
|
|
|
|
struct bi_hashtab_s *next;
|
|
|
|
struct bi_hashtab_s **prev;
|
|
|
|
progs_t *pr;
|
|
|
|
hashtab_t *tab;
|
2022-01-18 06:32:43 +00:00
|
|
|
pr_func_t gk;
|
|
|
|
pr_func_t gh;
|
|
|
|
pr_func_t cmp;
|
|
|
|
pr_func_t f;
|
2022-01-18 03:11:14 +00:00
|
|
|
pr_ptr_t ud;
|
2003-04-07 16:38:34 +00:00
|
|
|
} bi_hashtab_t;
|
|
|
|
|
|
|
|
typedef struct {
|
2004-11-11 07:57:00 +00:00
|
|
|
PR_RESMAP (bi_hashtab_t) table_map;
|
2003-04-07 16:38:34 +00:00
|
|
|
bi_hashtab_t *tabs;
|
|
|
|
} hash_resources_t;
|
|
|
|
|
2004-11-11 07:57:00 +00:00
|
|
|
static bi_hashtab_t *
|
|
|
|
table_new (hash_resources_t *res)
|
|
|
|
{
|
2021-03-21 12:26:36 +00:00
|
|
|
return PR_RESNEW (res->table_map);
|
2004-11-11 07:57:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
table_free (hash_resources_t *res, bi_hashtab_t *table)
|
|
|
|
{
|
2021-03-21 12:26:36 +00:00
|
|
|
PR_RESFREE (res->table_map, table);
|
2004-11-11 07:57:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
table_reset (hash_resources_t *res)
|
|
|
|
{
|
2021-03-21 12:26:36 +00:00
|
|
|
PR_RESRESET (res->table_map);
|
2004-11-11 07:57:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bi_hashtab_t *
|
|
|
|
table_get (hash_resources_t *res, int index)
|
|
|
|
{
|
2021-03-21 12:26:36 +00:00
|
|
|
return PR_RESGET(res->table_map, index);
|
2004-11-11 07:57:00 +00:00
|
|
|
}
|
|
|
|
|
2020-12-20 17:12:51 +00:00
|
|
|
static inline int __attribute__((pure))
|
2004-11-11 07:57:00 +00:00
|
|
|
table_index (hash_resources_t *res, bi_hashtab_t *table)
|
|
|
|
{
|
2021-03-21 12:26:36 +00:00
|
|
|
return PR_RESINDEX(res->table_map, table);
|
2004-11-11 07:57:00 +00:00
|
|
|
}
|
|
|
|
|
2003-04-07 16:38:34 +00:00
|
|
|
static const char *
|
2012-07-18 13:34:37 +00:00
|
|
|
bi_get_key (const void *key, void *_ht)
|
2003-04-07 16:38:34 +00:00
|
|
|
{
|
|
|
|
bi_hashtab_t *ht = (bi_hashtab_t *)_ht;
|
2022-01-31 14:45:29 +00:00
|
|
|
PR_PushFrame (ht->pr);
|
2005-06-12 09:54:01 +00:00
|
|
|
PR_RESET_PARAMS (ht->pr);
|
2007-04-04 07:48:14 +00:00
|
|
|
P_INT (ht->pr, 0) = (intptr_t) (key);
|
2003-04-07 16:38:34 +00:00
|
|
|
P_INT (ht->pr, 1) = ht->ud;
|
2020-02-25 08:28:32 +00:00
|
|
|
ht->pr->pr_argc = 2;
|
2003-04-07 16:38:34 +00:00
|
|
|
PR_ExecuteProgram (ht->pr, ht->gk);
|
2022-01-31 14:45:29 +00:00
|
|
|
pr_string_t string = R_STRING (ht->pr);
|
|
|
|
PR_PopFrame (ht->pr);
|
|
|
|
return PR_GetString (ht->pr, string);
|
2003-04-07 16:38:34 +00:00
|
|
|
}
|
|
|
|
|
2007-04-04 07:48:14 +00:00
|
|
|
static uintptr_t
|
2012-07-18 13:34:37 +00:00
|
|
|
bi_get_hash (const void *key, void *_ht)
|
2003-04-07 16:38:34 +00:00
|
|
|
{
|
|
|
|
bi_hashtab_t *ht = (bi_hashtab_t *)_ht;
|
2022-01-31 14:45:29 +00:00
|
|
|
PR_PushFrame (ht->pr);
|
2005-06-12 09:54:01 +00:00
|
|
|
PR_RESET_PARAMS (ht->pr);
|
2007-04-04 07:48:14 +00:00
|
|
|
P_INT (ht->pr, 0) = (intptr_t) (key);
|
2003-04-07 16:38:34 +00:00
|
|
|
P_INT (ht->pr, 1) = ht->ud;
|
2020-02-25 08:28:32 +00:00
|
|
|
ht->pr->pr_argc = 2;
|
2003-04-07 16:38:34 +00:00
|
|
|
PR_ExecuteProgram (ht->pr, ht->gh);
|
2022-01-31 14:45:29 +00:00
|
|
|
int hash = R_INT (ht->pr);
|
|
|
|
PR_PopFrame (ht->pr);
|
|
|
|
return hash;
|
2003-04-07 16:38:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2012-07-18 13:34:37 +00:00
|
|
|
bi_compare (const void *key1, const void *key2, void *_ht)
|
2003-04-07 16:38:34 +00:00
|
|
|
{
|
|
|
|
bi_hashtab_t *ht = (bi_hashtab_t *)_ht;
|
2022-01-31 14:45:29 +00:00
|
|
|
PR_PushFrame (ht->pr);
|
2005-06-12 09:54:01 +00:00
|
|
|
PR_RESET_PARAMS (ht->pr);
|
2007-04-04 07:48:14 +00:00
|
|
|
P_INT (ht->pr, 0) = (intptr_t) (key1);
|
|
|
|
P_INT (ht->pr, 1) = (intptr_t) (key2);
|
2003-04-07 16:38:34 +00:00
|
|
|
P_INT (ht->pr, 2) = ht->ud;
|
2020-02-25 08:28:32 +00:00
|
|
|
ht->pr->pr_argc = 3;
|
2003-04-07 16:38:34 +00:00
|
|
|
PR_ExecuteProgram (ht->pr, ht->cmp);
|
2022-01-31 14:45:29 +00:00
|
|
|
int cmp = R_INT (ht->pr);
|
|
|
|
PR_PopFrame (ht->pr);
|
|
|
|
return cmp;
|
2003-04-07 16:38:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bi_free (void *key, void *_ht)
|
|
|
|
{
|
|
|
|
bi_hashtab_t *ht = (bi_hashtab_t *)_ht;
|
2022-01-31 14:45:29 +00:00
|
|
|
PR_PushFrame (ht->pr);
|
2005-06-12 09:54:01 +00:00
|
|
|
PR_RESET_PARAMS (ht->pr);
|
2007-04-04 07:48:14 +00:00
|
|
|
P_INT (ht->pr, 0) = (intptr_t) (key);
|
2003-04-07 16:38:34 +00:00
|
|
|
P_INT (ht->pr, 1) = ht->ud;
|
2020-02-25 08:28:32 +00:00
|
|
|
ht->pr->pr_argc = 2;
|
2003-04-07 16:38:34 +00:00
|
|
|
PR_ExecuteProgram (ht->pr, ht->f);
|
2022-01-31 14:45:29 +00:00
|
|
|
PR_PopFrame (ht->pr);
|
2003-04-07 16:38:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Hash_NewTable (progs_t *pr, void *_res)
|
2003-04-07 16:38:34 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
__auto_type res = (hash_resources_t *) _res;
|
2003-04-07 16:38:34 +00:00
|
|
|
int tsize = P_INT (pr, 0);
|
2012-07-18 13:34:37 +00:00
|
|
|
const char *(*gk)(const void*,void*);
|
2003-04-07 16:38:34 +00:00
|
|
|
void (*f)(void*,void*);
|
|
|
|
bi_hashtab_t *ht;
|
|
|
|
|
2004-11-11 07:57:00 +00:00
|
|
|
ht = table_new (res);
|
2003-04-07 16:38:34 +00:00
|
|
|
ht->pr = pr;
|
|
|
|
ht->gk = P_FUNCTION (pr, 1);
|
|
|
|
ht->f = P_FUNCTION (pr, 2);
|
|
|
|
ht->ud = P_INT (pr, 3); // don't convert pointer for speed reasons
|
|
|
|
|
|
|
|
ht->next = res->tabs;
|
|
|
|
ht->prev = &res->tabs;
|
2004-11-11 07:57:00 +00:00
|
|
|
if (res->tabs)
|
|
|
|
res->tabs->prev = &ht->next;
|
|
|
|
res->tabs = ht;
|
2003-04-07 16:38:34 +00:00
|
|
|
|
|
|
|
gk = ht->gk ? bi_get_key : 0;
|
|
|
|
f = ht->f ? bi_free : 0;
|
2020-03-25 06:43:16 +00:00
|
|
|
ht->tab = Hash_NewTable (tsize, gk, f, ht, pr->hashlink_freelist);
|
2004-11-11 07:57:00 +00:00
|
|
|
R_INT (pr) = table_index (res, ht);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bi_hashtab_t *
|
2022-02-14 03:28:38 +00:00
|
|
|
get_table (progs_t *pr, hash_resources_t *res, const char *name, int index)
|
2004-11-11 07:57:00 +00:00
|
|
|
{
|
|
|
|
bi_hashtab_t *ht = table_get (res, index);
|
|
|
|
|
|
|
|
if (!ht)
|
|
|
|
PR_RunError (pr, "invalid hash table index passed to %s", name + 3);
|
|
|
|
return ht;
|
2003-04-07 16:38:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Hash_SetHashCompare (progs_t *pr, void *_res)
|
2003-04-07 16:38:34 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
__auto_type res = (hash_resources_t *) _res;
|
|
|
|
bi_hashtab_t *ht = get_table (pr, res, __FUNCTION__, P_INT (pr, 0));
|
2012-07-18 13:34:37 +00:00
|
|
|
uintptr_t (*gh)(const void*,void*);
|
|
|
|
int (*cmp)(const void*,const void*,void*);
|
2003-04-07 16:38:34 +00:00
|
|
|
|
|
|
|
ht->gh = P_FUNCTION (pr, 1);
|
|
|
|
ht->cmp = P_FUNCTION (pr, 2);
|
|
|
|
gh = ht->gh ? bi_get_hash : 0;
|
|
|
|
cmp = ht->cmp ? bi_compare : 0;
|
|
|
|
Hash_SetHashCompare (ht->tab, gh, cmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Hash_DelTable (progs_t *pr, void *_res)
|
2003-04-07 16:38:34 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
__auto_type res = (hash_resources_t *) _res;
|
|
|
|
bi_hashtab_t *ht = get_table (pr, res, __FUNCTION__, P_INT (pr, 0));
|
2003-04-07 16:38:34 +00:00
|
|
|
|
|
|
|
Hash_DelTable (ht->tab);
|
|
|
|
*ht->prev = ht->next;
|
2011-07-09 00:42:11 +00:00
|
|
|
if (ht->next)
|
|
|
|
ht->next->prev = ht->prev;
|
2004-11-11 07:57:00 +00:00
|
|
|
table_free (res, ht);
|
2003-04-07 16:38:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Hash_FlushTable (progs_t *pr, void *_res)
|
2003-04-07 16:38:34 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
__auto_type res = (hash_resources_t *) _res;
|
|
|
|
bi_hashtab_t *ht = get_table (pr, res, __FUNCTION__, P_INT (pr, 0));
|
2003-04-07 16:38:34 +00:00
|
|
|
|
|
|
|
Hash_FlushTable (ht->tab);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Hash_Add (progs_t *pr, void *_res)
|
2003-04-07 16:38:34 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
__auto_type res = (hash_resources_t *) _res;
|
|
|
|
bi_hashtab_t *ht = get_table (pr, res, __FUNCTION__, P_INT (pr, 0));
|
2003-04-07 16:38:34 +00:00
|
|
|
|
2007-04-04 07:48:14 +00:00
|
|
|
R_INT (pr) = Hash_Add (ht->tab, (void *) (intptr_t) P_INT (pr, 1));
|
2003-04-07 16:38:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Hash_AddElement (progs_t *pr, void *_res)
|
2003-04-07 16:38:34 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
__auto_type res = (hash_resources_t *) _res;
|
|
|
|
bi_hashtab_t *ht = get_table (pr, res, __FUNCTION__, P_INT (pr, 0));
|
2003-04-07 16:38:34 +00:00
|
|
|
|
2007-04-04 07:48:14 +00:00
|
|
|
R_INT (pr) = Hash_AddElement (ht->tab, (void *) (intptr_t) P_INT (pr, 1));
|
2003-04-07 16:38:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Hash_Find (progs_t *pr, void *_res)
|
2003-04-07 16:38:34 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
__auto_type res = (hash_resources_t *) _res;
|
|
|
|
bi_hashtab_t *ht = get_table (pr, res, __FUNCTION__, P_INT (pr, 0));
|
2003-04-07 16:38:34 +00:00
|
|
|
|
2007-04-04 07:48:14 +00:00
|
|
|
R_INT (pr) = (intptr_t) Hash_Find (ht->tab, P_GSTRING (pr, 1));
|
2003-04-07 16:38:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Hash_FindElement (progs_t *pr, void *_res)
|
2003-04-07 16:38:34 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
__auto_type res = (hash_resources_t *) _res;
|
|
|
|
bi_hashtab_t *ht = get_table (pr, res, __FUNCTION__, P_INT (pr, 0));
|
2003-04-07 16:38:34 +00:00
|
|
|
|
2007-04-04 07:48:14 +00:00
|
|
|
R_INT (pr) = (intptr_t) Hash_FindElement (ht->tab,
|
|
|
|
(void *) (intptr_t) P_INT (pr, 1));
|
2003-04-07 16:38:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Hash_FindList (progs_t *pr, void *_res)
|
2003-04-07 16:38:34 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
__auto_type res = (hash_resources_t *) _res;
|
|
|
|
bi_hashtab_t *ht = get_table (pr, res, __FUNCTION__, P_INT (pr, 0));
|
2003-04-07 16:38:34 +00:00
|
|
|
void **list, **l;
|
|
|
|
pr_type_t *pr_list;
|
|
|
|
int count;
|
|
|
|
|
2003-04-22 18:20:15 +00:00
|
|
|
list = Hash_FindList (ht->tab, P_GSTRING (pr, 1));
|
2003-04-07 16:38:34 +00:00
|
|
|
for (count = 1, l = list; *l; l++)
|
|
|
|
count++;
|
|
|
|
pr_list = PR_Zone_Malloc (pr, count * sizeof (pr_type_t));
|
2004-11-11 07:57:00 +00:00
|
|
|
// the hash tables stores progs pointers...
|
2003-04-07 16:38:34 +00:00
|
|
|
for (count = 0, l = list; *l; l++)
|
2022-01-18 04:21:06 +00:00
|
|
|
pr_list[count++].int_var = (intptr_t) *l;
|
2003-04-07 16:38:34 +00:00
|
|
|
free (list);
|
|
|
|
RETURN_POINTER (pr, pr_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Hash_FindElementList (progs_t *pr, void *_res)
|
2003-04-07 16:38:34 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
__auto_type res = (hash_resources_t *) _res;
|
|
|
|
bi_hashtab_t *ht = get_table (pr, res, __FUNCTION__, P_INT (pr, 0));
|
2003-04-07 16:38:34 +00:00
|
|
|
void **list, **l;
|
|
|
|
pr_type_t *pr_list;
|
|
|
|
int count;
|
|
|
|
|
2007-04-04 07:48:14 +00:00
|
|
|
list = Hash_FindElementList (ht->tab, (void *) (intptr_t) P_INT (pr, 1));
|
2003-04-07 16:38:34 +00:00
|
|
|
for (count = 1, l = list; *l; l++)
|
|
|
|
count++;
|
|
|
|
pr_list = PR_Zone_Malloc (pr, count * sizeof (pr_type_t));
|
2004-11-11 07:57:00 +00:00
|
|
|
// the hash tables stores progs pointers...
|
2003-04-07 16:38:34 +00:00
|
|
|
for (count = 0, l = list; *l; l++)
|
2022-01-18 04:21:06 +00:00
|
|
|
pr_list[count++].int_var = (intptr_t) *l;
|
2003-04-07 16:38:34 +00:00
|
|
|
free (list);
|
|
|
|
RETURN_POINTER (pr, pr_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Hash_Del (progs_t *pr, void *_res)
|
2003-04-07 16:38:34 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
__auto_type res = (hash_resources_t *) _res;
|
|
|
|
bi_hashtab_t *ht = get_table (pr, res, __FUNCTION__, P_INT (pr, 0));
|
2003-04-07 16:38:34 +00:00
|
|
|
|
2007-04-04 07:48:14 +00:00
|
|
|
R_INT (pr) = (intptr_t) Hash_Del (ht->tab, P_GSTRING (pr, 1));
|
2003-04-07 16:38:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Hash_DelElement (progs_t *pr, void *_res)
|
2003-04-07 16:38:34 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
__auto_type res = (hash_resources_t *) _res;
|
|
|
|
bi_hashtab_t *ht = get_table (pr, res, __FUNCTION__, P_INT (pr, 0));
|
2003-04-07 16:38:34 +00:00
|
|
|
|
2007-04-04 07:48:14 +00:00
|
|
|
R_INT (pr) = (intptr_t) Hash_DelElement (ht->tab,
|
|
|
|
(void *) (intptr_t) P_INT (pr, 1));
|
2003-04-07 16:38:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Hash_Free (progs_t *pr, void *_res)
|
2003-04-07 16:38:34 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
__auto_type res = (hash_resources_t *) _res;
|
|
|
|
bi_hashtab_t *ht = get_table (pr, res, __FUNCTION__, P_INT (pr, 0));
|
2003-04-07 16:38:34 +00:00
|
|
|
|
2007-04-04 07:48:14 +00:00
|
|
|
Hash_Free (ht->tab, (void *) (intptr_t) P_INT (pr, 1));
|
2003-04-07 16:38:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Hash_String (progs_t *pr, void *_res)
|
2003-04-07 16:38:34 +00:00
|
|
|
{
|
2003-04-22 18:20:15 +00:00
|
|
|
R_INT (pr) = Hash_String (P_GSTRING (pr, 0));
|
2003-04-07 16:38:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Hash_Buffer (progs_t *pr, void *_res)
|
2003-04-07 16:38:34 +00:00
|
|
|
{
|
2003-04-22 18:20:15 +00:00
|
|
|
R_INT (pr) = Hash_Buffer (P_GPOINTER (pr, 0), P_INT (pr, 1));
|
2003-04-07 16:38:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Hash_GetList (progs_t *pr, void *_res)
|
2003-04-07 16:38:34 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
__auto_type res = (hash_resources_t *) _res;
|
|
|
|
bi_hashtab_t *ht = get_table (pr, res, __FUNCTION__, P_INT (pr, 0));
|
2003-04-07 16:38:34 +00:00
|
|
|
void **list, **l;
|
|
|
|
pr_type_t *pr_list;
|
|
|
|
int count;
|
|
|
|
|
|
|
|
list = Hash_GetList (ht->tab);
|
|
|
|
for (count = 1, l = list; *l; l++)
|
|
|
|
count++;
|
|
|
|
pr_list = PR_Zone_Malloc (pr, count * sizeof (pr_type_t));
|
2004-11-11 07:57:00 +00:00
|
|
|
// the hash tables stores progs pointers...
|
2003-04-07 16:38:34 +00:00
|
|
|
for (count = 0, l = list; *l; l++)
|
2022-01-18 04:21:06 +00:00
|
|
|
pr_list[count++].int_var = (intptr_t) *l;
|
2003-04-07 16:38:34 +00:00
|
|
|
free (list);
|
|
|
|
RETURN_POINTER (pr, pr_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Hash_Stats (progs_t *pr, void *_res)
|
2003-04-07 16:38:34 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
__auto_type res = (hash_resources_t *) _res;
|
|
|
|
bi_hashtab_t *ht = get_table (pr, res, __FUNCTION__, P_INT (pr, 0));
|
2003-04-07 16:38:34 +00:00
|
|
|
|
|
|
|
Hash_Stats (ht->tab);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_hash_clear (progs_t *pr, void *_res)
|
2003-04-07 16:38:34 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
hash_resources_t *res = (hash_resources_t *) _res;
|
2003-04-07 16:38:34 +00:00
|
|
|
bi_hashtab_t *ht;
|
|
|
|
|
|
|
|
for (ht = res->tabs; ht; ht = ht->next)
|
|
|
|
Hash_DelTable (ht->tab);
|
|
|
|
res->tabs = 0;
|
2004-11-11 07:57:00 +00:00
|
|
|
table_reset (res);
|
2003-04-07 16:38:34 +00:00
|
|
|
}
|
|
|
|
|
2022-01-23 12:54:03 +00:00
|
|
|
#define bi(x,np,params...) {#x, bi_##x, -1, np, {params}}
|
|
|
|
#define p(type) PR_PARAM(type)
|
2004-01-06 05:51:09 +00:00
|
|
|
static builtin_t builtins[] = {
|
2022-01-23 12:54:03 +00:00
|
|
|
bi(Hash_NewTable, 4, p(int), p(func), p(func), p(ptr)),
|
|
|
|
bi(Hash_SetHashCompare, 3, p(ptr), p(func), p(func)),
|
|
|
|
bi(Hash_DelTable, 1, p(ptr)),
|
|
|
|
bi(Hash_FlushTable, 1, p(ptr)),
|
|
|
|
bi(Hash_Add, 2, p(ptr), p(ptr)),
|
|
|
|
bi(Hash_AddElement, 2, p(ptr), p(ptr)),
|
|
|
|
bi(Hash_Find, 2, p(ptr), p(string)),
|
|
|
|
bi(Hash_FindElement, 2, p(ptr), p(ptr)),
|
|
|
|
bi(Hash_FindList, 2, p(ptr), p(string)),
|
|
|
|
bi(Hash_FindElementList, 2, p(ptr), p(ptr)),
|
|
|
|
bi(Hash_Del, 2, p(ptr), p(string)),
|
|
|
|
bi(Hash_DelElement, 2, p(ptr), p(ptr)),
|
|
|
|
bi(Hash_Free, 2, p(ptr), p(ptr)),
|
|
|
|
bi(Hash_String, 1, p(string)),
|
|
|
|
bi(Hash_Buffer, 2, p(ptr), p(int)),
|
|
|
|
bi(Hash_GetList, 1, p(ptr)),
|
|
|
|
bi(Hash_Stats, 1, p(ptr)),
|
2004-01-06 05:51:09 +00:00
|
|
|
{0}
|
|
|
|
};
|
|
|
|
|
2003-04-07 16:38:34 +00:00
|
|
|
void
|
2004-01-16 07:03:58 +00:00
|
|
|
RUA_Hash_Init (progs_t *pr, int secure)
|
2003-04-07 16:38:34 +00:00
|
|
|
{
|
2004-11-11 07:57:00 +00:00
|
|
|
hash_resources_t *res = calloc (1, sizeof (hash_resources_t));
|
2003-04-07 16:38:34 +00:00
|
|
|
res->tabs = 0;
|
|
|
|
|
|
|
|
PR_Resources_Register (pr, "Hash", res, bi_hash_clear);
|
2022-01-23 15:20:05 +00:00
|
|
|
PR_RegisterBuiltins (pr, builtins, res);
|
2003-04-07 16:38:34 +00:00
|
|
|
}
|