File: hashmap.h

package info (click to toggle)
spass 3.7-2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 5,500 kB
  • ctags: 5,981
  • sloc: ansic: 50,634; yacc: 3,038; sh: 1,072; lex: 430; perl: 407; makefile: 394
file content (62 lines) | stat: -rw-r--r-- 2,462 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**************************************************************/
/* ********************************************************** */
/* *                                                        * */
/* *           HASHMAP SUPPORTED BY GROWABLE ARRAY          * */
/* *                                                        * */
/* ********************************************************** */
/**************************************************************/

#ifndef _HASHMAP_
#define _HASHMAP_
/* *  This program is free software; you can redistribute   * */
/* *  it and/or modify it under the terms of the FreeBSD    * */
/* *  Licence.                                              * */
/* *                                                        * */
/* *  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 LICENCE file       * */
/* *  for more details.                                     * */

/**************************************************************/
/* Includes                                                   */
/**************************************************************/

#include "memory.h"
#include "misc.h"
#include "list.h"

/**************************************************************/
/* Structures                                                 */
/**************************************************************/

#define HASHMAP_NO_RETRIEVE ((POINTER)-1)

typedef unsigned HASHMAP_HASH;

typedef struct HASHMAP_HELP {
  LIST* table;            /* the actual array, it is an array of lists of pairs (hash, value) */
  int   size;             /* size of the table, has to be a power of two */
  int   num_of_els;       /* number of elements currently stored */
} HASHMAP_NODE;

typedef HASHMAP_NODE *HASHMAP;

/**************************************************************/
/* Functions                                                  */
/**************************************************************/

void         hm_Init(void);
void         hm_Free(void);

HASHMAP      hm_Create(int);
void         hm_Delete(HASHMAP);

HASHMAP_HASH hm_StringHash(const char*);

void         hm_Insert(HASHMAP,POINTER,HASHMAP_HASH);
void         hm_Remove(HASHMAP,POINTER,HASHMAP_HASH);

POINTER      hm_Retrieve(HASHMAP,HASHMAP_HASH,BOOL(*)(POINTER));

#endif