arraylist.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. /**
  12. * @file
  13. * @brief Internal methods for working with json_type_array objects.
  14. * Although this is exposed by the json_object_get_array() method,
  15. * it is not recommended for direct use.
  16. */
  17. #ifndef _arraylist_h_
  18. #define _arraylist_h_
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. #define ARRAY_LIST_DEFAULT_SIZE 32
  23. typedef void (array_list_free_fn) (void *data);
  24. struct array_list
  25. {
  26. void **array;
  27. size_t length;
  28. size_t size;
  29. array_list_free_fn *free_fn;
  30. };
  31. typedef struct array_list array_list;
  32. extern struct array_list*
  33. array_list_new(array_list_free_fn *free_fn);
  34. extern void
  35. array_list_free(struct array_list *al);
  36. extern void*
  37. array_list_get_idx(struct array_list *al, size_t i);
  38. extern int
  39. array_list_put_idx(struct array_list *al, size_t i, void *data);
  40. extern int
  41. array_list_add(struct array_list *al, void *data);
  42. extern size_t
  43. array_list_length(struct array_list *al);
  44. extern void
  45. array_list_sort(struct array_list *arr, int(*compar)(const void *, const void *));
  46. extern void* array_list_bsearch(const void **key,
  47. struct array_list *arr,
  48. int (*sort_fn)(const void *, const void *));
  49. extern int
  50. array_list_del_idx(struct array_list *arr, size_t idx, size_t count);
  51. #ifdef __cplusplus
  52. }
  53. #endif
  54. #endif