Monado OpenXR Runtime
u_hashset.h
Go to the documentation of this file.
1 // Copyright 2019, Collabora, Ltd.
2 // SPDX-License-Identifier: BSL-1.0
3 /*!
4  * @file
5  * @brief Hashset struct header.
6  * @author Jakob Bornecrantz <jakob@collabora.com>
7  * @ingroup aux_util
8  */
9 
10 #pragma once
11 
12 #include "xrt/xrt_compiler.h"
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 
19 /*!
20  * @struct u_hashset
21  * @ingroup aux_util
22  *
23  * Kind of bespoke hashset implementation, where the user is responsible for
24  * allocating and freeing the items themselves.
25  *
26  * This allows embedding the @ref u_hashset_item at the end of structs.
27  */
28 struct u_hashset;
29 
30 /*!
31  * A embeddable hashset item, note that the string directly follows the
32  * @ref u_hashset_item.
33  *
34  * @ingroup aux_util
35  */
37 {
38  size_t hash;
39  size_t length;
40  const char c_str[];
41 };
42 
43 typedef void (*u_hashset_callback)(struct u_hashset_item *item, void *priv);
44 
45 int
46 u_hashset_create(struct u_hashset **out_hashset);
47 
48 int
49 u_hashset_destroy(struct u_hashset **hs);
50 
51 int
52 u_hashset_find_str(struct u_hashset *hs,
53  const char *str,
54  size_t length,
55  struct u_hashset_item **out_item);
56 
57 int
58 u_hashset_find_c_str(struct u_hashset *hs,
59  const char *c_str,
60  struct u_hashset_item **out_item);
61 
62 int
63 u_hashset_insert_item(struct u_hashset *hs, struct u_hashset_item *item);
64 
65 int
66 u_hashset_erase_item(struct u_hashset *hs, struct u_hashset_item *item);
67 
68 int
69 u_hashset_erase_str(struct u_hashset *hs, const char *str, size_t length);
70 
71 int
72 u_hashset_erase_c_str(struct u_hashset *hs, const char *c_str);
73 
74 /*!
75  * First clear the hashset and then call the given callback with each item that
76  * was in the hashset.
77  *
78  * @ingroup aux_util
79  */
80 void
82  u_hashset_callback cb,
83  void *priv);
84 
85 
86 #ifdef __cplusplus
87 }
88 #endif
A embeddable hashset item, note that the string directly follows the u_hashset_item.
Definition: u_hashset.h:36
void u_hashset_clear_and_call_for_each(struct u_hashset *hs, u_hashset_callback cb, void *priv)
First clear the hashset and then call the given callback with each item that was in the hashset...
Definition: u_hashset.cpp:109
Kind of bespoke hashset implementation, where the user is responsible for allocating and freeing the ...
Definition: u_hashset.cpp:24
Header holding common defines.