Minor documentation edits.
[zddfun.git] / inta.h
blob3d676d1351cff9eb2859862adc0457d8738a00b2
1 // A linked-list of ints using C arrays
2 // inta = "int array"
4 struct inta_s {
5 int *item;
6 int count;
7 int max;
8 };
10 typedef struct inta_s inta_t[1];
11 typedef struct inta_s *inta_ptr;
13 /*@manual inta
14 Initialize a dynamic array ''a''. Must be called before ''a'' is used.
16 void inta_init(inta_t a);
17 inta_ptr inta_new();
19 /*@manual inta
20 Clears a dynamic array ''a''. Should be called after ''a'' is no longer needed.
22 void inta_clear(inta_t a);
24 /*@manual inta
25 Appends ''p'' to the dynamic array ''a''.
27 void inta_append(inta_t a, int p);
29 /*@manual inta
30 Returns the pointer at index ''i'' in the dynamic array ''a''.
32 static inline int inta_at(inta_t a, int i)
34 return a->item[i];
37 static inline int inta_put(inta_t a, int n, int i) {
38 return a->item[i] = n;
41 int inta_at_test(inta_ptr a, int (*test)(int));
42 int inta_index_of(inta_ptr a, int p);
43 int inta_index_of_test(inta_ptr a, int (*test)(int));
44 void inta_remove(inta_ptr a, int p);
45 int inta_remove_last(inta_ptr a);
46 void inta_remove_test(inta_ptr a, int (*test)(int));
47 void inta_swap(inta_ptr a, int i, int j);
49 /*@manual inta
50 Removes the pointer at index ''i'' in the dynamic array ''a''.
52 void inta_remove_index(inta_ptr a, int n);
53 void inta_copy(inta_ptr dst, inta_ptr src);
54 void inta_remove_all(inta_ptr d);
55 void inta_forall(inta_t a, void (*func)(int));
57 /*@manual inta
58 Returns the number of pointers held in ''a''.
60 static inline int inta_count(const inta_ptr a) { return a->count; }
62 static inline int *inta_raw(const inta_ptr a) { return a->item; }
64 static inline int inta_set_count(inta_ptr a, int n) { return a->count = n; }
66 static inline int inta_is_empty(const inta_ptr a) { return !a->count; }
68 static inline int inta_first(inta_t a) { return a->item[0]; }
70 static inline int inta_last(inta_t a) { return a->item[a->count - 1]; }
72 void inta_qsort(inta_t a, int (*compar)(const void *, const void *));
74 void inta_init_n(inta_t a, int n);