Monado OpenXR Runtime
u_hashset.h
Go to the documentation of this file.
1// Copyright 2019-2020, 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
15extern "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 */
28struct 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
52typedef void (*u_hashset_callback)(struct u_hashset_item *item, void *priv);
53
54int
55u_hashset_create(struct u_hashset **out_hashset);
56
57int
58u_hashset_destroy(struct u_hashset **hs);
59
60int
61u_hashset_find_str(struct u_hashset *hs, const char *str, size_t length, struct u_hashset_item **out_item);
62
63int
64u_hashset_find_c_str(struct u_hashset *hs, const char *c_str, struct u_hashset_item **out_item);
65
66int
67u_hashset_create_and_insert_str(struct u_hashset *hs, const char *str, size_t length, struct u_hashset_item **out_item);
68
69int
70u_hashset_create_and_insert_str_c(struct u_hashset *hs, const char *c_str, struct u_hashset_item **out_item);
71
72int
73u_hashset_insert_item(struct u_hashset *hs, struct u_hashset_item *item);
74
75int
76u_hashset_erase_item(struct u_hashset *hs, struct u_hashset_item *item);
77
78int
79u_hashset_erase_str(struct u_hashset *hs, const char *str, size_t length);
80
81int
82u_hashset_erase_c_str(struct u_hashset *hs, const char *c_str);
83
84/*!
85 * First clear the hashset and then call the given callback with each item that
86 * was in the hashset.
87 *
88 * @ingroup aux_util
89 */
90void
91u_hashset_clear_and_call_for_each(struct u_hashset *hs, u_hashset_callback cb, void *priv);
92
93
94#ifdef __cplusplus
95}
96#endif
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:151
A embeddable hashset item, note that the string directly follows the u_hashset_item.
Definition: u_hashset.h:37
Kind of bespoke hashset implementation, where the user is responsible for allocating and freeing the ...
Definition: u_hashset.cpp:26
Header holding common defines.