00001 /* 00002 00003 Copyright (c) 2005-2008, Simon Howard 00004 00005 Permission to use, copy, modify, and/or distribute this software 00006 for any purpose with or without fee is hereby granted, provided 00007 that the above copyright notice and this permission notice appear 00008 in all copies. 00009 00010 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 00011 WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 00012 WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 00013 AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR 00014 CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 00015 LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 00016 NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 00017 CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 00018 00019 */ 00020 00047 #ifndef ALGORITHM_SET_H 00048 #define ALGORITHM_SET_H 00049 00050 #ifdef __cplusplus 00051 extern "C" { 00052 #endif 00053 00059 typedef struct _Set Set; 00060 00067 typedef struct _SetIterator SetIterator; 00068 00073 typedef struct _SetEntry SetEntry; 00074 00079 typedef void *SetValue; 00080 00085 struct _SetIterator { 00086 Set *set; 00087 SetEntry *next_entry; 00088 int next_chain; 00089 }; 00090 00095 #define SET_NULL ((void *) 0) 00096 00101 typedef unsigned long (*SetHashFunc)(SetValue value); 00102 00108 typedef int (*SetEqualFunc)(SetValue value1, SetValue value2); 00109 00115 typedef void (*SetFreeFunc)(SetValue value); 00116 00127 Set *set_new(SetHashFunc hash_func, SetEqualFunc equal_func); 00128 00135 void set_free(Set *set); 00136 00146 void set_register_free_function(Set *set, SetFreeFunc free_func); 00147 00159 int set_insert(Set *set, SetValue data); 00160 00171 int set_remove(Set *set, SetValue data); 00172 00182 int set_query(Set *set, SetValue data); 00183 00191 int set_num_entries(Set *set); 00192 00202 SetValue *set_to_array(Set *set); 00203 00214 Set *set_union(Set *set1, Set *set2); 00215 00226 Set *set_intersection(Set *set1, Set *set2); 00227 00236 void set_iterate(Set *set, SetIterator *iter); 00237 00247 int set_iter_has_more(SetIterator *iterator); 00248 00257 SetValue set_iter_next(SetIterator *iterator); 00258 00259 #ifdef __cplusplus 00260 } 00261 #endif 00262 00263 #endif /* #ifndef ALGORITHM_SET_H */ 00264