| 1 |
/// @file |
| 2 |
/// @brief unordered set of `Agsubnode_t *` |
| 3 |
|
| 4 |
#pragma once |
| 5 |
|
| 6 |
#include <assert.h> |
| 7 |
#include <cgraph/cgraph.h> |
| 8 |
#include <stdbool.h> |
| 9 |
#include <stddef.h> |
| 10 |
|
| 11 |
/// an unordered set |
| 12 |
typedef struct graphviz_node_set node_set_t; |
| 13 |
|
| 14 |
/// construct a new set |
| 15 |
/// |
| 16 |
/// Calls `exit` on failure (out-of-memory). |
| 17 |
/// |
| 18 |
/// @return A constructed set |
| 19 |
node_set_t *node_set_new(void); |
| 20 |
|
| 21 |
/// add an item to the set |
| 22 |
/// |
| 23 |
/// If the backing store is not large enough, it is expanded on demand. On |
| 24 |
/// allocation failure, `exit` is called. |
| 25 |
/// |
| 26 |
/// @param self Set to add to |
| 27 |
/// @param item Element to add |
| 28 |
void node_set_add(node_set_t *self, Agsubnode_t *item); |
| 29 |
|
| 30 |
/// lookup an existing item in a set |
| 31 |
/// |
| 32 |
/// @param self Set to search |
| 33 |
/// @param key Identifier of node to look for |
| 34 |
/// @return The found corresponding subnode or `NULL` if it was not in the set |
| 35 |
Agsubnode_t *node_set_find(node_set_t *self, IDTYPE key); |
| 36 |
|
| 37 |
/// remove an item from a set |
| 38 |
/// |
| 39 |
/// If the given item was not in the set, this is a no-op. |
| 40 |
/// |
| 41 |
/// @param self Set to remove from |
| 42 |
/// @param item Identifier of element to remove |
| 43 |
void node_set_remove(node_set_t *self, IDTYPE item); |
| 44 |
|
| 45 |
/// get the number of items in a set |
| 46 |
/// |
| 47 |
/// @param self Set to query |
| 48 |
/// @return Number of elements in the set |
| 49 |
size_t node_set_size(const node_set_t *self); |
| 50 |
|
| 51 |
/// is this set empty? |
| 52 |
/// |
| 53 |
/// @param self Set to query |
| 54 |
/// @return True if this set contains nothing |
| 55 |
static inline bool node_set_is_empty(const node_set_t *self) { |
| 56 |
assert(self != NULL); |
| 57 |
return node_set_size(self) == 0; |
| 58 |
} |
| 59 |
|
| 60 |
/// destruct a set |
| 61 |
/// |
| 62 |
/// `*self` is `NULL` on return. |
| 63 |
/// |
| 64 |
/// @param self Set to destroy |
| 65 |
void node_set_free(node_set_t **self); |