2007-12-30 17:41:49 +01:00
|
|
|
/***************************************************************************
|
|
|
|
|
2015-11-02 04:24:44 +01:00
|
|
|
gb_hash.h
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2022-09-12 15:13:13 +02:00
|
|
|
(c) 2000-2017 Benoît Minisini <benoit.minisini@gambas-basic.org>
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2015-11-02 04:24:44 +01:00
|
|
|
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, or (at your option)
|
|
|
|
any later version.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2015-11-02 04:24:44 +01:00
|
|
|
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.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2015-11-02 04:24:44 +01:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
MA 02110-1301, USA.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __GB_HASH_H
|
|
|
|
#define __GB_HASH_H
|
|
|
|
|
|
|
|
#define KEEP_ORDER
|
|
|
|
|
|
|
|
typedef
|
2015-11-02 04:24:44 +01:00
|
|
|
enum {
|
|
|
|
HF_NORMAL = 0,
|
|
|
|
HF_IGNORE_CASE = 1
|
|
|
|
}
|
|
|
|
HASH_FLAG;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
typedef
|
2015-11-02 04:24:44 +01:00
|
|
|
struct _HASH_NODE
|
|
|
|
{
|
|
|
|
struct _HASH_NODE *next;
|
|
|
|
#ifdef KEEP_ORDER
|
|
|
|
struct _HASH_NODE *snext;
|
|
|
|
struct _HASH_NODE *sprev;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
HASH_NODE;
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
typedef
|
2015-11-02 04:24:44 +01:00
|
|
|
struct {
|
|
|
|
ushort len;
|
|
|
|
char key[0];
|
|
|
|
}
|
|
|
|
PACKED
|
|
|
|
HASH_KEY;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
typedef
|
2015-11-02 04:24:44 +01:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
int size;
|
|
|
|
int nnodes;
|
|
|
|
HASH_NODE **nodes;
|
|
|
|
size_t s_value;
|
|
|
|
HASH_NODE *last;
|
|
|
|
HASH_FLAG mode;
|
|
|
|
#ifdef KEEP_ORDER
|
|
|
|
HASH_NODE *sfirst;
|
|
|
|
HASH_NODE *slast;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
HASH_TABLE;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-10-06 14:03:27 +02:00
|
|
|
// NOTE: If HASH_ENUM changes, GB_COLLECTION_ITER must be updated accordingly in gambas.h
|
2015-11-02 04:24:44 +01:00
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
typedef
|
2015-11-02 04:24:44 +01:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
HASH_NODE *node;
|
|
|
|
HASH_NODE *next;
|
|
|
|
}
|
|
|
|
HASH_ENUM;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
typedef
|
2015-11-02 04:24:44 +01:00
|
|
|
uint (*HASH_FUNC)(const char *, int);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
typedef
|
2015-11-02 04:24:44 +01:00
|
|
|
bool (*HASH_COMP)(const char *, const char *, int);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
#define HASH_TABLE_MIN_SIZE 11
|
|
|
|
#define HASH_TABLE_MAX_SIZE 13845163
|
|
|
|
|
2011-12-31 02:02:42 +01:00
|
|
|
#ifndef __GB_HASH_C
|
|
|
|
extern uint HASH_seed;
|
|
|
|
#endif
|
2015-11-02 04:24:44 +01:00
|
|
|
|
2009-07-08 21:57:50 +02:00
|
|
|
void HASH_TABLE_create(HASH_TABLE **hash, size_t s_value, HASH_FLAG mode);
|
|
|
|
void HASH_TABLE_delete(HASH_TABLE **hash);
|
|
|
|
int HASH_TABLE_size(HASH_TABLE *hash_table);
|
2014-04-05 02:28:41 +02:00
|
|
|
void *HASH_TABLE_lookup(HASH_TABLE *hash_table, const char *key, int len, bool set_last);
|
2009-07-08 21:57:50 +02:00
|
|
|
void *HASH_TABLE_insert(HASH_TABLE *hash_table, const char *key, int len);
|
|
|
|
void HASH_TABLE_remove(HASH_TABLE *hash_table, const char *key, int len);
|
2014-04-05 02:28:41 +02:00
|
|
|
void *HASH_TABLE_next(HASH_TABLE *hash_table, HASH_ENUM *iter, bool set_last);
|
2009-07-08 21:57:50 +02:00
|
|
|
void HASH_TABLE_get_key(HASH_TABLE *hash_table, HASH_NODE *node, char **key, int *len);
|
|
|
|
bool HASH_TABLE_get_last_key(HASH_TABLE *hash_table, char **key, int *len);
|
2014-04-05 02:28:41 +02:00
|
|
|
void HASH_TABLE_set_last_key(HASH_TABLE *hash_table, char *key, int len);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|