| 1 | /* $Id$Revision: */ | 
|---|
| 2 | /* vim:set shiftwidth=4 ts=8: */ | 
|---|
| 3 |  | 
|---|
| 4 | /************************************************************************* | 
|---|
| 5 | * Copyright (c) 2011 AT&T Intellectual Property | 
|---|
| 6 | * All rights reserved. This program and the accompanying materials | 
|---|
| 7 | * are made available under the terms of the Eclipse Public License v1.0 | 
|---|
| 8 | * which accompanies this distribution, and is available at | 
|---|
| 9 | * http://www.eclipse.org/legal/epl-v10.html | 
|---|
| 10 | * | 
|---|
| 11 | * Contributors: See CVS logs. Details at http://www.graphviz.org/ | 
|---|
| 12 | *************************************************************************/ | 
|---|
| 13 |  | 
|---|
| 14 | #include "config.h" | 
|---|
| 15 |  | 
|---|
| 16 | #include <stddef.h> | 
|---|
| 17 | #include <intset.h> | 
|---|
| 18 | #include <memory.h> | 
|---|
| 19 |  | 
|---|
| 20 | static void* | 
|---|
| 21 | mkIntItem(Dt_t* d,intitem* obj,Dtdisc_t* disc) | 
|---|
| 22 | { | 
|---|
| 23 | intitem* np = NEW(intitem); | 
|---|
| 24 | np->id = obj->id; | 
|---|
| 25 | return (void*)np; | 
|---|
| 26 | } | 
|---|
| 27 |  | 
|---|
| 28 | static void | 
|---|
| 29 | freeIntItem(Dt_t* d,intitem* obj,Dtdisc_t* disc) | 
|---|
| 30 | { | 
|---|
| 31 | free (obj); | 
|---|
| 32 | } | 
|---|
| 33 |  | 
|---|
| 34 | static int | 
|---|
| 35 | cmpid(Dt_t* d, int* key1, int* key2, Dtdisc_t* disc) | 
|---|
| 36 | { | 
|---|
| 37 | if (*key1 > *key2) return 1; | 
|---|
| 38 | else if (*key1 < *key2) return -1; | 
|---|
| 39 | else return 0; | 
|---|
| 40 | } | 
|---|
| 41 |  | 
|---|
| 42 | static Dtdisc_t intSetDisc = { | 
|---|
| 43 | offsetof(intitem,id), | 
|---|
| 44 | sizeof(int), | 
|---|
| 45 | offsetof(intitem,link), | 
|---|
| 46 | (Dtmake_f)mkIntItem, | 
|---|
| 47 | (Dtfree_f)freeIntItem, | 
|---|
| 48 | (Dtcompar_f)cmpid, | 
|---|
| 49 | 0, | 
|---|
| 50 | 0, | 
|---|
| 51 | 0 | 
|---|
| 52 | }; | 
|---|
| 53 |  | 
|---|
| 54 | Dt_t* | 
|---|
| 55 | openIntSet (void) | 
|---|
| 56 | { | 
|---|
| 57 | return dtopen(&intSetDisc,Dtoset); | 
|---|
| 58 | } | 
|---|
| 59 |  | 
|---|
| 60 | void | 
|---|
| 61 | addIntSet (Dt_t* is, int v) | 
|---|
| 62 | { | 
|---|
| 63 | intitem obj; | 
|---|
| 64 |  | 
|---|
| 65 | obj.id = v; | 
|---|
| 66 | dtinsert(is, &obj); | 
|---|
| 67 | } | 
|---|
| 68 |  | 
|---|
| 69 | int | 
|---|
| 70 | inIntSet (Dt_t* is, int v) | 
|---|
| 71 | { | 
|---|
| 72 | return (dtmatch (is, &v) != 0); | 
|---|
| 73 | } | 
|---|
| 74 |  | 
|---|
| 75 |  | 
|---|