X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fgl_oset.h;h=0ecc6112cb69919d5cf0e4f4f11999d94c79eb15;hb=2c33678711c8d7ac62ddd06b4df234a0ccbb74a7;hp=2a67994a86f3a2a0a7e659c253fb1b92cb5675f2;hpb=5c90f29795d4e8d9a66268d5dc61d02b82cf7db8;p=gnulib.git diff --git a/lib/gl_oset.h b/lib/gl_oset.h index 2a67994a8..0ecc6112c 100644 --- a/lib/gl_oset.h +++ b/lib/gl_oset.h @@ -1,11 +1,11 @@ /* Abstract ordered set data type. - Copyright (C) 2006 Free Software Foundation, Inc. + Copyright (C) 2006-2007 Free Software Foundation, Inc. Written by Bruno Haible , 2006. - This program is free software; you can redistribute it and/or modify + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -13,8 +13,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + along with this program. If not, see . */ #ifndef _GL_OSET_H #define _GL_OSET_H @@ -70,6 +69,10 @@ extern "C" { NULL denotes pointer comparison. */ typedef int (*gl_setelement_compar_fn) (const void *elt1, const void *elt2); +/* Type of function used to dispose an element once it's removed from a set. + NULL denotes a no-op. */ +typedef void (*gl_setelement_dispose_fn) (const void *elt); + /* Type of function used to compare an element with a threshold. Return true if the element is greater or equal than the threshold. */ typedef bool (*gl_setelement_threshold_fn) (const void *elt, const void *threshold); @@ -84,9 +87,11 @@ typedef const struct gl_oset_implementation * gl_oset_implementation_t; /* Create an empty set. IMPLEMENTATION is one of GL_ARRAY_OSET, GL_AVLTREE_OSET, GL_RBTREE_OSET. - COMPAR_FN is an element comparison function or NULL. */ + COMPAR_FN is an element comparison function or NULL. + DISPOSE_FN is an element disposal function or NULL. */ extern gl_oset_t gl_oset_create_empty (gl_oset_implementation_t implementation, - gl_setelement_compar_fn compar_fn); + gl_setelement_compar_fn compar_fn, + gl_setelement_dispose_fn dispose_fn); /* Return the current number of elements in an ordered set. */ extern size_t gl_oset_size (gl_oset_t set); @@ -153,9 +158,10 @@ extern void gl_oset_iterator_free (gl_oset_iterator_t *iterator); struct gl_oset_implementation { - // gl_oset_t functions. + /* gl_oset_t functions. */ gl_oset_t (*create_empty) (gl_oset_implementation_t implementation, - gl_setelement_compar_fn compar_fn); + gl_setelement_compar_fn compar_fn, + gl_setelement_dispose_fn dispose_fn); size_t (*size) (gl_oset_t set); bool (*search) (gl_oset_t set, const void *elt); bool (*search_atleast) (gl_oset_t set, @@ -164,7 +170,7 @@ struct gl_oset_implementation bool (*add) (gl_oset_t set, const void *elt); bool (*remove) (gl_oset_t set, const void *elt); void (*oset_free) (gl_oset_t set); - // gl_oset_iterator_t functions. + /* gl_oset_iterator_t functions. */ gl_oset_iterator_t (*iterator) (gl_oset_t set); bool (*iterator_next) (gl_oset_iterator_t *iterator, const void **eltp); void (*iterator_free) (gl_oset_iterator_t *iterator); @@ -174,6 +180,7 @@ struct gl_oset_impl_base { const struct gl_oset_implementation *vtable; gl_setelement_compar_fn compar_fn; + gl_setelement_dispose_fn dispose_fn; }; #if HAVE_INLINE @@ -185,9 +192,10 @@ struct gl_oset_impl_base # define gl_oset_create_empty gl_oset_create_empty_inline static inline gl_oset_t gl_oset_create_empty (gl_oset_implementation_t implementation, - gl_setelement_compar_fn compar_fn) + gl_setelement_compar_fn compar_fn, + gl_setelement_dispose_fn dispose_fn) { - return implementation->create_empty (implementation, compar_fn); + return implementation->create_empty (implementation, compar_fn, dispose_fn); } # define gl_oset_size gl_oset_size_inline