Graphviz 12.0.1~dev.20240716.0800
Loading...
Searching...
No Matches
intset.c
Go to the documentation of this file.
1
3/*************************************************************************
4 * Copyright (c) 2011 AT&T Intellectual Property
5 * All rights reserved. This program and the accompanying materials
6 * are made available under the terms of the Eclipse Public License v1.0
7 * which accompanies this distribution, and is available at
8 * https://www.eclipse.org/legal/epl-v10.html
9 *
10 * Contributors: Details at https://graphviz.org
11 *************************************************************************/
12
13#include "config.h"
14#include <cgraph/alloc.h>
15#include <stddef.h>
16#include <common/intset.h>
17
18static void *mkIntItem(intitem *obj, Dtdisc_t *disc) {
19 (void)disc;
20
21 intitem* np = gv_alloc(sizeof(intitem));
22 np->id = obj->id;
23 return np;
24}
25
26static int cmpid(void *k1, void *k2) {
27 const size_t *key1 = k1;
28 const size_t *key2 = k2;
29 if (*key1 > *key2) return 1;
30 else if (*key1 < *key2) return -1;
31 else return 0;
32}
33
35 offsetof(intitem,id),
36 sizeof(int),
37 offsetof(intitem,link),
39 free,
40 cmpid,
41};
42
43Dt_t*
45{
46 return dtopen(&intSetDisc,Dtoset);
47}
48
49void addIntSet(Dt_t *is, size_t v) {
50 intitem obj;
51
52 obj.id = v;
53 dtinsert(is, &obj);
54}
55
56int inIntSet(Dt_t *is, size_t v) {
57 return (dtmatch (is, &v) != 0);
58}
59
Memory allocation wrappers that exit on failure.
static void * gv_alloc(size_t size)
Definition alloc.h:47
void *(* Dtmake_f)(void *, Dtdisc_t *)
Definition cdt.h:50
#define dtmatch(d, o)
Definition cdt.h:192
#define dtinsert(d, o)
Definition cdt.h:193
CDT_API Dtmethod_t * Dtoset
ordered set (self-adjusting tree)
Definition dttree.c:304
CDT_API Dt_t * dtopen(Dtdisc_t *, Dtmethod_t *)
Definition dtopen.c:9
void free(void *)
static void * mkIntItem(intitem *obj, Dtdisc_t *disc)
Definition intset.c:18
int inIntSet(Dt_t *is, size_t v)
Definition intset.c:56
static Dtdisc_t intSetDisc
Definition intset.c:34
void addIntSet(Dt_t *is, size_t v)
Definition intset.c:49
Dt_t * openIntSet(void)
Definition intset.c:44
static int cmpid(void *k1, void *k2)
Definition intset.c:26
Definition cdt.h:104
size_t id
Definition intset.h:19