You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

arraylist.h 1.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * $Id: arraylist.h,v 1.4 2006/01/26 02:16:28 mclark Exp $
  3. *
  4. * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
  5. * Michael Clark <michael@metaparadigm.com>
  6. *
  7. * This library is free software; you can redistribute it and/or modify
  8. * it under the terms of the MIT license. See COPYING for details.
  9. *
  10. */
  11. #ifndef _arraylist_h_
  12. #define _arraylist_h_
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. #define ARRAY_LIST_DEFAULT_SIZE 32
  17. typedef void (array_list_free_fn) (void *data);
  18. struct array_list
  19. {
  20. void **array;
  21. size_t length;
  22. size_t size;
  23. array_list_free_fn *free_fn;
  24. };
  25. extern struct array_list*
  26. array_list_new(array_list_free_fn *free_fn);
  27. extern void
  28. array_list_free(struct array_list *al);
  29. extern void*
  30. array_list_get_idx(struct array_list *al, size_t i);
  31. extern int
  32. array_list_put_idx(struct array_list *al, size_t i, void *data);
  33. extern int
  34. array_list_add(struct array_list *al, void *data);
  35. extern size_t
  36. array_list_length(struct array_list *al);
  37. extern void
  38. array_list_sort(struct array_list *arr, int(*compar)(const void *, const void *));
  39. extern void* array_list_bsearch(const void **key,
  40. struct array_list *arr,
  41. int (*sort_fn)(const void *, const void *));
  42. extern int
  43. array_list_del_idx(struct array_list *arr, size_t idx, size_t count);
  44. #ifdef __cplusplus
  45. }
  46. #endif
  47. #endif