document hash collision resolutions
[mesa.git] / src / gallium / auxiliary / cso_cache / cso_hash.h
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 /**
29 This file provides a hash implementation that is capable of dealing
30 with collisions. It stores colliding entries in linked list. All
31 functions operating on the hash return an iterator. The iterator
32 itself points to the collision list. If there wasn't any collision
33 the list will have just one entry, otherwise client code should
34 iterate over the entries to find the exact entry among ones that
35 had the same key (e.g. memcmp could be used on the data to check
36 that)
37 */
38 /*
39 * Authors:
40 * Zack Rusin <zack@tungstengraphics.com>
41 */
42
43 #ifndef CSO_HASH_H
44 #define CSO_HASH_H
45
46
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50
51 struct cso_hash;
52 struct cso_node;
53
54 struct cso_hash_iter {
55 struct cso_hash *hash;
56 struct cso_node *node;
57 };
58
59 struct cso_hash *cso_hash_create(void);
60 void cso_hash_delete(struct cso_hash *hash);
61
62 int cso_hash_size(struct cso_hash *hash);
63
64 struct cso_hash_iter cso_hash_insert(struct cso_hash *hash, unsigned key,
65 void *data);
66 void *cso_hash_take(struct cso_hash *hash, unsigned key);
67
68 struct cso_hash_iter cso_hash_first_node(struct cso_hash *hash);
69 struct cso_hash_iter cso_hash_find(struct cso_hash *hash, unsigned key);
70
71
72 int cso_hash_iter_is_null(struct cso_hash_iter iter);
73 unsigned cso_hash_iter_key(struct cso_hash_iter iter);
74 void *cso_hash_iter_data(struct cso_hash_iter iter);
75
76 struct cso_hash_iter cso_hash_iter_next(struct cso_hash_iter iter);
77 struct cso_hash_iter cso_hash_iter_prev(struct cso_hash_iter iter);
78
79
80 /* KW: a convenience routine:
81 */
82 void *cso_hash_find_data_from_template( struct cso_hash *hash,
83 unsigned hash_key,
84 void *templ,
85 int size );
86
87
88 #ifdef __cplusplus
89 }
90 #endif
91
92 #endif