]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /* |
2 | * Copyright 1993, 1995 Christopher Seiwald. | |
3 | * | |
4 | * This file is part of Jam - see jam.c for Copyright information. | |
5 | */ | |
6 | ||
7 | /* | |
8 | * hash.h - simple in-memory hashing routines | |
9 | */ | |
10 | ||
11 | #ifndef BOOST_JAM_HASH_H | |
12 | #define BOOST_JAM_HASH_H | |
13 | ||
14 | #include "object.h" | |
15 | ||
16 | /* | |
17 | * An opaque struct representing an item in the hash table. The first element of | |
18 | * every struct stored in the table must be an OBJECT * which is treated as the | |
19 | * key. | |
20 | */ | |
21 | typedef struct hashdata HASHDATA; | |
22 | ||
23 | /* | |
24 | * hashinit() - initialize a hash table, returning a handle. | |
25 | * | |
26 | * Parameters: | |
27 | * datalen - item size | |
28 | * name - used for debugging | |
29 | */ | |
30 | struct hash * hashinit( int datalen, char const * name ); | |
31 | ||
32 | /* | |
33 | * hash_free() - free a hash table, given its handle | |
34 | */ | |
35 | void hash_free( struct hash * ); | |
36 | void hashdone( struct hash * ); | |
37 | ||
38 | /* | |
39 | * hashenumerate() - call f(i, data) on each item, i in the hash table. The | |
40 | * enumeration order is unspecified. | |
41 | */ | |
42 | void hashenumerate( struct hash *, void (* f)( void *, void * ), void * data ); | |
43 | ||
44 | /* | |
45 | * hash_insert() - insert a new item in a hash table, or return an existing one. | |
46 | * | |
47 | * Preconditions: | |
48 | * - hp must be a hash table created by hashinit() | |
49 | * - key must be an object created by object_new() | |
50 | * | |
51 | * Postconditions: | |
52 | * - if the key does not already exist in the hash table, *found == 0 and the | |
53 | * result will be a pointer to an uninitialized item. The key of the new | |
54 | * item must be set to a value equal to key before any further operations on | |
55 | * the hash table except hashdone(). | |
56 | * - if the key is present then *found == 1 and the result is a pointer to the | |
57 | * existing record. | |
58 | */ | |
59 | HASHDATA * hash_insert( struct hash *, OBJECT * key, int * found ); | |
60 | ||
61 | /* | |
62 | * hash_find() - find a record in the table or NULL if none exists | |
63 | */ | |
64 | HASHDATA * hash_find( struct hash *, OBJECT * key ); | |
65 | ||
66 | struct hashstats { | |
67 | int count; | |
68 | int num_items; | |
69 | int tab_size; | |
70 | int item_size; | |
71 | int sets; | |
72 | int num_hashes; | |
73 | }; | |
74 | ||
75 | void hashstats_init( struct hashstats * stats ); | |
76 | void hashstats_add( struct hashstats * stats, struct hash * ); | |
77 | void hashstats_print( struct hashstats * stats, char const * name ); | |
78 | ||
79 | #endif |