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 
41 #ifdef __cplusplus
42  inline const char *
43  c_str()
44  {
45  return (const char *)&this[1];
46  }
47 #else
48  const char c_str[];
49 #endif
50 };
51 
52 typedef void (*u_hashset_callback)(struct u_hashset_item *item, void *priv);
53 
54 int
55 u_hashset_create(struct u_hashset **out_hashset);
56 
57 int
58 u_hashset_destroy(struct u_hashset **hs);
59 
60 int
61 u_hashset_find_str(struct u_hashset *hs,
62  const char *str,
63  size_t length,
64  struct u_hashset_item **out_item);
65 
66 int
68  const char *c_str,
69  struct u_hashset_item **out_item);
70 
71 int
72 u_hashset_insert_item(struct u_hashset *hs, struct u_hashset_item *item);
73 
74 int
75 u_hashset_erase_item(struct u_hashset *hs, struct u_hashset_item *item);
76 
77 int
78 u_hashset_erase_str(struct u_hashset *hs, const char *str, size_t length);
79 
80 int
81 u_hashset_erase_c_str(struct u_hashset *hs, const char *c_str);
82 
83 /*!
84  * First clear the hashset and then call the given callback with each item that
85  * was in the hashset.
86  *
87  * @ingroup aux_util
88  */
89 void
92  void *priv);
93 
94 
95 #ifdef __cplusplus
96 }
97 #endif
int u_hashset_erase_str(struct u_hashset *hs, const char *str, size_t length)
Definition: u_hashset.cpp:94
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
int u_hashset_create(struct u_hashset **out_hashset)
Definition: u_hashset.cpp:37
int u_hashset_erase_item(struct u_hashset *hs, struct u_hashset_item *item)
Definition: u_hashset.cpp:86
int u_hashset_insert_item(struct u_hashset *hs, struct u_hashset_item *item)
Definition: u_hashset.cpp:78
int u_hashset_find_c_str(struct u_hashset *hs, const char *c_str, struct u_hashset_item **out_item)
Definition: u_hashset.cpp:69
void(* u_hashset_callback)(struct u_hashset_item *item, void *priv)
Definition: u_hashset.h:52
int u_hashset_find_str(struct u_hashset *hs, const char *str, size_t length, struct u_hashset_item **out_item)
Definition: u_hashset.cpp:53
size_t length
Definition: u_hashset.h:39
int u_hashset_destroy(struct u_hashset **hs)
Definition: u_hashset.cpp:45
Header holding common defines.
size_t hash
Definition: u_hashset.h:38
int u_hashset_erase_c_str(struct u_hashset *hs, const char *c_str)
Definition: u_hashset.cpp:102
const char c_str[]
Definition: u_hashset.h:48