Simon Josefsson wrote: > > This function is invoked for each list item that for any reason is > > being removed from the list. Is it possible to do this with the > > linked-list module?
Good idea. I'm apply this: 2007-03-15 Bruno Haible <[EMAIL PROTECTED]> * lib/gl_list.h (gl_listelement_dispose_fn): New type. (gl_list_create_empty, gl_list_create): Add dispose_fn argument. (struct gl_list_implementation): Add dispose_fn argument to the 'create_empty', 'create' methods. (struct gl_list_impl_base): Add field 'dispose_fn'. * lib/gl_list.c (gl_list_create_empty, gl_list_create): Add dispose_fn argument. * lib/gl_array_list.c (gl_array_create_empty, gl_array_create): Add dispose_fn argument. (gl_array_remove_node, gl_array_remove_at, gl_array_list_free): Call dispose_fn on the dropped values. * lib/gl_carray_list.c (gl_carray_create_empty, gl_carray_create): Add dispose_fn argument. (gl_carray_remove_at, gl_carray_list_free): Call dispose_fn on the dropped values. * lib/gl_anyavltree_list2.h (gl_tree_create): Add dispose_fn argument. (gl_tree_remove_node): Call dispose_fn on the dropped value. * lib/gl_anyrbtree_list2.h (gl_tree_create): Add dispose_fn argument. (gl_tree_remove_node): Call dispose_fn on the dropped value. * lib/gl_anytree_list2.h (gl_tree_create_empty): Add dispose_fn argument. (gl_tree_list_free): Call dispose_fn on the dropped values. * lib/gl_anytreehash_list2.h (gl_tree_list_free): Call dispose_fn on the dropped values. * lib/gl_anylinked_list2.h (gl_linked_create_empty, gl_linked_create): Add dispose_fn argument. (gl_linked_remove_node, gl_linked_remove_at, gl_linked_list_free): Call dispose_fn on the dropped values. * lib/gl_sublist.c (gl_sublist_create_empty, gl_sublist_create_fill): Add dispose_fn argument. (gl_sublist_create): Initialize the 'dispose_fn' field. * lib/clean-temp.c (create_temp_dir, register_fd): Update. * tests/test-array_list.c (main): Update. * tests/test-carray_list.c (main): Update. * tests/test-avltree_list.c (main): Update. * tests/test-rbtree_list.c (main): Update. * tests/test-avltreehash_list.c (main): Update. * tests/test-rbtreehash_list.c (main): Update. * tests/test-linked_list.c (main): Update. * tests/test-linkedhash_list.c (main): Update. * tests/test-array_oset.c (main): Update. *** lib/clean-temp.c 18 Feb 2007 15:42:40 -0000 1.13 --- lib/clean-temp.c 16 Mar 2007 00:03:58 -0000 *************** *** 320,328 **** tmpdir->dirname = NULL; tmpdir->cleanup_verbose = cleanup_verbose; tmpdir->subdirs = gl_list_create_empty (GL_LINKEDHASH_LIST, ! string_equals, string_hash, false); tmpdir->files = gl_list_create_empty (GL_LINKEDHASH_LIST, ! string_equals, string_hash, false); /* Create the temporary directory. */ xtemplate = (char *) xallocsa (PATH_MAX); --- 320,330 ---- tmpdir->dirname = NULL; tmpdir->cleanup_verbose = cleanup_verbose; tmpdir->subdirs = gl_list_create_empty (GL_LINKEDHASH_LIST, ! string_equals, string_hash, NULL, ! false); tmpdir->files = gl_list_create_empty (GL_LINKEDHASH_LIST, ! string_equals, string_hash, NULL, ! false); /* Create the temporary directory. */ xtemplate = (char *) xallocsa (PATH_MAX); *************** *** 599,605 **** register_fd (int fd) { if (descriptors == NULL) ! descriptors = gl_list_create_empty (GL_LINKEDHASH_LIST, NULL, NULL, false); gl_list_add_first (descriptors, (void *) (uintptr_t) fd); } --- 601,608 ---- register_fd (int fd) { if (descriptors == NULL) ! descriptors = gl_list_create_empty (GL_LINKEDHASH_LIST, NULL, NULL, NULL, ! false); gl_list_add_first (descriptors, (void *) (uintptr_t) fd); } *** lib/gl_anyavltree_list2.h 7 Nov 2006 14:24:05 -0000 1.2 --- lib/gl_anyavltree_list2.h 16 Mar 2007 00:03:58 -0000 *************** *** 1,5 **** /* Sequential list data type implemented by a binary tree. ! Copyright (C) 2006 Free Software Foundation, Inc. Written by Bruno Haible <[EMAIL PROTECTED]>, 2006. This program is free software; you can redistribute it and/or modify --- 1,5 ---- /* Sequential list data type implemented by a binary tree. ! Copyright (C) 2006-2007 Free Software Foundation, Inc. Written by Bruno Haible <[EMAIL PROTECTED]>, 2006. This program is free software; you can redistribute it and/or modify *************** *** 63,68 **** --- 63,69 ---- gl_tree_create (gl_list_implementation_t implementation, gl_listelement_equals_fn equals_fn, gl_listelement_hashcode_fn hashcode_fn, + gl_listelement_dispose_fn dispose_fn, bool allow_duplicates, size_t count, const void **contents) { *************** *** 71,76 **** --- 72,78 ---- list->base.vtable = implementation; list->base.equals_fn = equals_fn; list->base.hashcode_fn = hashcode_fn; + list->base.dispose_fn = dispose_fn; list->base.allow_duplicates = allow_duplicates; #if WITH_HASHTABLE { *************** *** 738,743 **** --- 740,747 ---- rebalance (list, child, -1, subst_parent != node ? subst_parent : subst); } + if (list->base.dispose_fn != NULL) + list->base.dispose_fn (node->value); free (node); return true; } *** lib/gl_anylinked_list2.h 7 Nov 2006 14:24:05 -0000 1.7 --- lib/gl_anylinked_list2.h 16 Mar 2007 00:03:58 -0000 *************** *** 1,5 **** /* Sequential list data type implemented by a linked list. ! Copyright (C) 2006 Free Software Foundation, Inc. Written by Bruno Haible <[EMAIL PROTECTED]>, 2006. This program is free software; you can redistribute it and/or modify --- 1,5 ---- /* Sequential list data type implemented by a linked list. ! Copyright (C) 2006-2007 Free Software Foundation, Inc. Written by Bruno Haible <[EMAIL PROTECTED]>, 2006. This program is free software; you can redistribute it and/or modify *************** *** 41,46 **** --- 41,47 ---- gl_linked_create_empty (gl_list_implementation_t implementation, gl_listelement_equals_fn equals_fn, gl_listelement_hashcode_fn hashcode_fn, + gl_listelement_dispose_fn dispose_fn, bool allow_duplicates) { struct gl_list_impl *list = XMALLOC (struct gl_list_impl); *************** *** 48,53 **** --- 49,55 ---- list->base.vtable = implementation; list->base.equals_fn = equals_fn; list->base.hashcode_fn = hashcode_fn; + list->base.dispose_fn = dispose_fn; list->base.allow_duplicates = allow_duplicates; #if WITH_HASHTABLE list->table_size = 11; *************** *** 64,69 **** --- 66,72 ---- gl_linked_create (gl_list_implementation_t implementation, gl_listelement_equals_fn equals_fn, gl_listelement_hashcode_fn hashcode_fn, + gl_listelement_dispose_fn dispose_fn, bool allow_duplicates, size_t count, const void **contents) { *************** *** 73,78 **** --- 76,82 ---- list->base.vtable = implementation; list->base.equals_fn = equals_fn; list->base.hashcode_fn = hashcode_fn; + list->base.dispose_fn = dispose_fn; list->base.allow_duplicates = allow_duplicates; #if WITH_HASHTABLE { *************** *** 684,689 **** --- 688,695 ---- next->prev = prev; list->count--; + if (list->base.dispose_fn != NULL) + list->base.dispose_fn (node->value); free (node); return true; } *************** *** 730,735 **** --- 736,743 ---- #endif list->count--; + if (list->base.dispose_fn != NULL) + list->base.dispose_fn (removed_node->value); free (removed_node); return true; } *************** *** 748,758 **** --- 756,769 ---- static void gl_linked_list_free (gl_list_t list) { + gl_listelement_dispose_fn dispose = list->base.dispose_fn; gl_list_node_t node; for (node = list->root.next; node != &list->root; ) { gl_list_node_t next = node->next; + if (dispose != NULL) + dispose (node->value); free (node); node = next; } *** lib/gl_anyrbtree_list2.h 7 Nov 2006 14:24:05 -0000 1.2 --- lib/gl_anyrbtree_list2.h 16 Mar 2007 00:03:58 -0000 *************** *** 1,5 **** /* Sequential list data type implemented by a binary tree. ! Copyright (C) 2006 Free Software Foundation, Inc. Written by Bruno Haible <[EMAIL PROTECTED]>, 2006. This program is free software; you can redistribute it and/or modify --- 1,5 ---- /* Sequential list data type implemented by a binary tree. ! Copyright (C) 2006-2007 Free Software Foundation, Inc. Written by Bruno Haible <[EMAIL PROTECTED]>, 2006. This program is free software; you can redistribute it and/or modify *************** *** 68,73 **** --- 68,74 ---- gl_tree_create (gl_list_implementation_t implementation, gl_listelement_equals_fn equals_fn, gl_listelement_hashcode_fn hashcode_fn, + gl_listelement_dispose_fn dispose_fn, bool allow_duplicates, size_t count, const void **contents) { *************** *** 76,81 **** --- 77,83 ---- list->base.vtable = implementation; list->base.equals_fn = equals_fn; list->base.hashcode_fn = hashcode_fn; + list->base.dispose_fn = dispose_fn; list->base.allow_duplicates = allow_duplicates; #if WITH_HASHTABLE { *************** *** 959,964 **** --- 961,968 ---- } } + if (list->base.dispose_fn != NULL) + list->base.dispose_fn (node->value); free (node); return true; } *** lib/gl_anytree_list2.h 7 Nov 2006 14:24:05 -0000 1.5 --- lib/gl_anytree_list2.h 16 Mar 2007 00:03:58 -0000 *************** *** 1,5 **** /* Sequential list data type implemented by a binary tree. ! Copyright (C) 2006 Free Software Foundation, Inc. Written by Bruno Haible <[EMAIL PROTECTED]>, 2006. This program is free software; you can redistribute it and/or modify --- 1,5 ---- /* Sequential list data type implemented by a binary tree. ! Copyright (C) 2006-2007 Free Software Foundation, Inc. Written by Bruno Haible <[EMAIL PROTECTED]>, 2006. This program is free software; you can redistribute it and/or modify *************** *** 23,28 **** --- 23,29 ---- gl_tree_create_empty (gl_list_implementation_t implementation, gl_listelement_equals_fn equals_fn, gl_listelement_hashcode_fn hashcode_fn, + gl_listelement_dispose_fn dispose_fn, bool allow_duplicates) { struct gl_list_impl *list = XMALLOC (struct gl_list_impl); *************** *** 30,35 **** --- 31,37 ---- list->base.vtable = implementation; list->base.equals_fn = equals_fn; list->base.hashcode_fn = hashcode_fn; + list->base.dispose_fn = dispose_fn; list->base.allow_duplicates = allow_duplicates; #if WITH_HASHTABLE list->table_size = 11; *************** *** 457,462 **** --- 459,466 ---- if (!stack_ptr->rightp) break; /* Free the current node. */ + if (list->base.dispose_fn != NULL) + list->base.dispose_fn (node->value); free (node); } /* Descend on right branch. */ *** lib/gl_anytreehash_list2.h 10 Oct 2006 12:48:57 -0000 1.3 --- lib/gl_anytreehash_list2.h 16 Mar 2007 00:03:58 -0000 *************** *** 1,5 **** /* Sequential list data type implemented by a hash table with a binary tree. ! Copyright (C) 2006 Free Software Foundation, Inc. Written by Bruno Haible <[EMAIL PROTECTED]>, 2006. This program is free software; you can redistribute it and/or modify --- 1,5 ---- /* Sequential list data type implemented by a hash table with a binary tree. ! Copyright (C) 2006-2007 Free Software Foundation, Inc. Written by Bruno Haible <[EMAIL PROTECTED]>, 2006. This program is free software; you can redistribute it and/or modify *************** *** 198,203 **** --- 198,205 ---- if (!stack_ptr->rightp) break; /* Free the current node. */ + if (list->base.dispose_fn != NULL) + list->base.dispose_fn (node->value); free (node); } /* Descend on right branch. */ *** lib/gl_array_list.c 6 Nov 2006 13:03:51 -0000 1.8 --- lib/gl_array_list.c 16 Mar 2007 00:03:58 -0000 *************** *** 1,5 **** /* Sequential list data type implemented by an array. ! Copyright (C) 2006 Free Software Foundation, Inc. Written by Bruno Haible <[EMAIL PROTECTED]>, 2006. This program is free software; you can redistribute it and/or modify --- 1,5 ---- /* Sequential list data type implemented by an array. ! Copyright (C) 2006-2007 Free Software Foundation, Inc. Written by Bruno Haible <[EMAIL PROTECTED]>, 2006. This program is free software; you can redistribute it and/or modify *************** *** 56,61 **** --- 56,62 ---- gl_array_create_empty (gl_list_implementation_t implementation, gl_listelement_equals_fn equals_fn, gl_listelement_hashcode_fn hashcode_fn, + gl_listelement_dispose_fn dispose_fn, bool allow_duplicates) { struct gl_list_impl *list = XMALLOC (struct gl_list_impl); *************** *** 63,68 **** --- 64,70 ---- list->base.vtable = implementation; list->base.equals_fn = equals_fn; list->base.hashcode_fn = hashcode_fn; + list->base.dispose_fn = dispose_fn; list->base.allow_duplicates = allow_duplicates; list->elements = NULL; list->count = 0; *************** *** 75,80 **** --- 77,83 ---- gl_array_create (gl_list_implementation_t implementation, gl_listelement_equals_fn equals_fn, gl_listelement_hashcode_fn hashcode_fn, + gl_listelement_dispose_fn dispose_fn, bool allow_duplicates, size_t count, const void **contents) { *************** *** 83,88 **** --- 86,92 ---- list->base.vtable = implementation; list->base.equals_fn = equals_fn; list->base.hashcode_fn = hashcode_fn; + list->base.dispose_fn = dispose_fn; list->base.allow_duplicates = allow_duplicates; if (count > 0) { *************** *** 345,350 **** --- 349,356 ---- abort (); position = index; elements = list->elements; + if (list->base.dispose_fn != NULL) + list->base.dispose_fn (elements[position]); for (i = position + 1; i < count; i++) elements[i - 1] = elements[i]; list->count = count - 1; *************** *** 362,367 **** --- 368,375 ---- /* Invalid argument. */ abort (); elements = list->elements; + if (list->base.dispose_fn != NULL) + list->base.dispose_fn (elements[position]); for (i = position + 1; i < count; i++) elements[i - 1] = elements[i]; list->count = count - 1; *************** *** 382,388 **** gl_array_list_free (gl_list_t list) { if (list->elements != NULL) ! free (list->elements); free (list); } --- 390,412 ---- gl_array_list_free (gl_list_t list) { if (list->elements != NULL) ! { ! if (list->base.dispose_fn != NULL) ! { ! size_t count = list->count; ! ! if (count > 0) ! { ! gl_listelement_dispose_fn dispose = list->base.dispose_fn; ! const void **elements = list->elements; ! ! do ! dispose (*elements++); ! while (--count > 0); ! } ! } ! free (list->elements); ! } free (list); } *** lib/gl_carray_list.c 6 Nov 2006 13:03:10 -0000 1.7 --- lib/gl_carray_list.c 16 Mar 2007 00:03:58 -0000 *************** *** 1,5 **** /* Sequential list data type implemented by a circular array. ! Copyright (C) 2006 Free Software Foundation, Inc. Written by Bruno Haible <[EMAIL PROTECTED]>, 2006. This program is free software; you can redistribute it and/or modify --- 1,5 ---- /* Sequential list data type implemented by a circular array. ! Copyright (C) 2006-2007 Free Software Foundation, Inc. Written by Bruno Haible <[EMAIL PROTECTED]>, 2006. This program is free software; you can redistribute it and/or modify *************** *** 57,71 **** static gl_list_t gl_carray_create_empty (gl_list_implementation_t implementation, ! gl_listelement_equals_fn equals_fn, ! gl_listelement_hashcode_fn hashcode_fn, ! bool allow_duplicates) { struct gl_list_impl *list = XMALLOC (struct gl_list_impl); list->base.vtable = implementation; list->base.equals_fn = equals_fn; list->base.hashcode_fn = hashcode_fn; list->base.allow_duplicates = allow_duplicates; list->elements = NULL; list->offset = 0; --- 57,73 ---- static gl_list_t gl_carray_create_empty (gl_list_implementation_t implementation, ! gl_listelement_equals_fn equals_fn, ! gl_listelement_hashcode_fn hashcode_fn, ! gl_listelement_dispose_fn dispose_fn, ! bool allow_duplicates) { struct gl_list_impl *list = XMALLOC (struct gl_list_impl); list->base.vtable = implementation; list->base.equals_fn = equals_fn; list->base.hashcode_fn = hashcode_fn; + list->base.dispose_fn = dispose_fn; list->base.allow_duplicates = allow_duplicates; list->elements = NULL; list->offset = 0; *************** *** 77,92 **** static gl_list_t gl_carray_create (gl_list_implementation_t implementation, ! gl_listelement_equals_fn equals_fn, ! gl_listelement_hashcode_fn hashcode_fn, ! bool allow_duplicates, ! size_t count, const void **contents) { struct gl_list_impl *list = XMALLOC (struct gl_list_impl); list->base.vtable = implementation; list->base.equals_fn = equals_fn; list->base.hashcode_fn = hashcode_fn; list->base.allow_duplicates = allow_duplicates; if (count > 0) { --- 79,96 ---- static gl_list_t gl_carray_create (gl_list_implementation_t implementation, ! gl_listelement_equals_fn equals_fn, ! gl_listelement_hashcode_fn hashcode_fn, ! gl_listelement_dispose_fn dispose_fn, ! bool allow_duplicates, ! size_t count, const void **contents) { struct gl_list_impl *list = XMALLOC (struct gl_list_impl); list->base.vtable = implementation; list->base.equals_fn = equals_fn; list->base.hashcode_fn = hashcode_fn; + list->base.dispose_fn = dispose_fn; list->base.allow_duplicates = allow_duplicates; if (count > 0) { *************** *** 448,453 **** --- 452,459 ---- /* Here we must have list->offset > 0, hence list->allocated > 0. */ size_t i1 = list->allocated - 1; i2 -= list->allocated; + if (list->base.dispose_fn != NULL) + list->base.dispose_fn (elements[i2]); for (i = i2; i > 0; i--) elements[i] = elements[i - 1]; elements[0] = elements[i1]; *************** *** 456,461 **** --- 462,469 ---- } else { + if (list->base.dispose_fn != NULL) + list->base.dispose_fn (elements[i2]); for (i = i2; i > i0; i--) elements[i] = elements[i - 1]; } *************** *** 474,479 **** --- 482,489 ---- { i1 -= list->allocated; i3 -= list->allocated; + if (list->base.dispose_fn != NULL) + list->base.dispose_fn (elements[i1]); for (i = i1; i < i3; i++) elements[i] = elements[i + 1]; } *************** *** 482,487 **** --- 492,499 ---- /* Here we must have list->offset > 0, hence list->allocated > 0. */ size_t i2 = list->allocated - 1; i3 -= list->allocated; + if (list->base.dispose_fn != NULL) + list->base.dispose_fn (elements[i1]); for (i = i1; i < i2; i++) elements[i] = elements[i + 1]; elements[i2] = elements[0]; *************** *** 490,495 **** --- 502,509 ---- } else { + if (list->base.dispose_fn != NULL) + list->base.dispose_fn (elements[i1]); for (i = i1; i < i3; i++) elements[i] = elements[i + 1]; } *************** *** 524,530 **** gl_carray_list_free (gl_list_t list) { if (list->elements != NULL) ! free (list->elements); free (list); } --- 538,579 ---- gl_carray_list_free (gl_list_t list) { if (list->elements != NULL) ! { ! if (list->base.dispose_fn != NULL) ! { ! size_t count = list->count; ! ! if (count > 0) ! { ! gl_listelement_dispose_fn dispose = list->base.dispose_fn; ! const void **elements = list->elements; ! size_t i1 = list->offset; ! size_t i3 = list->offset + count - 1; ! ! if (i3 >= list->allocated) ! { ! /* Here we must have list->offset > 0, hence ! list->allocated > 0. */ ! size_t i2 = list->allocated - 1; ! size_t i; ! ! i3 -= list->allocated; ! for (i = i1; i <= i2; i++) ! dispose (elements[i]); ! for (i = 0; i <= i3; i++) ! dispose (elements[i]); ! } ! else ! { ! size_t i; ! ! for (i = i1; i <= i3; i++) ! dispose (elements[i]); ! } ! } ! } ! free (list->elements); ! } free (list); } *** lib/gl_list.c 6 Oct 2006 12:06:07 -0000 1.4 --- lib/gl_list.c 16 Mar 2007 00:03:58 -0000 *************** *** 1,5 **** /* Abstract sequential list data type. ! Copyright (C) 2006 Free Software Foundation, Inc. Written by Bruno Haible <[EMAIL PROTECTED]>, 2006. This program is free software; you can redistribute it and/or modify --- 1,5 ---- /* Abstract sequential list data type. ! Copyright (C) 2006-2007 Free Software Foundation, Inc. Written by Bruno Haible <[EMAIL PROTECTED]>, 2006. This program is free software; you can redistribute it and/or modify *************** *** 31,51 **** gl_list_create_empty (gl_list_implementation_t implementation, gl_listelement_equals_fn equals_fn, gl_listelement_hashcode_fn hashcode_fn, bool allow_duplicates) { return implementation->create_empty (implementation, equals_fn, hashcode_fn, ! allow_duplicates); } gl_list_t gl_list_create (gl_list_implementation_t implementation, gl_listelement_equals_fn equals_fn, gl_listelement_hashcode_fn hashcode_fn, bool allow_duplicates, size_t count, const void **contents) { return implementation->create (implementation, equals_fn, hashcode_fn, ! allow_duplicates, count, contents); } size_t --- 31,53 ---- gl_list_create_empty (gl_list_implementation_t implementation, gl_listelement_equals_fn equals_fn, gl_listelement_hashcode_fn hashcode_fn, + gl_listelement_dispose_fn dispose_fn, bool allow_duplicates) { return implementation->create_empty (implementation, equals_fn, hashcode_fn, ! dispose_fn, allow_duplicates); } gl_list_t gl_list_create (gl_list_implementation_t implementation, gl_listelement_equals_fn equals_fn, gl_listelement_hashcode_fn hashcode_fn, + gl_listelement_dispose_fn dispose_fn, bool allow_duplicates, size_t count, const void **contents) { return implementation->create (implementation, equals_fn, hashcode_fn, ! dispose_fn, allow_duplicates, count, contents); } size_t *** lib/gl_list.h 24 Oct 2006 13:25:29 -0000 1.4 --- lib/gl_list.h 16 Mar 2007 00:03:58 -0000 *************** *** 1,5 **** /* Abstract sequential list data type. ! Copyright (C) 2006 Free Software Foundation, Inc. Written by Bruno Haible <[EMAIL PROTECTED]>, 2006. This program is free software; you can redistribute it and/or modify --- 1,5 ---- /* Abstract sequential list data type. ! Copyright (C) 2006-2007 Free Software Foundation, Inc. Written by Bruno Haible <[EMAIL PROTECTED]>, 2006. This program is free software; you can redistribute it and/or modify *************** *** 102,107 **** --- 102,111 ---- NULL denotes a function that depends only on the pointer itself. */ typedef size_t (*gl_listelement_hashcode_fn) (const void *elt); + /* Type of function used to dispose an element once it's removed from a list. + NULL denotes a no-op. */ + typedef void (*gl_listelement_dispose_fn) (const void *elt); + struct gl_list_impl; /* Type representing an entire list. */ typedef struct gl_list_impl * gl_list_t; *************** *** 122,132 **** --- 126,138 ---- GL_RBTREEHASH_LIST. EQUALS_FN is an element comparison function or NULL. HASHCODE_FN is an element hash code function or NULL. + DISPOSE_FN is an element disposal function or NULL. ALLOW_DUPLICATES is false if duplicate elements shall not be allowed in the list. The implementation may verify this at runtime. */ extern gl_list_t gl_list_create_empty (gl_list_implementation_t implementation, gl_listelement_equals_fn equals_fn, gl_listelement_hashcode_fn hashcode_fn, + gl_listelement_dispose_fn dispose_fn, bool allow_duplicates); /* Create a list with given contents. *************** *** 135,140 **** --- 141,147 ---- GL_RBTREEHASH_LIST. EQUALS_FN is an element comparison function or NULL. HASHCODE_FN is an element hash code function or NULL. + DISPOSE_FN is an element disposal function or NULL. ALLOW_DUPLICATES is false if duplicate elements shall not be allowed in the list. The implementation may verify this at runtime. COUNT is the number of initial elements. *************** *** 142,147 **** --- 149,155 ---- extern gl_list_t gl_list_create (gl_list_implementation_t implementation, gl_listelement_equals_fn equals_fn, gl_listelement_hashcode_fn hashcode_fn, + gl_listelement_dispose_fn dispose_fn, bool allow_duplicates, size_t count, const void **contents); *************** *** 364,373 **** --- 372,383 ---- gl_list_t (*create_empty) (gl_list_implementation_t implementation, gl_listelement_equals_fn equals_fn, gl_listelement_hashcode_fn hashcode_fn, + gl_listelement_dispose_fn dispose_fn, bool allow_duplicates); gl_list_t (*create) (gl_list_implementation_t implementation, gl_listelement_equals_fn equals_fn, gl_listelement_hashcode_fn hashcode_fn, + gl_listelement_dispose_fn dispose_fn, bool allow_duplicates, size_t count, const void **contents); size_t (*size) (gl_list_t list); *************** *** 429,434 **** --- 439,445 ---- const struct gl_list_implementation *vtable; gl_listelement_equals_fn equals_fn; gl_listelement_hashcode_fn hashcode_fn; + gl_listelement_dispose_fn dispose_fn; bool allow_duplicates; }; *************** *** 443,452 **** gl_list_create_empty (gl_list_implementation_t implementation, gl_listelement_equals_fn equals_fn, gl_listelement_hashcode_fn hashcode_fn, bool allow_duplicates) { return implementation->create_empty (implementation, equals_fn, hashcode_fn, ! allow_duplicates); } # define gl_list_create gl_list_create_inline --- 454,464 ---- gl_list_create_empty (gl_list_implementation_t implementation, gl_listelement_equals_fn equals_fn, gl_listelement_hashcode_fn hashcode_fn, + gl_listelement_dispose_fn dispose_fn, bool allow_duplicates) { return implementation->create_empty (implementation, equals_fn, hashcode_fn, ! dispose_fn, allow_duplicates); } # define gl_list_create gl_list_create_inline *************** *** 454,464 **** gl_list_create (gl_list_implementation_t implementation, gl_listelement_equals_fn equals_fn, gl_listelement_hashcode_fn hashcode_fn, bool allow_duplicates, size_t count, const void **contents) { return implementation->create (implementation, equals_fn, hashcode_fn, ! allow_duplicates, count, contents); } # define gl_list_size gl_list_size_inline --- 466,477 ---- gl_list_create (gl_list_implementation_t implementation, gl_listelement_equals_fn equals_fn, gl_listelement_hashcode_fn hashcode_fn, + gl_listelement_dispose_fn dispose_fn, bool allow_duplicates, size_t count, const void **contents) { return implementation->create (implementation, equals_fn, hashcode_fn, ! dispose_fn, allow_duplicates, count, contents); } # define gl_list_size gl_list_size_inline *** lib/gl_sublist.c 6 Nov 2006 13:03:10 -0000 1.2 --- lib/gl_sublist.c 16 Mar 2007 00:03:59 -0000 *************** *** 1,5 **** /* Sequential list data type backed by another list. ! Copyright (C) 2006 Free Software Foundation, Inc. Written by Bruno Haible <[EMAIL PROTECTED]>, 2006. This program is free software; you can redistribute it and/or modify --- 1,5 ---- /* Sequential list data type backed by another list. ! Copyright (C) 2006-2007 Free Software Foundation, Inc. Written by Bruno Haible <[EMAIL PROTECTED]>, 2006. This program is free software; you can redistribute it and/or modify *************** *** 53,58 **** --- 53,59 ---- gl_sublist_create_empty (gl_list_implementation_t implementation, gl_listelement_equals_fn equals_fn, gl_listelement_hashcode_fn hashcode_fn, + gl_listelement_dispose_fn dispose_fn, bool allow_duplicates) { /* Shouldn't be called. */ *************** *** 63,68 **** --- 64,70 ---- gl_sublist_create_fill (gl_list_implementation_t implementation, gl_listelement_equals_fn equals_fn, gl_listelement_hashcode_fn hashcode_fn, + gl_listelement_dispose_fn dispose_fn, bool allow_duplicates, size_t count, const void **contents) { *************** *** 435,440 **** --- 437,443 ---- list->base.vtable = &gl_sublist_list_implementation; list->base.equals_fn = whole_list->base.equals_fn; /* actually unused */ list->base.hashcode_fn = whole_list->base.hashcode_fn; /* actually unused */ + list->base.dispose_fn = whole_list->base.dispose_fn; /* actually unused */ list->base.allow_duplicates = whole_list->base.allow_duplicates; /* unused */ if (whole_list->base.vtable == &gl_sublist_list_implementation) { *** tests/test-array_list.c 3 Mar 2007 01:46:17 -0000 1.3 --- tests/test-array_list.c 16 Mar 2007 00:03:59 -0000 *************** *** 71,80 **** contents[i] = RANDOM_OBJECT (); /* Create list1. */ ! list1 = gl_list_create (GL_ARRAY_LIST, NULL, NULL, true, initial_size, contents); /* Create list2. */ ! list2 = gl_list_create_empty (GL_ARRAY_LIST, NULL, NULL, true); for (i = 0; i < initial_size; i++) gl_list_add_last (list2, contents[i]); --- 71,80 ---- contents[i] = RANDOM_OBJECT (); /* Create list1. */ ! list1 = gl_list_create (GL_ARRAY_LIST, NULL, NULL, NULL, true, initial_size, contents); /* Create list2. */ ! list2 = gl_list_create_empty (GL_ARRAY_LIST, NULL, NULL, NULL, true); for (i = 0; i < initial_size; i++) gl_list_add_last (list2, contents[i]); *** tests/test-array_oset.c 15 Mar 2007 23:56:14 -0000 1.3 --- tests/test-array_oset.c 16 Mar 2007 00:03:59 -0000 *************** *** 91,97 **** set1 = gl_oset_create_empty (GL_ARRAY_OSET, (gl_setelement_compar_fn) strcmp, NULL); /* Create set2. */ ! set2 = gl_list_create_empty (GL_ARRAY_LIST, NULL, NULL, false); check_all (set1, set2); --- 91,97 ---- set1 = gl_oset_create_empty (GL_ARRAY_OSET, (gl_setelement_compar_fn) strcmp, NULL); /* Create set2. */ ! set2 = gl_list_create_empty (GL_ARRAY_LIST, NULL, NULL, NULL, false); check_all (set1, set2); *** tests/test-avltree_list.c 3 Mar 2007 01:50:21 -0000 1.2 --- tests/test-avltree_list.c 16 Mar 2007 00:03:59 -0000 *************** *** 81,95 **** contents[i] = RANDOM_OBJECT (); /* Create list1. */ ! list1 = gl_list_create (GL_ARRAY_LIST, NULL, NULL, true, initial_size, contents); /* Create list2. */ ! list2 = gl_list_create_empty (GL_AVLTREE_LIST, NULL, NULL, true); for (i = 0; i < initial_size; i++) gl_list_add_last (list2, contents[i]); /* Create list3. */ ! list3 = gl_list_create (GL_AVLTREE_LIST, NULL, NULL, true, initial_size, contents); check_all (list1, list2, list3); --- 81,95 ---- contents[i] = RANDOM_OBJECT (); /* Create list1. */ ! list1 = gl_list_create (GL_ARRAY_LIST, NULL, NULL, NULL, true, initial_size, contents); /* Create list2. */ ! list2 = gl_list_create_empty (GL_AVLTREE_LIST, NULL, NULL, NULL, true); for (i = 0; i < initial_size; i++) gl_list_add_last (list2, contents[i]); /* Create list3. */ ! list3 = gl_list_create (GL_AVLTREE_LIST, NULL, NULL, NULL, true, initial_size, contents); check_all (list1, list2, list3); *** tests/test-avltreehash_list.c 3 Mar 2007 01:54:22 -0000 1.2 --- tests/test-avltreehash_list.c 16 Mar 2007 00:03:59 -0000 *************** *** 111,127 **** /* Create list1. */ list1 = gl_list_create (GL_ARRAY_LIST, ! string_equals, string_hash, true, initial_size, contents); /* Create list2. */ list2 = gl_list_create_empty (GL_AVLTREEHASH_LIST, ! string_equals, string_hash, true); for (i = 0; i < initial_size; i++) gl_list_add_last (list2, contents[i]); /* Create list3. */ list3 = gl_list_create (GL_AVLTREEHASH_LIST, ! string_equals, string_hash, true, initial_size, contents); check_all (list1, list2, list3); --- 111,127 ---- /* Create list1. */ list1 = gl_list_create (GL_ARRAY_LIST, ! string_equals, string_hash, NULL, true, initial_size, contents); /* Create list2. */ list2 = gl_list_create_empty (GL_AVLTREEHASH_LIST, ! string_equals, string_hash, NULL, true); for (i = 0; i < initial_size; i++) gl_list_add_last (list2, contents[i]); /* Create list3. */ list3 = gl_list_create (GL_AVLTREEHASH_LIST, ! string_equals, string_hash, NULL, true, initial_size, contents); check_all (list1, list2, list3); *** tests/test-carray_list.c 3 Mar 2007 04:01:15 -0000 1.2 --- tests/test-carray_list.c 16 Mar 2007 00:03:59 -0000 *************** *** 79,93 **** contents[i] = RANDOM_OBJECT (); /* Create list1. */ ! list1 = gl_list_create (GL_ARRAY_LIST, NULL, NULL, true, initial_size, contents); /* Create list2. */ ! list2 = gl_list_create_empty (GL_CARRAY_LIST, NULL, NULL, true); for (i = 0; i < initial_size; i++) gl_list_add_last (list2, contents[i]); /* Create list3. */ ! list3 = gl_list_create (GL_CARRAY_LIST, NULL, NULL, true, initial_size, contents); check_all (list1, list2, list3); --- 79,93 ---- contents[i] = RANDOM_OBJECT (); /* Create list1. */ ! list1 = gl_list_create (GL_ARRAY_LIST, NULL, NULL, NULL, true, initial_size, contents); /* Create list2. */ ! list2 = gl_list_create_empty (GL_CARRAY_LIST, NULL, NULL, NULL, true); for (i = 0; i < initial_size; i++) gl_list_add_last (list2, contents[i]); /* Create list3. */ ! list3 = gl_list_create (GL_CARRAY_LIST, NULL, NULL, NULL, true, initial_size, contents); check_all (list1, list2, list3); *** tests/test-linked_list.c 3 Mar 2007 12:42:29 -0000 1.2 --- tests/test-linked_list.c 16 Mar 2007 00:03:59 -0000 *************** *** 79,93 **** contents[i] = RANDOM_OBJECT (); /* Create list1. */ ! list1 = gl_list_create (GL_ARRAY_LIST, NULL, NULL, true, initial_size, contents); /* Create list2. */ ! list2 = gl_list_create_empty (GL_LINKED_LIST, NULL, NULL, true); for (i = 0; i < initial_size; i++) gl_list_add_last (list2, contents[i]); /* Create list3. */ ! list3 = gl_list_create (GL_LINKED_LIST, NULL, NULL, true, initial_size, contents); check_all (list1, list2, list3); --- 79,93 ---- contents[i] = RANDOM_OBJECT (); /* Create list1. */ ! list1 = gl_list_create (GL_ARRAY_LIST, NULL, NULL, NULL, true, initial_size, contents); /* Create list2. */ ! list2 = gl_list_create_empty (GL_LINKED_LIST, NULL, NULL, NULL, true); for (i = 0; i < initial_size; i++) gl_list_add_last (list2, contents[i]); /* Create list3. */ ! list3 = gl_list_create (GL_LINKED_LIST, NULL, NULL, NULL, true, initial_size, contents); check_all (list1, list2, list3); *** tests/test-linkedhash_list.c 3 Mar 2007 04:05:36 -0000 1.2 --- tests/test-linkedhash_list.c 16 Mar 2007 00:03:59 -0000 *************** *** 107,123 **** /* Create list1. */ list1 = gl_list_create (GL_ARRAY_LIST, ! string_equals, string_hash, true, initial_size, contents); /* Create list2. */ list2 = gl_list_create_empty (GL_LINKEDHASH_LIST, ! string_equals, string_hash, true); for (i = 0; i < initial_size; i++) gl_list_add_last (list2, contents[i]); /* Create list3. */ list3 = gl_list_create (GL_LINKEDHASH_LIST, ! string_equals, string_hash, true, initial_size, contents); check_all (list1, list2, list3); --- 107,123 ---- /* Create list1. */ list1 = gl_list_create (GL_ARRAY_LIST, ! string_equals, string_hash, NULL, true, initial_size, contents); /* Create list2. */ list2 = gl_list_create_empty (GL_LINKEDHASH_LIST, ! string_equals, string_hash, NULL, true); for (i = 0; i < initial_size; i++) gl_list_add_last (list2, contents[i]); /* Create list3. */ list3 = gl_list_create (GL_LINKEDHASH_LIST, ! string_equals, string_hash, NULL, true, initial_size, contents); check_all (list1, list2, list3); *** tests/test-rbtree_list.c 3 Mar 2007 12:56:10 -0000 1.2 --- tests/test-rbtree_list.c 16 Mar 2007 00:03:59 -0000 *************** *** 83,97 **** contents[i] = RANDOM_OBJECT (); /* Create list1. */ ! list1 = gl_list_create (GL_ARRAY_LIST, NULL, NULL, true, initial_size, contents); /* Create list2. */ ! list2 = gl_list_create_empty (GL_RBTREE_LIST, NULL, NULL, true); for (i = 0; i < initial_size; i++) gl_list_add_last (list2, contents[i]); /* Create list3. */ ! list3 = gl_list_create (GL_RBTREE_LIST, NULL, NULL, true, initial_size, contents); check_all (list1, list2, list3); --- 83,97 ---- contents[i] = RANDOM_OBJECT (); /* Create list1. */ ! list1 = gl_list_create (GL_ARRAY_LIST, NULL, NULL, NULL, true, initial_size, contents); /* Create list2. */ ! list2 = gl_list_create_empty (GL_RBTREE_LIST, NULL, NULL, NULL, true); for (i = 0; i < initial_size; i++) gl_list_add_last (list2, contents[i]); /* Create list3. */ ! list3 = gl_list_create (GL_RBTREE_LIST, NULL, NULL, NULL, true, initial_size, contents); check_all (list1, list2, list3); *** tests/test-rbtreehash_list.c 3 Mar 2007 13:00:31 -0000 1.2 --- tests/test-rbtreehash_list.c 16 Mar 2007 00:03:59 -0000 *************** *** 111,127 **** /* Create list1. */ list1 = gl_list_create (GL_ARRAY_LIST, ! string_equals, string_hash, true, initial_size, contents); /* Create list2. */ list2 = gl_list_create_empty (GL_RBTREEHASH_LIST, ! string_equals, string_hash, true); for (i = 0; i < initial_size; i++) gl_list_add_last (list2, contents[i]); /* Create list3. */ list3 = gl_list_create (GL_RBTREEHASH_LIST, ! string_equals, string_hash, true, initial_size, contents); check_all (list1, list2, list3); --- 111,127 ---- /* Create list1. */ list1 = gl_list_create (GL_ARRAY_LIST, ! string_equals, string_hash, NULL, true, initial_size, contents); /* Create list2. */ list2 = gl_list_create_empty (GL_RBTREEHASH_LIST, ! string_equals, string_hash, NULL, true); for (i = 0; i < initial_size; i++) gl_list_add_last (list2, contents[i]); /* Create list3. */ list3 = gl_list_create (GL_RBTREEHASH_LIST, ! string_equals, string_hash, NULL, true, initial_size, contents); check_all (list1, list2, list3);