Ian Jauslin
summaryrefslogtreecommitdiff
blob: 002ea08e58320481d4bde97b41bdc4a99374e835 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
Copyright 2016 Ian Jauslin

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

/*
  Base functions for arrays

  see polynomial_*.h for the values taken by ARRAY_FUNC, etc...
*/

// init
int ARRAY_FUNC(init) (ARRAY_TYPENAME* array, unsigned int memory);
int ARRAY_FUNC(free) (ARRAY_TYPENAME array);
// do not free values, only free calloc'ed memory
int ARRAY_FUNC(free_vects) (ARRAY_TYPENAME array);

// resize memory
int ARRAY_FUNC(resize) (ARRAY_TYPENAME* array, unsigned int newsize);

// add a value
int ARRAY_FUNC(append) (ARRAY_VAL_TYPE val, ARRAY_TYPENAME* output);
#ifdef ARRAY_VAL_FREE
// do not copy the value, instead let the last element of the array point to 'val'
int ARRAY_FUNC(append_noinit) (ARRAY_VAL_TYPE val, ARRAY_TYPENAME* output);
#endif
// add a value only if it is not already present
#ifdef ARRAY_VAL_IFEQ
int ARRAY_FUNC(append_unique) (ARRAY_VAL_TYPE val, ARRAY_TYPENAME* output);
#endif

// copy
int ARRAY_FUNC(cpy) (ARRAY_TYPENAME input, ARRAY_TYPENAME* output);
int ARRAY_FUNC(cpy_noinit) (ARRAY_TYPENAME input, ARRAY_TYPENAME* output);

// concatenate
int ARRAY_FUNC(concat) (ARRAY_TYPENAME input, ARRAY_TYPENAME* output);
// concat but only add values that are not already present in the array
#ifdef ARRAY_VAL_IFEQ
int ARRAY_FUNC(concat_unique) (ARRAY_TYPENAME input, ARRAY_TYPENAME* output);
#endif

// sub-array
int ARRAY_FUNC(subarray) (ARRAY_TYPENAME array, unsigned int begin, unsigned int end, ARRAY_TYPENAME* subarray);

// find (does not assume the array is sorted)
#ifdef ARRAY_VAL_IFEQ
int ARRAY_FUNC(find) (ARRAY_VAL_TYPE val, ARRAY_TYPENAME array);
#endif

// sort (quicksort)
#ifdef ARRAY_VAL_IFLT
int ARRAY_FUNC(sort) (ARRAY_TYPENAME array);
// sort a sub-array
int ARRAY_FUNC(sort_sub) (ARRAY_TYPENAME array, unsigned int begin, unsigned int end);
#endif

// compare arrays
#if defined ARRAY_VAL_IFLT && defined ARRAY_VAL_IFGT
int ARRAY_FUNC(cmp) (ARRAY_TYPENAME array1, ARRAY_TYPENAME array2);
#endif

// print array
#ifdef ARRAY_VAL_PRINT
int ARRAY_FUNC(print) (ARRAY_TYPENAME array);
#endif

// allocate memory for values until there are at least 'n' alloacted values
#ifdef ARRAY_VAL_INIT
int ARRAY_FUNC(alloc_tmps) (unsigned int n, ARRAY_TYPENAME* array);
#endif