libFirm
Loading...
Searching...
No Matches
set.h
1/*
2 * This file is part of libFirm.
3 * Copyright (C) 2012 University of Karlsruhe.
4 */
5
11#ifndef FIRM_ADT_SET_H
12#define FIRM_ADT_SET_H
13
14#include <stddef.h>
15
16#include "../begin.h"
17
34typedef struct set set;
35
37typedef struct set_entry {
38 unsigned hash;
39 size_t size;
40 int dptr[1];
42} set_entry;
43
59typedef int (*set_cmp_fun) (void const *elt, void const *key, size_t size);
60
71FIRM_API set *new_set(set_cmp_fun func, size_t slots);
72
78FIRM_API void del_set(set *set);
79
85FIRM_API size_t set_count(set const *set);
86
97FIRM_API void *set_find(set *set, void const *key, size_t size, unsigned hash);
98
114FIRM_API void *set_insert(set *set, void const *key, size_t size, unsigned hash);
115
131FIRM_API set_entry *set_hinsert(set *set, void const *key, size_t size,
132 unsigned hash);
133
149FIRM_API set_entry *set_hinsert0(set *set, void const *key, size_t size,
150 unsigned hash);
151
159FIRM_API void *set_first(set *set);
160
171#define set_first(type, set) ((type*)set_first((set)))
172
181FIRM_API void *set_next(set *set);
182
194#define set_next(type, set) ((type*)set_next((set)))
195
203FIRM_API void set_break(set *set);
204
212#define foreach_set(set, type, entry) for (type *entry = set_first(type, set); entry; entry = set_next(type, set))
213
216/* implementation specific */
217#define new_set(cmp, slots) ((new_set) ((cmp), (slots)))
218#define set_find(type, set, key, size, hash) \
219 ((type*)_set_search((set), 1 ? (key) : (type*)0 /* type check */, (size), (hash), _set_find))
220#define set_insert(type, set, key, size, hash) \
221 ((type*)_set_search((set), 1 ? (key) : (type*)0 /* type check */, (size), (hash), _set_insert))
222#define set_hinsert(set, key, size, hash) \
223 ((set_entry *)_set_search ((set), (key), (size), (hash), _set_hinsert))
224#define set_hinsert0(set, key, size, hash) \
225 ((set_entry *)_set_search ((set), (key), (size), (hash), _set_hinsert0))
226
227typedef enum { _set_find, _set_insert, _set_hinsert, _set_hinsert0 } _set_action;
228
229FIRM_API void *_set_search(set *set, void const *key, size_t size,
230 unsigned hash, _set_action action);
231
236#include "../end.h"
237
238#endif
The entry of a set, representing an element in the set and its meta-information.
Definition set.h:37
size_t size
the size of the element
Definition set.h:39
unsigned hash
the hash value of the element
Definition set.h:38
int dptr[1]
the element itself, data copied in must not need more alignment than this
Definition set.h:40
set * new_set(set_cmp_fun func, size_t slots)
Creates a new set.
void del_set(set *set)
Deletes a set and all elements of it.
#define set_first(type, set)
Returns the first element of a set.
Definition set.h:171
void * set_insert(set *set, void const *key, size_t size, unsigned hash)
Inserts an element into a set.
size_t set_count(set const *set)
Returns the number of elements in a set.
set_entry * set_hinsert0(set *set, void const *key, size_t size, unsigned hash)
Inserts an element into a set, zero-terminate it and returns its set_entry.
set_entry * set_hinsert(set *set, void const *key, size_t size, unsigned hash)
Inserts an element into a set and returns its set_entry.
int(* set_cmp_fun)(void const *elt, void const *key, size_t size)
The type of a set compare function.
Definition set.h:59
void set_break(set *set)
Breaks the iteration of a set.
struct set set
The abstract type of a set.
Definition set.h:34
#define set_next(type, set)
Returns the next element of a set.
Definition set.h:194
void * set_find(set *set, void const *key, size_t size, unsigned hash)
Searches an element in a set.