2007-12-30 17:41:49 +01:00
|
|
|
/***************************************************************************
|
|
|
|
|
2009-08-17 12:41:51 +02:00
|
|
|
gb_hash.h
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-03-21 01:04:10 +01:00
|
|
|
(c) 2000-2011 Benoît Minisini <gambas@users.sourceforge.net>
|
2007-12-30 17:41:49 +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
|
2009-08-17 12:41:51 +02:00
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
2007-12-30 17:41:49 +01:00
|
|
|
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 the Free Software
|
2011-06-03 02:51:09 +02:00
|
|
|
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
|
|
|
|
enum {
|
|
|
|
HF_NORMAL = 0,
|
|
|
|
HF_IGNORE_CASE = 1
|
|
|
|
}
|
|
|
|
HASH_FLAG;
|
|
|
|
|
|
|
|
typedef
|
|
|
|
struct _HASH_NODE
|
|
|
|
{
|
|
|
|
struct _HASH_NODE *next;
|
|
|
|
#ifdef KEEP_ORDER
|
|
|
|
struct _HASH_NODE *snext;
|
|
|
|
struct _HASH_NODE *sprev;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
HASH_NODE;
|
|
|
|
|
|
|
|
typedef
|
|
|
|
struct {
|
|
|
|
ushort len;
|
|
|
|
char key[0];
|
|
|
|
}
|
|
|
|
PACKED
|
|
|
|
HASH_KEY;
|
|
|
|
|
|
|
|
typedef
|
|
|
|
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;
|
|
|
|
|
2010-10-06 14:03:27 +02:00
|
|
|
// NOTE: If HASH_ENUM changes, GB_COLLECTION_ITER must be updated accordingly in gambas.h
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
typedef
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
HASH_NODE *node;
|
|
|
|
HASH_NODE *next;
|
|
|
|
}
|
|
|
|
HASH_ENUM;
|
|
|
|
|
|
|
|
typedef
|
|
|
|
uint (*HASH_FUNC)(const char *, int);
|
|
|
|
|
|
|
|
typedef
|
|
|
|
bool (*HASH_COMP)(const char *, const char *, int);
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
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);
|
|
|
|
void *HASH_TABLE_lookup(HASH_TABLE *hash_table, const char *key, int len);
|
|
|
|
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);
|
|
|
|
void *HASH_TABLE_next(HASH_TABLE *hash_table, HASH_ENUM *iter);
|
|
|
|
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);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|