libFirm 1.20
libfirm/adt/set.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 1995-2011 University of Karlsruhe.  All right reserved.
00003  *
00004  * This file is part of libFirm.
00005  *
00006  * This file may be distributed and/or modified under the terms of the
00007  * GNU General Public License version 2 as published by the Free Software
00008  * Foundation and appearing in the file LICENSE.GPL included in the
00009  * packaging of this file.
00010  *
00011  * Licensees holding valid libFirm Professional Edition licenses may use
00012  * this file in accordance with the libFirm Commercial License.
00013  * Agreement provided with the Software.
00014  *
00015  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00016  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00017  * PURPOSE.
00018  */
00019 
00025 #ifndef FIRM_ADT_SET_H
00026 #define FIRM_ADT_SET_H
00027 
00028 #include <stddef.h>
00029 
00030 #include "../begin.h"
00031 
00048 typedef struct set set;
00049 
00051 typedef struct set_entry {
00052     unsigned hash;  
00053     size_t size;    
00054     int dptr[1];    
00056 } set_entry;
00057 
00073 typedef int (*set_cmp_fun) (const void *elt, const void *key, size_t size);
00074 
00085 FIRM_API set *new_set(set_cmp_fun func, size_t slots);
00086 
00092 FIRM_API void del_set(set *set);
00093 
00099 FIRM_API size_t set_count(set *set);
00100 
00112 FIRM_API void *set_find(set *set, const void *key, size_t size, unsigned hash);
00113 
00129 FIRM_API void *set_insert(set *set, const void *key, size_t size, unsigned hash);
00130 
00146 FIRM_API set_entry *set_hinsert(set *set, const void *key, size_t size, unsigned hash);
00147 
00163 FIRM_API set_entry *set_hinsert0(set *set, const void *key, size_t size, unsigned hash);
00164 
00172 FIRM_API void *set_first(set *set);
00173 
00182 FIRM_API void *set_next(set *set);
00183 
00191 FIRM_API void set_break(set *set);
00192 
00200 #define foreach_set(set, type, entry) for (entry = (type) set_first(set); entry; entry = (type) set_next(set))
00201 
00204 /* implementation specific */
00205 #define new_set(cmp, slots) ((new_set) ((cmp), (slots)))
00206 #define set_find(set, key, size, hash) \
00207   _set_search ((set), (key), (size), (hash), _set_find)
00208 #define set_insert(set, key, size, hash) \
00209   _set_search ((set), (key), (size), (hash), _set_insert)
00210 #define set_hinsert(set, key, size, hash) \
00211   ((set_entry *)_set_search ((set), (key), (size), (hash), _set_hinsert))
00212 #define set_hinsert0(set, key, size, hash) \
00213   ((set_entry *)_set_search ((set), (key), (size), (hash), _set_hinsert0))
00214 
00215 typedef enum { _set_find, _set_insert, _set_hinsert, _set_hinsert0 } _set_action;
00216 
00217 FIRM_API void *_set_search(set *, const void *, size_t, unsigned, _set_action);
00218 
00223 #include "../end.h"
00224 
00225 #endif