Graphviz  2.29.20120524.0446
lib/common/intset.c
Go to the documentation of this file.
00001 /* $Id$Revision: */
00002 /* vim:set shiftwidth=4 ts=8: */
00003 
00004 /*************************************************************************
00005  * Copyright (c) 2011 AT&T Intellectual Property 
00006  * All rights reserved. This program and the accompanying materials
00007  * are made available under the terms of the Eclipse Public License v1.0
00008  * which accompanies this distribution, and is available at
00009  * http://www.eclipse.org/legal/epl-v10.html
00010  *
00011  * Contributors: See CVS logs. Details at http://www.graphviz.org/
00012  *************************************************************************/
00013 
00014 #ifdef HAVE_CONFIG_H
00015 #include "config.h"
00016 #endif
00017 
00018 #include <stddef.h>
00019 #include <intset.h>
00020 #include <memory.h>
00021 
00022 static Void_t*
00023 mkIntItem(Dt_t* d,intitem* obj,Dtdisc_t* disc)
00024 { 
00025     intitem* np = NEW(intitem);
00026     np->id = obj->id;
00027     return (Void_t*)np;
00028 }
00029 
00030 static void
00031 freeIntItem(Dt_t* d,intitem* obj,Dtdisc_t* disc)
00032 {
00033     free (obj);
00034 }
00035 
00036 static int
00037 cmpid(Dt_t* d, int* key1, int* key2, Dtdisc_t* disc)
00038 {
00039   if (*key1 > *key2) return 1;
00040   else if (*key1 < *key2) return -1;
00041   else return 0;
00042 }   
00043 
00044 static Dtdisc_t intSetDisc = {
00045     offsetof(intitem,id),
00046     sizeof(int),
00047     offsetof(intitem,link),
00048     (Dtmake_f)mkIntItem,
00049     (Dtfree_f)freeIntItem,
00050     (Dtcompar_f)cmpid,
00051     0,
00052     0,
00053     0
00054 };
00055 
00056 Dt_t* 
00057 openIntSet (void)
00058 {
00059     return dtopen(&intSetDisc,Dtoset);
00060 }
00061 
00062 void 
00063 addIntSet (Dt_t* is, int v)
00064 {
00065     intitem obj;
00066 
00067     obj.id = v;
00068     dtinsert(is, &obj);
00069 }
00070 
00071 int 
00072 inIntSet (Dt_t* is, int v)
00073 {
00074     return (dtmatch (is, &v) != 0);
00075 }
00076