aboutsummaryrefslogtreecommitdiff
path: root/3rdparty/dict/dict.h
blob: 424bc2832abaa4d1bb06a2bdaf65c85bdee29b46 (plain)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/* ******************************************** */
/* File Name: dict.h                            */
/* Author: (C) 2008-2009 - Juan Jos� Ponteprino */
/* Description: Dictionary API Headers          */
/* License: This code is licenced as LGPL       */
/* ******************************************** */

#ifndef _DICT_H
#define _DICT_H

/* --------------------------------------------------------------------------- */

// Hash 8
#define DICT_HASH_MAX8      256
#define DICT_HASH_MASK8     0xff
#define DICT_HASH_SHIFT8    1

// Hash 16 (default)
#define DICT_HASH_MAX16     65536
#define DICT_HASH_MASK16    0xffff
#define DICT_HASH_SHIFT16   4

#ifdef USE_HASH8
// Hash 8
#define DICT_HASH_MAX       DICT_HASH_MAX8
#define DICT_HASH_MASK      DICT_HASH_MASK8
#define DICT_HASH_SHIFT     DICT_HASH_SHIFT8
#else
// Hash 16 (default)
#define DICT_HASH_MAX       DICT_HASH_MAX16
#define DICT_HASH_MASK      DICT_HASH_MASK16
#define DICT_HASH_SHIFT     DICT_HASH_SHIFT16
#endif

/* --------------------------------------------------------------------------- */

#define DICT_ENTRY_FLAG_NORMAL      0x00000000
#define DICT_ENTRY_FLAG_DONT_ALLOC  0x00000001

/* --------------------------------------------------------------------------- */

typedef struct DICT_ENTRY_T
{
    char * key;

    long len;
    void * val;

    int flags;

    struct DICT_ENTRY_T * prev;
    struct DICT_ENTRY_T * next;

    struct DICT_ENTRY_T * prev_hashed;
    struct DICT_ENTRY_T * next_hashed;

} DICT_ENTRY_T;

typedef struct DICT_T
{
    char * id;
    int hash;

    DICT_ENTRY_T * entries;
    DICT_ENTRY_T * entries_hashed[DICT_HASH_MAX];

    struct DICT_T * prev;
    struct DICT_T * next;

    struct DICT_T * prev_hashed;
    struct DICT_T * next_hashed;

} DICT_T;

/* --------------------------------------------------------------------------- */

extern void DICT_Init();
extern void DICT_Exit();

extern DICT_T * DICT_Create( char * id );
extern int DICT_Destroy( DICT_T * dict );

extern int DICT_AddEntry( DICT_T * dict, char * key, void * value, int len, int flags );
extern void * DICT_GetEntry( DICT_T * dict, char * key, int * len );
extern DICT_ENTRY_T * DICT_FindEntry( DICT_T * dict, char * key );

extern void DICT_DelEntry( DICT_T * dict, char * key );
extern void DICT_DelAllEntries( DICT_T * dict );
extern int DICT_Merge( DICT_T * target, DICT_T * source );

extern DICT_ENTRY_T * DICT_GetNextEntry( DICT_T * dict, DICT_ENTRY_T * current );
extern DICT_ENTRY_T * DICT_GetPrevEntry( DICT_T * dict, DICT_ENTRY_T * current );

extern void DICT_ShowAllEntries( DICT_T * dict, FILE * fp );

/* --------------------------------------------------------------------------- */

#endif