[go: up one dir, main page]

Menu

[r6]: / trunk / src / hash.h  Maximize  Restore  History

Download this file

122 lines (105 with data), 3.8 kB

  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
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
xmd - molecular dynamics for metals and ceramics
By Jonathan Rifkin <jon.rifkin@uconn.edu>
Copyright 1995-2004 Jonathan Rifkin
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 the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* hash.h
*
* hash header file
* By Jon Rifkin <jon.rifkin@uconn.edu>
* Copyright 1999-2004 Jonathan Rifkin
*
*
* 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 the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef _HASH_H
#define _HASH_H
#ifndef BYTE
#define BYTE unsigned char
#endif
/* Option flags */
#define HT_HISTORY 0x1
/*
------------------------------------------------------------------------
Type Definitions
------------------------------------------------------------------------
*/
/* Individual element */
typedef struct h_elem_s {
/* Key */
BYTE *key;
int nkey;
/* Data */
BYTE *data;
int ndata;
/* Links to double linked list for each hash slot */
struct helem_s *next, *prev;
/* Links for global double linked list for element history */
/* No space needed for these links if no history */
struct helem_s *newer, *older;
} helem_t;
/* Hash */
typedef struct {
/* Number of elements in all lists */
int nelem;
/* Array of lists */
helem_t **array;
/* Size of array of lists */
int narray;
/* Number of allocated lists: nlist <= narray */
int nlist;
/* Current element,list - used to find next */
helem_t *curelem;
int curlist;
/* This flag true/false to add new elements to list tail/head */
int AddTail;
/* Use history list */
int Options;
/* Size of element */
int ElementSize;
/* Oldest, newest nodes */
helem_t *oldest, *newest;
} htable_t;
/*
------------------------------------------------------------------------
Function Prototypes
------------------------------------------------------------------------
*/
htable_t *ht_init (int narray, int options);
int ht_findkey (htable_t *h, BYTE *k, int nk, BYTE **d, int *nd);
int ht_storenode (htable_t *h, BYTE *k, int nk, BYTE *d, int nd);
void ht_initwalk (htable_t *h);
helem_t *ht_getnext (htable_t *h);
helem_t *ht_getnewer (htable_t *h, helem_t *e);
int ht_getcount (htable_t *h);
void ht_free (htable_t *h);
helem_t *ht_findelem (htable_t *h, BYTE *k, int nk);
int ht_gethash (htable_t *h, BYTE *k, int nk);
void ht_freeelem (htable_t *h, helem_t *e);
void ht_makenewest(htable_t *h, helem_t *);
helem_t *ht_getoldest (htable_t *h);
void ht_debuginfo (htable_t *h);
#endif