rlib
Convenience library for useful things
Loading...
Searching...
No Matches
rhashset.h
Go to the documentation of this file.
1/* RLIB - Convenience library for useful things
2 * Copyright (C) 2017 Haakon Sporsheim <haakon.sporsheim@gmail.com>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 3.0 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library.
16 * See the COPYING file at the root of the source repository.
17 */
18#ifndef __R_HASH_SET_H__
19#define __R_HASH_SET_H__
20
21#if !defined(__RLIB_H_INCLUDE_GUARD__) && !defined(RLIB_COMPILATION)
22#error "#include <rlib.h> only please."
23#endif
24
44#include <rlib/rtypes.h>
45#include <rlib/rref.h>
46
48
50
52typedef struct RHashSet RHashSet;
53
55#define r_hash_set_new(hash, equal) r_hash_set_new_full (hash, equal, NULL)
65 RDestroyNotify notify) R_ATTR_MALLOC;
67#define r_hash_set_ref r_ref_ref
69#define r_hash_set_unref r_ref_unref
70
78
87
101 rpointer * out);
102
112 rpointer * out);
113
116
117R_END_DECLS
118
121#endif /* __R_HASH_SET_H__ */
122
123
struct RHashSet RHashSet
Opaque refcounted hash set.
Definition rhashset.h:52
rboolean r_hash_set_steal(RHashSet *ht, rconstpointer item, rpointer *out)
Remove item without running the destroy notifier; hand the stored pointer back via out.
rsize r_hash_set_current_alloc_size(RHashSet *ht)
Allocated bucket count.
rboolean r_hash_set_contains(RHashSet *ht, rconstpointer item)
TRUE iff item is present.
rboolean r_hash_set_foreach(RHashSet *ht, RFunc func, rpointer user)
Iterate every item in the set.
rboolean r_hash_set_remove(RHashSet *ht, rconstpointer item)
Remove item; destroy notifier runs.
rsize r_hash_set_size(RHashSet *ht)
Number of items currently in the set.
rboolean r_hash_set_contains_full(RHashSet *ht, rconstpointer item, rpointer *out)
Look up item and return the set-owned pointer.
void r_hash_set_remove_all(RHashSet *ht)
Remove every item; destroy notifier runs.
rboolean r_hash_set_insert(RHashSet *ht, rpointer item)
Add item to the set.
RHashSet * r_hash_set_new_full(RHashFunc hash, REqualFunc equal, RDestroyNotify notify)
Construct a hash set with custom hash / equality and an optional destroy notifier.
rsize r_hash_set_max_probe(RHashSet *ht)
Worst-case unsuccessful-probe length; diagnostic for home distribution (small means items are well sp...
#define R_API
Public-API decoration: resolves to R_API_EXPORT while building rlib and R_API_IMPORT for consumers.
Definition rmacros.h:115
#define R_BEGIN_DECLS
Open an extern "C" block under C++ (no-op in C).
Definition rmacros.h:196
rboolean(* REqualFunc)(rconstpointer a, rconstpointer b)
Equality predicate.
Definition rtypes.h:407
int rboolean
Boolean type (typedef'd to int).
Definition rtypes.h:59
void(* RFunc)(rpointer data, rpointer user)
Generic iteration callback over (data, user) pairs.
Definition rtypes.h:403
void(* RDestroyNotify)(rpointer ptr)
Destructor callback: free / release the value at ptr.
Definition rtypes.h:401
void * rpointer
Generic pointer (alias for void *).
Definition rtypes.h:327
const void * rconstpointer
Generic const pointer (alias for const void *).
Definition rtypes.h:329
unsigned long rsize
Unsigned pointer-sized size type (like size_t).
Definition rtypes.h:290
rsize(* RHashFunc)(rconstpointer key)
Hash function over an opaque key.
Definition rtypes.h:409
Pre-built hash / equality function pairs for the common key types (pointer-identity,...
Refcount base struct shared by every refcounted type in rlib.
Foundational type aliases used by every rlib header.