1 //metadoc List copyright Steve Dekorte 2002
2 //metadoc List license BSD revised
3 /*metadoc List description
4 	List - an array of void pointers
5 	User is responsible for io_freeing items
6 */
7 
8 #ifndef LIST_DEFINED
9 #define LIST_DEFINED 1
10 
11 #include "Common.h"
12 #include "PortableSorting.h"
13 #include <stdlib.h>
14 #include <stdio.h>
15 #include <string.h>
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 #ifdef LOW_MEMORY_SYSTEM
22 	#define LIST_START_SIZE 1
23 	#define LIST_RESIZE_FACTOR 2
24 #else
25 	#define LIST_START_SIZE 1
26 	#define LIST_RESIZE_FACTOR 2
27 #endif
28 
29 #define LIST_AT_(self, n) self->items[n]
30 
31 
32 typedef void  (ListDoCallback)(void *);
33 typedef void  (ListDoWithCallback)(void *, void *);
34 typedef void *(ListCollectCallback)(void *);
35 typedef int   (ListSelectCallback)(void *);
36 typedef int   (ListDetectCallback)(void *);
37 typedef int   (ListSortCallback)(const void *, const void *);
38 typedef int   (ListSortRCallback)(void *, const void *, const void *);
39 typedef int   (ListCompareFunc)(const void *, const void *);
40 
41 typedef struct
42 {
43 	void **items;
44 	size_t size;
45 	size_t memSize;
46 } List;
47 
48 typedef struct
49 {
50 	List *list;
51 	size_t index;
52 } ListCursor;
53 
54 BASEKIT_API List *List_new(void);
55 BASEKIT_API List *List_clone(const List *self);
56 BASEKIT_API List *List_cloneSlice(const List *self, long startIndex, long endIndex, long step);
57 
58 BASEKIT_API void List_free(List *self);
59 BASEKIT_API void List_removeAll(List *self);
60 BASEKIT_API void List_copy_(List *self, const List *otherList);
61 BASEKIT_API int  List_equals_(const List *self, const List *otherList);
62 BASEKIT_API size_t List_memorySize(const List *self);
63 
64 #include "UArray.h"
65 
66 BASEKIT_API UArray List_asStackAllocatedUArray(List *self);
67 
68 // sizing
69 
70 BASEKIT_API void List_preallocateToSize_(List *self, size_t index);
71 BASEKIT_API void List_setSize_(List *self, size_t index);
72 BASEKIT_API void List_compact(List *self);
73 
74 // utility
75 
76 BASEKIT_API void List_print(const List *self);
77 BASEKIT_API void List_sliceInPlace(List *self, long startIndex, long endIndex, long slice);
78 
79 // enumeration
80 
81 BASEKIT_API void List_do_(List *self, ListDoCallback *callback);
82 BASEKIT_API void List_do_with_(List *self, ListDoWithCallback *callback, void *arg);
83 
84 BASEKIT_API List *List_map_(List *self, ListCollectCallback *callback);
85 BASEKIT_API void List_mapInPlace_(List *self, ListCollectCallback *callback);
86 BASEKIT_API void *List_detect_(List *self, ListDetectCallback *callback);
87 BASEKIT_API List *List_select_(List *self, ListSelectCallback *callback);
88 
89 BASEKIT_API void *List_anyOne(const List *self);
90 BASEKIT_API void List_shuffle(List *self);
91 BASEKIT_API void *List_removeLast(List *self);
92 
93 #include "List_inline.h"
94 
95 #ifdef __cplusplus
96 }
97 #endif
98 #endif
99