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.6 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 *array_list_new(array_list_free_fn *free_fn);
  33. extern void array_list_free(struct array_list *al);
  34. extern void *array_list_get_idx(struct array_list *al, size_t i);
  35. extern int array_list_put_idx(struct array_list *al, size_t i, void *data);
  36. extern int array_list_add(struct array_list *al, void *data);
  37. extern size_t array_list_length(struct array_list *al);
  38. extern void array_list_sort(struct array_list *arr, int (*compar)(const void *, const void *));
  39. extern void *array_list_bsearch(const void **key, struct array_list *arr,
  40. int (*compar)(const void *, const void *));
  41. extern int array_list_del_idx(struct array_list *arr, size_t idx, size_t count);
  42. #ifdef __cplusplus
  43. }
  44. #endif
  45. #endif