2 * Copyright © 2009-2012 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 * Eric Anholt <eric@anholt.net>
45 struct set_entry
*table
;
46 uint32_t (*key_hash_function
)(const void *key
);
47 bool (*key_equals_function
)(const void *a
, const void *b
);
51 uint64_t rehash_magic
;
55 uint32_t deleted_entries
;
59 _mesa_set_create(void *mem_ctx
,
60 uint32_t (*key_hash_function
)(const void *key
),
61 bool (*key_equals_function
)(const void *a
,
64 _mesa_set_clone(struct set
*set
, void *dst_mem_ctx
);
67 _mesa_set_destroy(struct set
*set
,
68 void (*delete_function
)(struct set_entry
*entry
));
70 _mesa_set_resize(struct set
*set
, uint32_t entries
);
72 _mesa_set_clear(struct set
*set
,
73 void (*delete_function
)(struct set_entry
*entry
));
76 _mesa_set_add(struct set
*set
, const void *key
);
78 _mesa_set_add_pre_hashed(struct set
*set
, uint32_t hash
, const void *key
);
81 _mesa_set_search_or_add(struct set
*set
, const void *key
);
83 _mesa_set_search_or_add_pre_hashed(struct set
*set
, uint32_t hash
,
87 _mesa_set_search(const struct set
*set
, const void *key
);
89 _mesa_set_search_pre_hashed(const struct set
*set
, uint32_t hash
,
93 _mesa_set_search_and_add(struct set
*set
, const void *key
, bool *replaced
);
95 _mesa_set_search_and_add_pre_hashed(struct set
*set
, uint32_t hash
,
96 const void *key
, bool *replaced
);
99 _mesa_set_remove(struct set
*set
, struct set_entry
*entry
);
101 _mesa_set_remove_key(struct set
*set
, const void *key
);
104 _mesa_set_next_entry(const struct set
*set
, struct set_entry
*entry
);
107 _mesa_set_random_entry(struct set
*set
,
108 int (*predicate
)(struct set_entry
*entry
));
111 _mesa_pointer_set_create(void *mem_ctx
);
114 * This foreach function is safe against deletion, but not against
115 * insertion (which may rehash the set, making entry a dangling
118 #define set_foreach(set, entry) \
119 for (struct set_entry *entry = _mesa_set_next_entry(set, NULL); \
121 entry = _mesa_set_next_entry(set, entry))