diff options
author | Ian Jauslin <ian.jauslin@roma1.infn.it> | 2016-05-20 20:30:15 +0000 |
---|---|---|
committer | Ian Jauslin <ian.jauslin@roma1.infn.it> | 2016-05-20 20:30:15 +0000 |
commit | 2125f01f97abfe343fc5e0cc078bf1d081b2e441 (patch) | |
tree | 932dc60739384224be31f9e894ae63055634435e /src/array_base.h |
Initial commitv1.0
Diffstat (limited to 'src/array_base.h')
-rw-r--r-- | src/array_base.h | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/array_base.h b/src/array_base.h new file mode 100644 index 0000000..b9de5d2 --- /dev/null +++ b/src/array_base.h @@ -0,0 +1,78 @@ +/* +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 + |