File: node_set.h

package info (click to toggle)
graphviz 14.0.5-2
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 139,388 kB
  • sloc: ansic: 141,938; cpp: 11,957; python: 7,766; makefile: 4,043; yacc: 3,030; xml: 2,972; tcl: 2,495; sh: 1,388; objc: 1,159; java: 560; lex: 423; perl: 243; awk: 156; pascal: 139; php: 58; ruby: 49; cs: 31; sed: 1
file content (65 lines) | stat: -rw-r--r-- 1,640 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/// @file
/// @brief unordered set of `Agsubnode_t *`

#pragma once

#include <assert.h>
#include <cgraph/cgraph.h>
#include <stdbool.h>
#include <stddef.h>

/// an unordered set
typedef struct graphviz_node_set node_set_t;

/// construct a new set
///
/// Calls `exit` on failure (out-of-memory).
///
/// @return A constructed set
node_set_t *node_set_new(void);

/// add an item to the set
///
/// If the backing store is not large enough, it is expanded on demand. On
/// allocation failure, `exit` is called.
///
/// @param self Set to add to
/// @param item Element to add
void node_set_add(node_set_t *self, Agsubnode_t *item);

/// lookup an existing item in a set
///
/// @param self Set to search
/// @param key Identifier of node to look for
/// @return The found corresponding subnode or `NULL` if it was not in the set
Agsubnode_t *node_set_find(node_set_t *self, IDTYPE key);

/// remove an item from a set
///
/// If the given item was not in the set, this is a no-op.
///
/// @param self Set to remove from
/// @param item Identifier of element to remove
void node_set_remove(node_set_t *self, IDTYPE item);

/// get the number of items in a set
///
/// @param self Set to query
/// @return Number of elements in the set
size_t node_set_size(const node_set_t *self);

/// is this set empty?
///
/// @param self Set to query
/// @return True if this set contains nothing
static inline bool node_set_is_empty(const node_set_t *self) {
  assert(self != NULL);
  return node_set_size(self) == 0;
}

/// destruct a set
///
/// `*self` is `NULL` on return.
///
/// @param self Set to destroy
void node_set_free(node_set_t **self);