Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:19:15

0001 /*
0002  * $Id: arraylist.h,v 1.4 2006/01/26 02:16:28 mclark Exp $
0003  *
0004  * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
0005  * Michael Clark <michael@metaparadigm.com>
0006  *
0007  * This library is free software; you can redistribute it and/or modify
0008  * it under the terms of the MIT license. See COPYING for details.
0009  *
0010  */
0011 
0012 /**
0013  * @file
0014  * @brief Internal methods for working with json_type_array objects.
0015  *        Although this is exposed by the json_object_get_array() method,
0016  *        it is not recommended for direct use.
0017  */
0018 #ifndef _json_c_arraylist_h_
0019 #define _json_c_arraylist_h_
0020 
0021 #ifdef __cplusplus
0022 extern "C" {
0023 #endif
0024 
0025 #include <stddef.h>
0026 
0027 #define ARRAY_LIST_DEFAULT_SIZE 32
0028 
0029 typedef void(array_list_free_fn)(void *data);
0030 
0031 struct array_list
0032 {
0033     void **array;
0034     size_t length;
0035     size_t size;
0036     array_list_free_fn *free_fn;
0037 };
0038 typedef struct array_list array_list;
0039 
0040 /**
0041  * Allocate an array_list of the default size (32).
0042  * @deprecated Use array_list_new2() instead.
0043  */
0044 extern struct array_list *array_list_new(array_list_free_fn *free_fn);
0045 
0046 /**
0047  * Allocate an array_list of the desired size.
0048  *
0049  * If possible, the size should be chosen to closely match
0050  * the actual number of elements expected to be used.
0051  * If the exact size is unknown, there are tradeoffs to be made:
0052  * - too small - the array_list code will need to call realloc() more
0053  *   often (which might incur an additional memory copy).
0054  * - too large - will waste memory, but that can be mitigated
0055  *   by calling array_list_shrink() once the final size is known.
0056  *
0057  * @see array_list_shrink
0058  */
0059 extern struct array_list *array_list_new2(array_list_free_fn *free_fn, int initial_size);
0060 
0061 extern void array_list_free(struct array_list *al);
0062 
0063 extern void *array_list_get_idx(struct array_list *al, size_t i);
0064 
0065 extern int array_list_insert_idx(struct array_list *al, size_t i, void *data);
0066 
0067 extern int array_list_put_idx(struct array_list *al, size_t i, void *data);
0068 
0069 extern int array_list_add(struct array_list *al, void *data);
0070 
0071 extern size_t array_list_length(struct array_list *al);
0072 
0073 extern void array_list_sort(struct array_list *arr, int (*compar)(const void *, const void *));
0074 
0075 extern void *array_list_bsearch(const void **key, struct array_list *arr,
0076                                 int (*compar)(const void *, const void *));
0077 
0078 extern int array_list_del_idx(struct array_list *arr, size_t idx, size_t count);
0079 
0080 /**
0081  * Shrink the array list to just enough to fit the number of elements in it,
0082  * plus empty_slots.
0083  */
0084 extern int array_list_shrink(struct array_list *arr, size_t empty_slots);
0085 
0086 #ifdef __cplusplus
0087 }
0088 #endif
0089 
0090 #endif