Remove array_ prefix from ARRAY_DEF
See commit on shared pointers.
This commit is contained in:
1 parent
4cb92a92b8
commit
34943e5b2a
14 files changed
+226
-224
No files matched your search
@@ -269,7 +269,7 @@ Another example with a complete type (with proper initialization & clear functio
|
|||||||
#include <gmp.h>
|
#include <gmp.h>
|
||||||
#include "m-array.h"
|
#include "m-array.h"
|
||||||
|
|
||||||
ARRAY_DEF(mpz, mpz_t, (INIT(mpz_init), INIT_SET(mpz_init_set), SET(mpz_set), CLEAR(mpz_clear)) )
|
ARRAY_DEF(array_mpz, mpz_t, (INIT(mpz_init), INIT_SET(mpz_init_set), SET(mpz_set), CLEAR(mpz_clear)) )
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
array_mpz_t array ; /* array_mpz_t has been define above */
|
array_mpz_t array ; /* array_mpz_t has been define above */
|
||||||
@@ -297,7 +297,7 @@ or the equivalent:
|
|||||||
#include <gmp.h>
|
#include <gmp.h>
|
||||||
#include "m-array.h"
|
#include "m-array.h"
|
||||||
|
|
||||||
ARRAY_DEF(mpz, mpz_t, M_CLASSIC_OPLIST(mpz) )
|
ARRAY_DEF(array_mpz, mpz_t, M_CLASSIC_OPLIST(mpz) )
|
||||||
#define ARRAY_OP ARRAY_OPLIST(mpz, M_CLASSIC_OPLIST(mpz))
|
#define ARRAY_OP ARRAY_OPLIST(mpz, M_CLASSIC_OPLIST(mpz))
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
@@ -748,18 +748,18 @@ This method is only defined if the type of the element defines a EQUAL method it
|
|||||||
|
|
||||||
#### ARRAY\_DEF(name, type [, oplist])
|
#### ARRAY\_DEF(name, type [, oplist])
|
||||||
|
|
||||||
Define the array 'array\_##name##\_t' which contains the objects of type 'type' and its associated methods as "static inline" functions.
|
Define the array 'name##\_t' which contains the objects of type 'type' and its associated methods as "static inline" functions.
|
||||||
An array is a collection of element which are individually indexable.
|
An array is a collection of element which are individually indexable.
|
||||||
Compared to C arrays, the created methods handle automatically the size (aka growable array).
|
Compared to C arrays, the created methods handle automatically the size (aka growable array).
|
||||||
'name' shall be a C identifier which will be used to identify the container.
|
'name' shall be a C identifier which will be used to identify the container.
|
||||||
|
|
||||||
It also define the iterator array\_it\_##name##\_t and its associated methods as "static inline" functions.
|
It also define the iterator name##\_it\_t and its associated methods as "static inline" functions.
|
||||||
|
|
||||||
The object oplist is expected to have at least the following operators (INIT, INIT_SET, SET and CLEAR), otherwise default operators are used. If there is no given oplist, the default operators are also used. The created methods will use the operators to init, set and clear the contained object.
|
The object oplist is expected to have at least the following operators (INIT, INIT_SET, SET and CLEAR), otherwise default operators are used. If there is no given oplist, the default operators are also used. The created methods will use the operators to init, set and clear the contained object.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
ARRAY_DEF(mpfr_t, mpfr, \
|
ARRAY_DEF(array_mpfr_t, mpfr, \
|
||||||
(INIT(mpfr_init), INIT_SET(mpfr_init_set), SET(mpfr_set), CLEAR(mpfr_clear)))
|
(INIT(mpfr_init), INIT_SET(mpfr_init_set), SET(mpfr_set), CLEAR(mpfr_clear)))
|
||||||
|
|
||||||
array_mpfr_t my_array;
|
array_mpfr_t my_array;
|
||||||
@@ -779,56 +779,56 @@ Return the oplist of the array defined by calling ARRAY\_DEF with name & oplist.
|
|||||||
In the following methods, name stands for the name given to the macro which is used to identify the type.
|
In the following methods, name stands for the name given to the macro which is used to identify the type.
|
||||||
The following types are automatically defined by the previous macro:
|
The following types are automatically defined by the previous macro:
|
||||||
|
|
||||||
#### array\_name\_t
|
#### name\_t
|
||||||
|
|
||||||
Type of the array of 'type'.
|
Type of the array of 'type'.
|
||||||
|
|
||||||
#### array\_it\_name\_t
|
#### name\_it\_t
|
||||||
|
|
||||||
Type of an iterator over this array.
|
Type of an iterator over this array.
|
||||||
|
|
||||||
The following methods are automatically and properly created by the previous macros:
|
The following methods are automatically and properly created by the previous macros:
|
||||||
|
|
||||||
##### void array\_name\_init(array\_name\_t array)
|
##### void name\_init(name\_t array)
|
||||||
|
|
||||||
Initialize the array 'array' (aka constructor) to an empty array.
|
Initialize the array 'array' (aka constructor) to an empty array.
|
||||||
|
|
||||||
##### void array\_name\_init\_set(array\_name\_t array, const array\_name\_t ref)
|
##### void name\_init\_set(name\_t array, const name\_t ref)
|
||||||
|
|
||||||
Initialize the array 'array' (aka constructor) and set it to the value of 'ref'.
|
Initialize the array 'array' (aka constructor) and set it to the value of 'ref'.
|
||||||
|
|
||||||
##### void array\_name\_set(array\_name\_t array, const array\_name\_t ref)
|
##### void name\_set(name\_t array, const name\_t ref)
|
||||||
|
|
||||||
Set the array 'array' to the value of 'ref'.
|
Set the array 'array' to the value of 'ref'.
|
||||||
|
|
||||||
##### void array\_name\_init\_move(array\_name\_t array, array\_name\_t ref)
|
##### void name\_init\_move(name\_t array, name\_t ref)
|
||||||
|
|
||||||
Initialize the array 'array' (aka constructor) by stealing as many resources from 'ref' as possible.
|
Initialize the array 'array' (aka constructor) by stealing as many resources from 'ref' as possible.
|
||||||
After-wise 'ref' is cleared.
|
After-wise 'ref' is cleared.
|
||||||
|
|
||||||
##### void array\_name\_move(array\_name\_t array, array\_name\_t ref)
|
##### void name\_move(name\_t array, name\_t ref)
|
||||||
|
|
||||||
Set the array 'array' by stealing as many resources from 'ref' as possible.
|
Set the array 'array' by stealing as many resources from 'ref' as possible.
|
||||||
After-wise 'ref' is cleared.
|
After-wise 'ref' is cleared.
|
||||||
|
|
||||||
##### void array\_name\_clear(array\_name\_t array)
|
##### void name\_clear(name\_t array)
|
||||||
|
|
||||||
Clear the array 'array (aka destructor).
|
Clear the array 'array (aka destructor).
|
||||||
|
|
||||||
##### void array\_name\_clean(array\_name\_t array)
|
##### void name\_clean(name\_t array)
|
||||||
|
|
||||||
Clean the array (the array becomes empty but remains initialized).
|
Clean the array (the array becomes empty but remains initialized).
|
||||||
|
|
||||||
##### void array\_name\_push\_back(array\_name\_t array, const type value)
|
##### void name\_push\_back(name\_t array, const type value)
|
||||||
|
|
||||||
Push a new element into the back of the array 'array' with the value 'value' contained within.
|
Push a new element into the back of the array 'array' with the value 'value' contained within.
|
||||||
|
|
||||||
##### type *array\_name\_push\_new(array\_name\_t array)
|
##### type *name\_push\_new(name\_t array)
|
||||||
|
|
||||||
Push a new element into the back of the array 'array' and initialize it with the default constructor.
|
Push a new element into the back of the array 'array' and initialize it with the default constructor.
|
||||||
Return a pointer to this element.
|
Return a pointer to this element.
|
||||||
|
|
||||||
##### type *array\_name\_push\_raw(array\_name\_t array)
|
##### type *name\_push\_raw(name\_t array)
|
||||||
|
|
||||||
Push a new element within the array 'array' without initializing it and return
|
Push a new element within the array 'array' without initializing it and return
|
||||||
a pointer to the non-initialized data.
|
a pointer to the non-initialized data.
|
||||||
@@ -836,147 +836,147 @@ The first thing to do after calling this function is to initialize the data
|
|||||||
using the proper constructor. This allows to use a more specialized
|
using the proper constructor. This allows to use a more specialized
|
||||||
constructor than the generic one.
|
constructor than the generic one.
|
||||||
|
|
||||||
##### void array\_name\_push\_at(array\_name\_t array, size\_t key, const type x)
|
##### void name\_push\_at(name\_t array, size\_t key, const type x)
|
||||||
|
|
||||||
Push a new element into the position 'key' of the array 'array' with the value 'value' contained within.
|
Push a new element into the position 'key' of the array 'array' with the value 'value' contained within.
|
||||||
'key' shall be a valid position of the array: from 0 to the size of array (included).
|
'key' shall be a valid position of the array: from 0 to the size of array (included).
|
||||||
|
|
||||||
##### void array\_name\_pop\_back(type *data, array\_name\_t array)
|
##### void name\_pop\_back(type *data, name\_t array)
|
||||||
|
|
||||||
Pop a element from the back of the array 'array' and set *data to this value.
|
Pop a element from the back of the array 'array' and set *data to this value.
|
||||||
|
|
||||||
##### const type *array\_name\_back(const array\_name\_t array)
|
##### const type *name\_back(const name\_t array)
|
||||||
|
|
||||||
Return a constant pointer to the last element of the array.
|
Return a constant pointer to the last element of the array.
|
||||||
|
|
||||||
##### bool array\_name\_empty\_p(const array\_name\_t array)
|
##### bool name\_empty\_p(const name\_t array)
|
||||||
|
|
||||||
Return true if the array is empty, false otherwise.
|
Return true if the array is empty, false otherwise.
|
||||||
|
|
||||||
##### size\_t array\_name\_size(const array\_name\_t array)
|
##### size\_t name\_size(const name\_t array)
|
||||||
|
|
||||||
Return the size of the array.
|
Return the size of the array.
|
||||||
|
|
||||||
##### size\_t array\_name\_capacity(const array\_name\_t array)
|
##### size\_t name\_capacity(const name\_t array)
|
||||||
|
|
||||||
Return the capacity of the array.
|
Return the capacity of the array.
|
||||||
|
|
||||||
##### void array\_name\_swap(array\_name\_t array1, array\_name\_t array2)
|
##### void name\_swap(name\_t array1, name\_t array2)
|
||||||
|
|
||||||
Swap the array 'array1' and 'array2'.
|
Swap the array 'array1' and 'array2'.
|
||||||
|
|
||||||
##### void array\_name\_set\_at(array\_name\_t array, size\_t i, type value)
|
##### void name\_set\_at(name\_t array, size\_t i, type value)
|
||||||
|
|
||||||
Set the element 'i' of array 'array' to 'value'.
|
Set the element 'i' of array 'array' to 'value'.
|
||||||
'i' shall be within the size of the array.
|
'i' shall be within the size of the array.
|
||||||
|
|
||||||
##### void array\_name\_set\_at2(array\_name\_t array, size\_t i, type value)
|
##### void name\_set\_at2(name\_t array, size\_t i, type value)
|
||||||
|
|
||||||
Set the element 'i' of array 'array' to 'value', increasing the size
|
Set the element 'i' of array 'array' to 'value', increasing the size
|
||||||
of the array if needed.
|
of the array if needed.
|
||||||
|
|
||||||
##### void array\_name\_resize(array\_name\_t array, size\_t size)
|
##### void name\_resize(name\_t array, size\_t size)
|
||||||
|
|
||||||
Resize the array 'array' to the size 'size' (initializing or clearing elements).
|
Resize the array 'array' to the size 'size' (initializing or clearing elements).
|
||||||
|
|
||||||
##### void array\_name\_reserve(array\_name\_t array, size\_t capacity)
|
##### void name\_reserve(name\_t array, size\_t capacity)
|
||||||
|
|
||||||
Extend or reduce the capacity of the 'array' to a rounded value based on 'capacity'.
|
Extend or reduce the capacity of the 'array' to a rounded value based on 'capacity'.
|
||||||
If the given capacity is below the current size of the array, the capacity is set to the size of the array.
|
If the given capacity is below the current size of the array, the capacity is set to the size of the array.
|
||||||
|
|
||||||
##### void array\_name\_pop\_at(type *dest, array\_name\_t array, size\_t key)
|
##### void name\_pop\_at(type *dest, name\_t array, size\_t key)
|
||||||
|
|
||||||
Set *dest to the value the element 'i' if dest is not NULL,
|
Set *dest to the value the element 'i' if dest is not NULL,
|
||||||
Remove this element from the array.
|
Remove this element from the array.
|
||||||
'key' shall be within the size of the array.
|
'key' shall be within the size of the array.
|
||||||
|
|
||||||
##### void array\_name\_remove(array\_name\_t array, array\_it\_name\_t it)
|
##### void name\_remove(name\_t array, name\_it\_t it)
|
||||||
|
|
||||||
Remove the element pointed by the iterator 'it' from the array 'array'.
|
Remove the element pointed by the iterator 'it' from the array 'array'.
|
||||||
'it' shall be within the array. Afterwise 'it' points to the next element, or points to the end.
|
'it' shall be within the array. Afterwise 'it' points to the next element, or points to the end.
|
||||||
|
|
||||||
##### void array\_name\_remove\_v(array\_name\_t array, size\_t i, size\_t j)
|
##### void name\_remove\_v(name\_t array, size\_t i, size\_t j)
|
||||||
|
|
||||||
Remove the element 'i' (included) to the element 'j' (excluded)
|
Remove the element 'i' (included) to the element 'j' (excluded)
|
||||||
from the array.
|
from the array.
|
||||||
'i' and 'j' shall be within the size of the array, and i < j.
|
'i' and 'j' shall be within the size of the array, and i < j.
|
||||||
|
|
||||||
##### void array\_name\_insert(array\_name\_t array, size\_t i, const type x)
|
##### void name\_insert(name\_t array, size\_t i, const type x)
|
||||||
|
|
||||||
Insert the object 'x' at the position 'key' of the array.
|
Insert the object 'x' at the position 'key' of the array.
|
||||||
'key' shall be within the size of the array.
|
'key' shall be within the size of the array.
|
||||||
|
|
||||||
##### void array\_name\_insert\_v(array\_name\_t array, size\_t i, size\_t j)
|
##### void name\_insert\_v(name\_t array, size\_t i, size\_t j)
|
||||||
|
|
||||||
Insert from the element 'i' (included) to the element 'j' (excluded)
|
Insert from the element 'i' (included) to the element 'j' (excluded)
|
||||||
new empty elements to the array.
|
new empty elements to the array.
|
||||||
'i' and 'j' shall be within the size of the array, and i < j.
|
'i' and 'j' shall be within the size of the array, and i < j.
|
||||||
|
|
||||||
##### type *array\_name\_get(array\_name\_t array, size\_t i)
|
##### type *name\_get(name\_t array, size\_t i)
|
||||||
|
|
||||||
Return a pointer to the element 'i' of the array.
|
Return a pointer to the element 'i' of the array.
|
||||||
'i' shall be within the size of the array.
|
'i' shall be within the size of the array.
|
||||||
|
|
||||||
##### const type *array\_name\_cget(const array\_name\_t it, size\_t i)
|
##### const type *name\_cget(const name\_t it, size\_t i)
|
||||||
|
|
||||||
Return a constant pointer to the element 'i' of the array.
|
Return a constant pointer to the element 'i' of the array.
|
||||||
'i' shall be within the size of the array.
|
'i' shall be within the size of the array.
|
||||||
|
|
||||||
##### void array\_name\_it(array\_it\_name\_t it, array\_name\_t array)
|
##### void name\_it(name\_it\_t it, name\_t array)
|
||||||
|
|
||||||
Set the iterator 'it' to the first element of 'array'.
|
Set the iterator 'it' to the first element of 'array'.
|
||||||
|
|
||||||
##### void array\_name\_it\_set(array\_it\_name\_t it1, array\_it\_name\_t it2)
|
##### void name\_it\_set(name\_it\_t it1, name\_it\_t it2)
|
||||||
|
|
||||||
Set the iterator 'it1' to 'it2'.
|
Set the iterator 'it1' to 'it2'.
|
||||||
|
|
||||||
##### bool array\_name\_end\_p(array\_it\_name\_t it)
|
##### bool name\_end\_p(name\_it\_t it)
|
||||||
|
|
||||||
Return true if the iterator doesn't reference a valid element anymore.
|
Return true if the iterator doesn't reference a valid element anymore.
|
||||||
|
|
||||||
##### bool array\_name\_last\_p(array\_it\_name\_t it)
|
##### bool name\_last\_p(name\_it\_t it)
|
||||||
|
|
||||||
Return true if the iterator references the last element of the array, or doesn't reference a valid element.
|
Return true if the iterator references the last element of the array, or doesn't reference a valid element.
|
||||||
|
|
||||||
##### bool array\_name\_it\_equal\_p(const array\_it\_name\_t it1, const array\_it\_name\_t it2)
|
##### bool name\_it\_equal\_p(const name\_it\_t it1, const name\_it\_t it2)
|
||||||
|
|
||||||
Return true if both iterators point to the same element.
|
Return true if both iterators point to the same element.
|
||||||
|
|
||||||
##### void array\_name\_next(array\_it\_name\_t it)
|
##### void name\_next(name\_it\_t it)
|
||||||
|
|
||||||
Move the iterator 'it' to the next element of the array.
|
Move the iterator 'it' to the next element of the array.
|
||||||
|
|
||||||
##### void array\_name\_previous(array\_it\_name\_t it)
|
##### void name\_previous(name\_it\_t it)
|
||||||
|
|
||||||
Move the iterator 'it' to the previous element of the array.
|
Move the iterator 'it' to the previous element of the array.
|
||||||
|
|
||||||
##### type *array\_name\_ref(array\_it\_name\_t it)
|
##### type *name\_ref(name\_it\_t it)
|
||||||
|
|
||||||
Return a pointer to the element pointed by the iterator.
|
Return a pointer to the element pointed by the iterator.
|
||||||
This pointer remains valid until the array is modified by another method.
|
This pointer remains valid until the array is modified by another method.
|
||||||
|
|
||||||
##### const type *array\_name\_cref(const array\_it\_name\_t it)
|
##### const type *name\_cref(const name\_it\_t it)
|
||||||
|
|
||||||
Return a constant pointer to the element pointed by the iterator.
|
Return a constant pointer to the element pointed by the iterator.
|
||||||
This pointer remains valid until the array is modified by another method.
|
This pointer remains valid until the array is modified by another method.
|
||||||
|
|
||||||
##### void array\_name\_get\_str(string\_t str, const array\_name\_t array, bool append)
|
##### void name\_get\_str(string\_t str, const name\_t array, bool append)
|
||||||
|
|
||||||
Generate a string representation of the array 'array' and set 'str' to this representation
|
Generate a string representation of the array 'array' and set 'str' to this representation
|
||||||
(if 'append' is false) or append 'str' with this representation (if 'append' is true).
|
(if 'append' is false) or append 'str' with this representation (if 'append' is true).
|
||||||
This method is only defined if the type of the element defines a GET\_STR method itself.
|
This method is only defined if the type of the element defines a GET\_STR method itself.
|
||||||
|
|
||||||
##### void array\_name\_out\_str(FILE *file, const array\_name\_t array)
|
##### void name\_out\_str(FILE *file, const name\_t array)
|
||||||
|
|
||||||
Generate a string representation of the array 'array' and outputs it into the FILE 'file'.
|
Generate a string representation of the array 'array' and outputs it into the FILE 'file'.
|
||||||
This method is only defined if the type of the element defines a OUT\_STR method itself.
|
This method is only defined if the type of the element defines a OUT\_STR method itself.
|
||||||
|
|
||||||
##### void array\_name\_in\_str(FILE *file, const array\_name\_t array)
|
##### void name\_in\_str(FILE *file, const name\_t array)
|
||||||
|
|
||||||
Read from the file 'file' a string representation of a array and set 'array' to this representation.
|
Read from the file 'file' a string representation of a array and set 'array' to this representation.
|
||||||
This method is only defined if the type of the element defines a IN\_STR method itself.
|
This method is only defined if the type of the element defines a IN\_STR method itself.
|
||||||
|
|
||||||
##### bool array\_name\_equal\_p(const array\_name\_t array1, const array\_name\_t array2)
|
##### bool name\_equal\_p(const name\_t array1, const name\_t array2)
|
||||||
|
|
||||||
Return true if both arrays 'array1' and 'array2' are equal.
|
Return true if both arrays 'array1' and 'array2' are equal.
|
||||||
This method is only defined if the type of the element defines a EQUAL method itself.
|
This method is only defined if the type of the element defines a EQUAL method itself.
|
||||||
|
|||||||
+5
-5
@@ -18,11 +18,11 @@
|
|||||||
|
|
||||||
/********************************************************************************************/
|
/********************************************************************************************/
|
||||||
|
|
||||||
ARRAY_DEF(uint, unsigned int)
|
ARRAY_DEF(array_uint, unsigned int)
|
||||||
|
|
||||||
static void test_array(size_t n)
|
static void test_array(size_t n)
|
||||||
{
|
{
|
||||||
M_LET(a1, a2, ARRAY_OPLIST(uint)) {
|
M_LET(a1, a2, ARRAY_OPLIST(array_uint)) {
|
||||||
for(size_t i = 0; i < n; i++) {
|
for(size_t i = 0; i < n; i++) {
|
||||||
array_uint_push_back(a1, rand_get() );
|
array_uint_push_back(a1, rand_get() );
|
||||||
array_uint_push_back(a2, rand_get() );
|
array_uint_push_back(a2, rand_get() );
|
||||||
@@ -247,12 +247,12 @@ test_dict_str(unsigned long n)
|
|||||||
|
|
||||||
/********************************************************************************************/
|
/********************************************************************************************/
|
||||||
|
|
||||||
ARRAY_DEF(float, float)
|
ARRAY_DEF(array_float, float)
|
||||||
ALGO_DEF(afloat, ARRAY_OPLIST(float))
|
ALGO_DEF(afloat, ARRAY_OPLIST(array_float))
|
||||||
|
|
||||||
static void test_sort(size_t n)
|
static void test_sort(size_t n)
|
||||||
{
|
{
|
||||||
M_LET(a1, ARRAY_OPLIST(float)) {
|
M_LET(a1, ARRAY_OPLIST(array_float)) {
|
||||||
for(size_t i = 0; i < n; i++) {
|
for(size_t i = 0; i < n; i++) {
|
||||||
array_float_push_back(a1, rand_get() );
|
array_float_push_back(a1, rand_get() );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "m-array.h"
|
#include "m-array.h"
|
||||||
|
|
||||||
// Let's define an array of 'char *' named 'charp'
|
// Let's define an array of 'char *' named 'charp'
|
||||||
ARRAY_DEF (charp, char *)
|
ARRAY_DEF (array_charp, char *)
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
@@ -20,7 +20,7 @@ int main(void)
|
|||||||
|
|
||||||
// Use iterator to display contents of al
|
// Use iterator to display contents of al
|
||||||
printf("Original contents of al: ");
|
printf("Original contents of al: ");
|
||||||
array_it_charp_t itr;
|
array_charp_it_t itr;
|
||||||
for (array_charp_it(itr, al) ; !array_charp_end_p (itr); array_charp_next(itr)) {
|
for (array_charp_it(itr, al) ; !array_charp_end_p (itr); array_charp_next(itr)) {
|
||||||
char *element = *array_charp_ref(itr);
|
char *element = *array_charp_ref(itr);
|
||||||
printf ("%s ", element);
|
printf ("%s ", element);
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
#include "m-array.h"
|
#include "m-array.h"
|
||||||
|
|
||||||
// Let's define an array of 'char *' named 'charp'
|
// Let's define an array of 'char *' named 'charp'
|
||||||
ARRAY_DEF (charp, char *)
|
ARRAY_DEF (array_charp, char *)
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
// Create an array list 'al'
|
// Create an array list 'al'
|
||||||
M_LET (al, ARRAY_OPLIST(charp)) {
|
M_LET (al, ARRAY_OPLIST(array_charp)) {
|
||||||
// add elements to the array list
|
// add elements to the array list
|
||||||
array_charp_push_back (al,"C");
|
array_charp_push_back (al,"C");
|
||||||
array_charp_push_back (al,"A");
|
array_charp_push_back (al,"A");
|
||||||
@@ -18,7 +18,7 @@ int main(void)
|
|||||||
// Display contents of al
|
// Display contents of al
|
||||||
printf("Original contents of al: ");
|
printf("Original contents of al: ");
|
||||||
// For each element of the array al
|
// For each element of the array al
|
||||||
for M_EACH(element, al, ARRAY_OPLIST(charp)) {
|
for M_EACH(element, al, ARRAY_OPLIST(array_charp)) {
|
||||||
printf ("%s ", *element);
|
printf ("%s ", *element);
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#include "m-array.h"
|
#include "m-array.h"
|
||||||
|
|
||||||
// Let's define an array of 'int' named 'int'
|
// Let's define an array of 'int' named 'int'
|
||||||
ARRAY_DEF(int, int)
|
ARRAY_DEF(array_int, int)
|
||||||
|
|
||||||
const int n = 100000;
|
const int n = 100000;
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
#include "m-array.h"
|
#include "m-array.h"
|
||||||
#include "m-algo.h"
|
#include "m-algo.h"
|
||||||
|
|
||||||
ARRAY_DEF(mpz, mpz_t, M_CLASSIC_OPLIST(mpz))
|
ARRAY_DEF(array_mpz, mpz_t, M_CLASSIC_OPLIST(mpz))
|
||||||
ALGO_DEF(array_mpz, ARRAY_OPLIST(mpz, M_CLASSIC_OPLIST(mpz)))
|
ALGO_DEF(array_mpz, ARRAY_OPLIST(array_mpz, M_CLASSIC_OPLIST(mpz)))
|
||||||
|
|
||||||
static inline void my_mpz_inc(mpz_t *d, const mpz_t a){
|
static inline void my_mpz_inc(mpz_t *d, const mpz_t a){
|
||||||
mpz_add(*d, *d, a);
|
mpz_add(*d, *d, a);
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include "m-array.h"
|
#include "m-array.h"
|
||||||
#include "m-string.h"
|
#include "m-string.h"
|
||||||
|
|
||||||
ARRAY_DEF(int, int)
|
ARRAY_DEF(array_int, int)
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int pos;
|
int pos;
|
||||||
|
|||||||
@@ -23,9 +23,9 @@ DICT_DEF2(my,
|
|||||||
#define MY_DICT_OPLIST DICT_OPLIST(my, STRING_OPLIST, INTEGER_OPLIST)
|
#define MY_DICT_OPLIST DICT_OPLIST(my, STRING_OPLIST, INTEGER_OPLIST)
|
||||||
|
|
||||||
/* Define an array of such dictionary named array_my_t */
|
/* Define an array of such dictionary named array_my_t */
|
||||||
ARRAY_DEF(my, dict_my_t, MY_DICT_OPLIST)
|
ARRAY_DEF(array_my, dict_my_t, MY_DICT_OPLIST)
|
||||||
/* Define the oplist associated to this array of dictionary of variant */
|
/* Define the oplist associated to this array of dictionary of variant */
|
||||||
#define MY_ARRAY_OPLIST ARRAY_OPLIST(my, MY_DICT_OPLIST)
|
#define MY_ARRAY_OPLIST ARRAY_OPLIST(array_my, MY_DICT_OPLIST)
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -78,12 +78,12 @@ extern bool json_in_str(json_t *, FILE *);
|
|||||||
|
|
||||||
DICT_DEF2(json, string_t, STRING_OPLIST, json_t, JSON_OPLIST)
|
DICT_DEF2(json, string_t, STRING_OPLIST, json_t, JSON_OPLIST)
|
||||||
|
|
||||||
ARRAY_DEF(json, json_t, JSON_OPLIST)
|
ARRAY_DEF(array_json, json_t, JSON_OPLIST)
|
||||||
|
|
||||||
VARIANT_DEF2(variant_json,
|
VARIANT_DEF2(variant_json,
|
||||||
(boolean, bool, M_OPEXTEND(M_DEFAULT_OPLIST, OUT_STR(boolean_out_str), IN_STR(boolean_in_str M_IPTR)) ),
|
(boolean, bool, M_OPEXTEND(M_DEFAULT_OPLIST, OUT_STR(boolean_out_str), IN_STR(boolean_in_str M_IPTR)) ),
|
||||||
(real, float, M_OPEXTEND (M_DEFAULT_OPLIST, OUT_STR(real_out_str), IN_STR(real_in_str M_IPTR))),
|
(real, float, M_OPEXTEND (M_DEFAULT_OPLIST, OUT_STR(real_out_str), IN_STR(real_in_str M_IPTR))),
|
||||||
(array, array_json_t, ARRAY_OPLIST(json, JSON_OPLIST)),
|
(array, array_json_t, ARRAY_OPLIST(array_json, JSON_OPLIST)),
|
||||||
(dict, dict_json_t, DICT_OPLIST(json, STRING_OPLIST, JSON_OPLIST)))
|
(dict, dict_json_t, DICT_OPLIST(json, STRING_OPLIST, JSON_OPLIST)))
|
||||||
|
|
||||||
struct json_node_s {
|
struct json_node_s {
|
||||||
|
|||||||
@@ -36,8 +36,8 @@
|
|||||||
USAGE: ARRAY_DEF(name, type [, oplist_of_the_type]) */
|
USAGE: ARRAY_DEF(name, type [, oplist_of_the_type]) */
|
||||||
#define ARRAY_DEF(name, ...) \
|
#define ARRAY_DEF(name, ...) \
|
||||||
M_IF_NARGS_EQ1(__VA_ARGS__) \
|
M_IF_NARGS_EQ1(__VA_ARGS__) \
|
||||||
(ARRAYI_DEF2(name, __VA_ARGS__, M_DEFAULT_OPLIST, M_C3(array_, name,_t), M_C3(array_it_,name,_t) ), \
|
(ARRAYI_DEF2(name, __VA_ARGS__, M_DEFAULT_OPLIST, M_C(name,_t), M_C(name,_it_t) ), \
|
||||||
ARRAYI_DEF2(name, __VA_ARGS__, M_C3(array_, name,_t), M_C3(array_it_,name,_t)))
|
ARRAYI_DEF2(name, __VA_ARGS__, M_C(name,_t), M_C(name,_it_t)))
|
||||||
|
|
||||||
/* Define the oplist of an array of type.
|
/* Define the oplist of an array of type.
|
||||||
USAGE: ARRAY_OPLIST(name[, oplist of the type]) */
|
USAGE: ARRAY_OPLIST(name[, oplist of the type]) */
|
||||||
@@ -49,39 +49,39 @@
|
|||||||
|
|
||||||
/********************************** INTERNAL ************************************/
|
/********************************** INTERNAL ************************************/
|
||||||
|
|
||||||
#define ARRAYI_OPLIST(name, oplist) \
|
#define ARRAYI_OPLIST(name, oplist) \
|
||||||
(INIT(M_C3(array_, name, _init)) \
|
(INIT(M_C(name, _init)) \
|
||||||
,INIT_SET(M_C3(array_, name, _init_set)) \
|
,INIT_SET(M_C(name, _init_set)) \
|
||||||
,SET(M_C3(array_, name, _set)) \
|
,SET(M_C(name, _set)) \
|
||||||
,CLEAR(M_C3(array_, name, _clear)) \
|
,CLEAR(M_C(name, _clear)) \
|
||||||
,INIT_MOVE(M_C3(array_, name, _init_move)) \
|
,INIT_MOVE(M_C(name, _init_move)) \
|
||||||
,MOVE(M_C3(array_, name, _move)) \
|
,MOVE(M_C(name, _move)) \
|
||||||
,SWAP(M_C3(array_, name, _swap)) \
|
,SWAP(M_C(name, _swap)) \
|
||||||
,TYPE(M_C3(array_,name,_t)) \
|
,TYPE(M_C(name,_t)) \
|
||||||
,SUBTYPE(M_C3(array_type_,name,_t)) \
|
,SUBTYPE(M_C(name, _type_t)) \
|
||||||
,IT_TYPE(M_C3(array_it_,name,_t)) \
|
,IT_TYPE(M_C(name,_it_t)) \
|
||||||
,IT_FIRST(M_C3(array_,name,_it)) \
|
,IT_FIRST(M_C(name,_it)) \
|
||||||
,IT_LAST(M_C3(array_,name,_it_last)) \
|
,IT_LAST(M_C(name,_it_last)) \
|
||||||
,IT_END(M_C3(array_,name,_it_end)) \
|
,IT_END(M_C(name,_it_end)) \
|
||||||
,IT_SET(M_C3(array_,name,_it_set)) \
|
,IT_SET(M_C(name,_it_set)) \
|
||||||
,IT_END_P(M_C3(array_,name,_end_p)) \
|
,IT_END_P(M_C(name,_end_p)) \
|
||||||
,IT_LAST_P(M_C3(array_,name,_last_p)) \
|
,IT_LAST_P(M_C(name,_last_p)) \
|
||||||
,IT_EQUAL_P(M_C3(array_,name,_it_equal_p)) \
|
,IT_EQUAL_P(M_C(name,_it_equal_p)) \
|
||||||
,IT_NEXT(M_C3(array_,name,_next)) \
|
,IT_NEXT(M_C(name,_next)) \
|
||||||
,IT_PREVIOUS(M_C3(array_,name,_previous)) \
|
,IT_PREVIOUS(M_C(name,_previous)) \
|
||||||
,IT_REF(M_C3(array_,name,_ref)) \
|
,IT_REF(M_C(name,_ref)) \
|
||||||
,IT_CREF(M_C3(array_,name,_cref)) \
|
,IT_CREF(M_C(name,_cref)) \
|
||||||
,IT_REMOVE(M_C3(array_,name,_remove)) \
|
,IT_REMOVE(M_C(name,_remove)) \
|
||||||
,CLEAN(M_C3(array_,name,_clean)) \
|
,CLEAN(M_C(name,_clean)) \
|
||||||
,PUSH(M_C3(array_,name,_push_back)) \
|
,PUSH(M_C(name,_push_back)) \
|
||||||
,POP(M_C3(array_,name,_pop_back)) \
|
,POP(M_C(name,_pop_back)) \
|
||||||
,OPLIST(oplist) \
|
,OPLIST(oplist) \
|
||||||
,M_IF_METHOD(CMP, oplist)(SORT(M_C3(array_, name, _sort)),) \
|
,M_IF_METHOD(CMP, oplist)(SORT(M_C(name, _sort)),) \
|
||||||
,M_IF_METHOD(GET_STR, oplist)(GET_STR(M_C3(array_, name, _get_str)),) \
|
,M_IF_METHOD(GET_STR, oplist)(GET_STR(M_C(name, _get_str)),) \
|
||||||
,M_IF_METHOD(OUT_STR, oplist)(OUT_STR(M_C3(array_, name, _out_str)),) \
|
,M_IF_METHOD(OUT_STR, oplist)(OUT_STR(M_C(name, _out_str)),) \
|
||||||
,M_IF_METHOD(IN_STR, oplist)(IN_STR(M_C3(array_, name, _in_str)),) \
|
,M_IF_METHOD(IN_STR, oplist)(IN_STR(M_C(name, _in_str)),) \
|
||||||
,M_IF_METHOD(EQUAL, oplist)(EQUAL(M_C3(array_, type, _equal_p)),) \
|
,M_IF_METHOD(EQUAL, oplist)(EQUAL(M_C(name, _equal_p)),) \
|
||||||
,M_IF_METHOD(HASH, oplist)(HASH(M_C3(array_, type, _hash)),) \
|
,M_IF_METHOD(HASH, oplist)(HASH(M_C(name, _hash)),) \
|
||||||
,M_IF_METHOD(NEW, oplist)(NEW(M_GET_NEW oplist),) \
|
,M_IF_METHOD(NEW, oplist)(NEW(M_GET_NEW oplist),) \
|
||||||
,M_IF_METHOD(REALLOC, oplist)(REALLOC(M_GET_REALLOC oplist),) \
|
,M_IF_METHOD(REALLOC, oplist)(REALLOC(M_GET_REALLOC oplist),) \
|
||||||
,M_IF_METHOD(DEL, oplist)(DEL(M_GET_DEL oplist),) \
|
,M_IF_METHOD(DEL, oplist)(DEL(M_GET_DEL oplist),) \
|
||||||
@@ -95,34 +95,36 @@
|
|||||||
|
|
||||||
// Compute alloc from the requested size.
|
// Compute alloc from the requested size.
|
||||||
// NOTE: EXPECTED_SIZE can be overloaded by the given oplist.
|
// NOTE: EXPECTED_SIZE can be overloaded by the given oplist.
|
||||||
|
// TODO: Factor 2 shall be configurable.
|
||||||
#define ARRAYI_INC_ALLOC_SIZE(oplist, n) \
|
#define ARRAYI_INC_ALLOC_SIZE(oplist, n) \
|
||||||
(M_MAX(M_GET_EXPECTED_SIZE oplist, (n))*2)
|
(M_MAX(M_GET_EXPECTED_SIZE oplist, (n))*2)
|
||||||
|
|
||||||
// Internal definition.
|
// Internal definition.
|
||||||
#define ARRAYI_DEF2(name, type, oplist, array_t, array_it_t) \
|
#define ARRAYI_DEF2(name, type, oplist, array_t, array_it_t) \
|
||||||
typedef struct M_C3(array_, name, _s) { \
|
\
|
||||||
|
typedef struct M_C(name, _s) { \
|
||||||
size_t size, alloc; \
|
size_t size, alloc; \
|
||||||
type *ptr; \
|
type *ptr; \
|
||||||
} array_t[1]; \
|
} array_t[1]; \
|
||||||
\
|
\
|
||||||
typedef type M_C3(array_type_,name,_t); \
|
typedef type M_C(name, _type_t); \
|
||||||
\
|
\
|
||||||
typedef struct M_C3(array_it_,name,_s) { \
|
typedef struct M_C(name, _it_s) { \
|
||||||
size_t index; \
|
size_t index; \
|
||||||
const struct M_C3(array_, name, _s) *array; \
|
const struct M_C(name, _s) *array; \
|
||||||
} array_it_t[1]; \
|
} array_it_t[1]; \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
M_C3(array_, name, _init)(array_t v) \
|
M_C(name, _init)(array_t v) \
|
||||||
{ \
|
{ \
|
||||||
assert (v != NULL); \
|
assert (v != NULL); \
|
||||||
v->size = v->alloc = 0; \
|
v->size = v->alloc = 0; \
|
||||||
v->ptr = NULL; \
|
v->ptr = NULL; \
|
||||||
ARRAYI_CONTRACT(v); \
|
ARRAYI_CONTRACT(v); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
M_C3(array_, name, _clean)(array_t v) \
|
M_C(name, _clean)(array_t v) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(v); \
|
ARRAYI_CONTRACT(v); \
|
||||||
for(size_t i = 0; i < v->size; i++) \
|
for(size_t i = 0; i < v->size; i++) \
|
||||||
@@ -130,19 +132,19 @@
|
|||||||
v->size = 0; \
|
v->size = 0; \
|
||||||
ARRAYI_CONTRACT(v); \
|
ARRAYI_CONTRACT(v); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
M_C3(array_, name, _clear)(array_t v) \
|
M_C(name, _clear)(array_t v) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(v); \
|
ARRAYI_CONTRACT(v); \
|
||||||
M_C3(array_, name, _clean)(v); \
|
M_C(name, _clean)(v); \
|
||||||
M_GET_FREE oplist(v->ptr); \
|
M_GET_FREE oplist(v->ptr); \
|
||||||
v->alloc = 0; \
|
v->alloc = 0; \
|
||||||
v->ptr = NULL; \
|
v->ptr = NULL; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
M_C3(array_, name, _set)(array_t d, const array_t s) \
|
M_C(name, _set)(array_t d, const array_t s) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(d); \
|
ARRAYI_CONTRACT(d); \
|
||||||
ARRAYI_CONTRACT(s); \
|
ARRAYI_CONTRACT(s); \
|
||||||
@@ -167,17 +169,17 @@
|
|||||||
d->size = s->size; \
|
d->size = s->size; \
|
||||||
ARRAYI_CONTRACT(d); \
|
ARRAYI_CONTRACT(d); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
M_C3(array_, name, _init_set)(array_t d, const array_t s) \
|
M_C(name, _init_set)(array_t d, const array_t s) \
|
||||||
{ \
|
{ \
|
||||||
assert (d != s); \
|
assert (d != s); \
|
||||||
M_C3(array_, name, _init)(d); \
|
M_C(name, _init)(d); \
|
||||||
M_C3(array_, name, _set)(d, s); \
|
M_C(name, _set)(d, s); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
M_C3(array_, name, _init_move)(array_t d, array_t s) \
|
M_C(name, _init_move)(array_t d, array_t s) \
|
||||||
{ \
|
{ \
|
||||||
assert (d != s); \
|
assert (d != s); \
|
||||||
ARRAYI_CONTRACT(s); \
|
ARRAYI_CONTRACT(s); \
|
||||||
@@ -188,17 +190,17 @@
|
|||||||
s->ptr = NULL; \
|
s->ptr = NULL; \
|
||||||
ARRAYI_CONTRACT(d); \
|
ARRAYI_CONTRACT(d); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
M_C3(array_, name, _move)(array_t d, array_t s) \
|
M_C(name, _move)(array_t d, array_t s) \
|
||||||
{ \
|
{ \
|
||||||
assert (d != s); \
|
assert (d != s); \
|
||||||
M_C3(array_, name, _clear)(d); \
|
M_C(name, _clear)(d); \
|
||||||
M_C3(array_, name, _init_move)(d, s); \
|
M_C(name, _init_move)(d, s); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
M_C3(array_, name, _set_at)(array_t v, size_t i, type x) \
|
M_C(name, _set_at)(array_t v, size_t i, type x) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(v); \
|
ARRAYI_CONTRACT(v); \
|
||||||
assert(v->size > 0 && v->ptr != NULL && i < v->size); \
|
assert(v->size > 0 && v->ptr != NULL && i < v->size); \
|
||||||
@@ -206,15 +208,15 @@
|
|||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline const type * \
|
static inline const type * \
|
||||||
M_C3(array_, name, _back)(array_t v) \
|
M_C(name, _back)(array_t v) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(v); \
|
ARRAYI_CONTRACT(v); \
|
||||||
assert(v->size > 0 && v->ptr != NULL); \
|
assert(v->size > 0 && v->ptr != NULL); \
|
||||||
return M_CONST_CAST(type, &v->ptr[v->size-1]); \
|
return M_CONST_CAST(type, &v->ptr[v->size-1]); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline type * \
|
static inline type * \
|
||||||
M_C3(array_, name, _push_raw)(array_t v) \
|
M_C(name, _push_raw)(array_t v) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(v); \
|
ARRAYI_CONTRACT(v); \
|
||||||
if (M_UNLIKELY (v->size >= v->alloc)) { \
|
if (M_UNLIKELY (v->size >= v->alloc)) { \
|
||||||
@@ -237,26 +239,26 @@
|
|||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
M_C3(array_, name, _push_back)(array_t v, type const x) \
|
M_C(name, _push_back)(array_t v, type const x) \
|
||||||
{ \
|
{ \
|
||||||
type *data = M_C3(array_, name, _push_raw)(v); \
|
type *data = M_C(name, _push_raw)(v); \
|
||||||
if (M_UNLIKELY (data == NULL) ) \
|
if (M_UNLIKELY (data == NULL) ) \
|
||||||
return; \
|
return; \
|
||||||
M_GET_INIT_SET oplist(*data, x); \
|
M_GET_INIT_SET oplist(*data, x); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline type * \
|
static inline type * \
|
||||||
M_C3(array_, name, _push_new)(array_t v) \
|
M_C(name, _push_new)(array_t v) \
|
||||||
{ \
|
{ \
|
||||||
type *data = M_C3(array_, name, _push_raw)(v); \
|
type *data = M_C(name, _push_raw)(v); \
|
||||||
if (M_UNLIKELY (data == NULL) ) \
|
if (M_UNLIKELY (data == NULL) ) \
|
||||||
return NULL; \
|
return NULL; \
|
||||||
M_GET_INIT oplist(*data); \
|
M_GET_INIT oplist(*data); \
|
||||||
return data; \
|
return data; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
M_C3(array_, name, _push_at)(array_t v, size_t key, type const x) \
|
M_C(name, _push_at)(array_t v, size_t key, type const x) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(v); \
|
ARRAYI_CONTRACT(v); \
|
||||||
assert (key <= v->size); \
|
assert (key <= v->size); \
|
||||||
@@ -280,7 +282,7 @@
|
|||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
M_C3(array_, name, _resize)(array_t v, size_t size) \
|
M_C(name, _resize)(array_t v, size_t size) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(v); \
|
ARRAYI_CONTRACT(v); \
|
||||||
if (v->size > size) { \
|
if (v->size > size) { \
|
||||||
@@ -308,7 +310,7 @@
|
|||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
M_C3(array_, name, _reserve)(array_t v, size_t alloc) \
|
M_C(name, _reserve)(array_t v, size_t alloc) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(v); \
|
ARRAYI_CONTRACT(v); \
|
||||||
/* NOTE: Reserve below needed size, perform a shrink to fit */ \
|
/* NOTE: Reserve below needed size, perform a shrink to fit */ \
|
||||||
@@ -332,7 +334,7 @@
|
|||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
M_C3(array_, name, _set_at2)(array_t v, size_t idx, type x) \
|
M_C(name, _set_at2)(array_t v, size_t idx, type x) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(v); \
|
ARRAYI_CONTRACT(v); \
|
||||||
const size_t size = idx + 1; \
|
const size_t size = idx + 1; \
|
||||||
@@ -359,7 +361,7 @@
|
|||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
M_C3(array_, name, _pop_back)(type *dest, array_t v) \
|
M_C(name, _pop_back)(type *dest, array_t v) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(v); \
|
ARRAYI_CONTRACT(v); \
|
||||||
v->size--; \
|
v->size--; \
|
||||||
@@ -374,28 +376,28 @@
|
|||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline bool \
|
static inline bool \
|
||||||
M_C3(array_, name, _empty_p)(const array_t v) \
|
M_C(name, _empty_p)(const array_t v) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(v); \
|
ARRAYI_CONTRACT(v); \
|
||||||
return v->size == 0; \
|
return v->size == 0; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline size_t \
|
static inline size_t \
|
||||||
M_C3(array_, name, _size)(const array_t v) \
|
M_C(name, _size)(const array_t v) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(v); \
|
ARRAYI_CONTRACT(v); \
|
||||||
return v->size; \
|
return v->size; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline size_t \
|
static inline size_t \
|
||||||
M_C3(array_, name, _capacity)(const array_t v) \
|
M_C(name, _capacity)(const array_t v) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(v); \
|
ARRAYI_CONTRACT(v); \
|
||||||
return v->alloc; \
|
return v->alloc; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
M_C3(array_, name, _pop_at)(type *dest, array_t v, size_t i) \
|
M_C(name, _pop_at)(type *dest, array_t v, size_t i) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(v); \
|
ARRAYI_CONTRACT(v); \
|
||||||
assert (v->size > 0 && v->ptr != NULL); \
|
assert (v->size > 0 && v->ptr != NULL); \
|
||||||
@@ -412,7 +414,7 @@
|
|||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
M_C3(array_, name, _insert_v)(array_t v, size_t i, size_t num) \
|
M_C(name, _insert_v)(array_t v, size_t i, size_t num) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(v); \
|
ARRAYI_CONTRACT(v); \
|
||||||
assert(i <= v->size); \
|
assert(i <= v->size); \
|
||||||
@@ -435,7 +437,7 @@
|
|||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
M_C3(array_, name, _remove_v)(array_t v, size_t i, size_t j) \
|
M_C(name, _remove_v)(array_t v, size_t i, size_t j) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(v); \
|
ARRAYI_CONTRACT(v); \
|
||||||
assert(i < v->size && j <= v->size && i < j && v->ptr != NULL); \
|
assert(i < v->size && j <= v->size && i < j && v->ptr != NULL); \
|
||||||
@@ -447,7 +449,7 @@
|
|||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
M_C3(array_, name, _swap)(array_t v1, array_t v2) \
|
M_C(name, _swap)(array_t v1, array_t v2) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(v1); \
|
ARRAYI_CONTRACT(v1); \
|
||||||
ARRAYI_CONTRACT(v2); \
|
ARRAYI_CONTRACT(v2); \
|
||||||
@@ -465,7 +467,7 @@
|
|||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
M_C3(array_, name, _swap_at)(array_t v, size_t i, size_t j) \
|
M_C(name, _swap_at)(array_t v, size_t i, size_t j) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(v); \
|
ARRAYI_CONTRACT(v); \
|
||||||
assert(i < v->size && j < v->size && v->ptr != NULL); \
|
assert(i < v->size && j < v->size && v->ptr != NULL); \
|
||||||
@@ -484,7 +486,7 @@
|
|||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline type * \
|
static inline type * \
|
||||||
M_C3(array_, name, _get)(const array_t v, size_t i) \
|
M_C(name, _get)(const array_t v, size_t i) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(v); \
|
ARRAYI_CONTRACT(v); \
|
||||||
assert (i < v->size && v->ptr != NULL); \
|
assert (i < v->size && v->ptr != NULL); \
|
||||||
@@ -492,7 +494,7 @@
|
|||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline const type * \
|
static inline const type * \
|
||||||
M_C3(array_, name, _cget)(const array_t v, size_t i) \
|
M_C(name, _cget)(const array_t v, size_t i) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(v); \
|
ARRAYI_CONTRACT(v); \
|
||||||
assert (i < v->size && v->ptr != NULL); \
|
assert (i < v->size && v->ptr != NULL); \
|
||||||
@@ -500,7 +502,7 @@
|
|||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
M_C3(array_, name, _it)(array_it_t it, const array_t v) \
|
M_C(name, _it)(array_it_t it, const array_t v) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(v); \
|
ARRAYI_CONTRACT(v); \
|
||||||
assert (it != NULL); \
|
assert (it != NULL); \
|
||||||
@@ -509,7 +511,7 @@
|
|||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
M_C3(array_, name, _it_last)(array_it_t it, const array_t v) \
|
M_C(name, _it_last)(array_it_t it, const array_t v) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(v); \
|
ARRAYI_CONTRACT(v); \
|
||||||
assert (it != NULL); \
|
assert (it != NULL); \
|
||||||
@@ -518,7 +520,7 @@
|
|||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
M_C3(array_, name, _it_end)(array_it_t it, const array_t v) \
|
M_C(name, _it_end)(array_it_t it, const array_t v) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(v); \
|
ARRAYI_CONTRACT(v); \
|
||||||
assert (it != NULL); \
|
assert (it != NULL); \
|
||||||
@@ -527,7 +529,7 @@
|
|||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
M_C3(array_, name, _it_set)(array_it_t it, const array_it_t org) \
|
M_C(name, _it_set)(array_it_t it, const array_it_t org) \
|
||||||
{ \
|
{ \
|
||||||
assert (it != NULL && org != NULL); \
|
assert (it != NULL && org != NULL); \
|
||||||
it->index = org->index; \
|
it->index = org->index; \
|
||||||
@@ -535,78 +537,78 @@
|
|||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline bool \
|
static inline bool \
|
||||||
M_C3(array_, name, _end_p)(const array_it_t it) \
|
M_C(name, _end_p)(const array_it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert(it != NULL && it->array != NULL); \
|
assert(it != NULL && it->array != NULL); \
|
||||||
return (it->index) >= it->array->size; \
|
return (it->index) >= it->array->size; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline bool \
|
static inline bool \
|
||||||
M_C3(array_, name, _last_p)(const array_it_t it) \
|
M_C(name, _last_p)(const array_it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert(it != NULL && it->array != NULL); \
|
assert(it != NULL && it->array != NULL); \
|
||||||
/* NOTE: Can not compute 'size-1' due to potential overflow \
|
/* NOTE: Can not compute 'size-1' due to potential overflow \
|
||||||
if size was 0 */ \
|
if size was 0 */ \
|
||||||
return it->index + 1 >= it->array->size; \
|
return it->index + 1 >= it->array->size; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline bool \
|
static inline bool \
|
||||||
M_C3(array_, name, _it_equal_p)(const array_it_t it1, \
|
M_C(name, _it_equal_p)(const array_it_t it1, \
|
||||||
const array_it_t it2) \
|
const array_it_t it2) \
|
||||||
{ \
|
{ \
|
||||||
assert(it1 != NULL && it2 != NULL); \
|
assert(it1 != NULL && it2 != NULL); \
|
||||||
return it1->array == it2->array && it1->index == it2->index; \
|
return it1->array == it2->array && it1->index == it2->index; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
M_C3(array_, name, _next)(array_it_t it) \
|
M_C(name, _next)(array_it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert(it != NULL && it->array != NULL); \
|
assert(it != NULL && it->array != NULL); \
|
||||||
it->index ++; \
|
it->index ++; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
M_C3(array_, name, _previous)(array_it_t it) \
|
M_C(name, _previous)(array_it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert(it != NULL && it->array != NULL); \
|
assert(it != NULL && it->array != NULL); \
|
||||||
/* NOTE: In the case index=0, it will be set to (unsigned) -1 \
|
/* NOTE: In the case index=0, it will be set to (unsigned) -1 \
|
||||||
==> it will be greater than size ==> end_p will return true */ \
|
==> it will be greater than size ==> end_p will return true */ \
|
||||||
it->index --; \
|
it->index --; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline type * \
|
static inline type * \
|
||||||
M_C3(array_, name, _ref)(const array_it_t it) \
|
M_C(name, _ref)(const array_it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert(it != NULL); \
|
assert(it != NULL); \
|
||||||
return M_C3(array_, name, _get)(it->array, it->index); \
|
return M_C(name, _get)(it->array, it->index); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline const type * \
|
static inline const type * \
|
||||||
M_C3(array_, name, _cref)(const array_it_t it) \
|
M_C(name, _cref)(const array_it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert(it != NULL); \
|
assert(it != NULL); \
|
||||||
return M_C3(array_, name, _cget)(it->array, it->index); \
|
return M_C(name, _cget)(it->array, it->index); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
M_C3(array_, name, _insert)(array_t a, array_it_t it, type const x) \
|
M_C(name, _insert)(array_t a, array_it_t it, type const x) \
|
||||||
{ \
|
{ \
|
||||||
assert (it != NULL && a == it->array); \
|
assert (it != NULL && a == it->array); \
|
||||||
M_C3(array_, name, _push_at)(a, it->index, x); \
|
M_C(name, _push_at)(a, it->index, x); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
M_C3(array_,name, _remove)(array_t a, array_it_t it) \
|
M_C(name, _remove)(array_t a, array_it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert (it != NULL && a == it->array); \
|
assert (it != NULL && a == it->array); \
|
||||||
M_C3(array_, name, _pop_at)(NULL, a, it->index); \
|
M_C(name, _pop_at)(NULL, a, it->index); \
|
||||||
/* NOTE: it->index will naturaly point to the next element */ \
|
/* NOTE: it->index will naturaly point to the next element */ \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
M_IF_METHOD(CMP, oplist) \
|
M_IF_METHOD(CMP, oplist) \
|
||||||
( \
|
( \
|
||||||
static inline void M_C3(array_, name, _sort)(array_t l, \
|
static inline void M_C(name, _sort)(array_t l, \
|
||||||
int (*func_type) (const type *a, const type *b))\
|
int (*func_type) (const type *a, const type *b)) \
|
||||||
{ \
|
{ \
|
||||||
/* Using qsort is more compact but slower than a full templated \
|
/* Using qsort is more compact but slower than a full templated \
|
||||||
version which can be twice faster */ \
|
version which can be twice faster */ \
|
||||||
@@ -615,39 +617,39 @@
|
|||||||
func_void = (int (*)(const void*, const void*))func_type; \
|
func_void = (int (*)(const void*, const void*))func_type; \
|
||||||
qsort (l->ptr, l->size, sizeof(type), func_void); \
|
qsort (l->ptr, l->size, sizeof(type), func_void); \
|
||||||
} \
|
} \
|
||||||
,) /* IF CMP oplist */ \
|
,) /* IF CMP oplist */ \
|
||||||
\
|
\
|
||||||
M_IF_METHOD(GET_STR, oplist)( \
|
M_IF_METHOD(GET_STR, oplist)( \
|
||||||
static inline void \
|
static inline void \
|
||||||
M_C3(array_, name, _get_str)(string_t str, array_t array, \
|
M_C(name, _get_str)(string_t str, array_t array, \
|
||||||
bool append) \
|
bool append) \
|
||||||
{ \
|
{ \
|
||||||
STRING_CONTRACT(str); \
|
STRING_CONTRACT(str); \
|
||||||
ARRAYI_CONTRACT(array); \
|
ARRAYI_CONTRACT(array); \
|
||||||
(append ? string_cat_str : string_set_str) (str, "["); \
|
(append ? string_cat_str : string_set_str) (str, "["); \
|
||||||
array_it_t it; \
|
array_it_t it; \
|
||||||
for (M_C3(array_, name, _it)(it, array) ; \
|
for (M_C(name, _it)(it, array) ; \
|
||||||
!M_C3(array_, name, _end_p)(it); \
|
!M_C(name, _end_p)(it); \
|
||||||
M_C3(array_, name, _next)(it)){ \
|
M_C(name, _next)(it)){ \
|
||||||
const type *item = M_C3(array_, name, _cref)(it); \
|
const type *item = M_C(name, _cref)(it); \
|
||||||
M_GET_GET_STR oplist (str, *item, true); \
|
M_GET_GET_STR oplist (str, *item, true); \
|
||||||
if (!M_C3(array_, name, _last_p)(it)) \
|
if (!M_C(name, _last_p)(it)) \
|
||||||
string_push_back (str, M_GET_SEPARATOR oplist); \
|
string_push_back (str, M_GET_SEPARATOR oplist); \
|
||||||
} \
|
} \
|
||||||
string_push_back (str, ']'); \
|
string_push_back (str, ']'); \
|
||||||
STRING_CONTRACT(str); \
|
STRING_CONTRACT(str); \
|
||||||
} \
|
} \
|
||||||
, /* no GET_STR */ ) \
|
, /* no GET_STR */ ) \
|
||||||
\
|
\
|
||||||
M_IF_METHOD(OUT_STR, oplist)( \
|
M_IF_METHOD(OUT_STR, oplist)( \
|
||||||
static inline void \
|
static inline void \
|
||||||
M_C3(array_, name, _out_str)(FILE *file, const array_t array) \
|
M_C(name, _out_str)(FILE *file, const array_t array) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(array); \
|
ARRAYI_CONTRACT(array); \
|
||||||
assert (file != NULL); \
|
assert (file != NULL); \
|
||||||
fputc ('[', file); \
|
fputc ('[', file); \
|
||||||
for (size_t i = 0; i < array->size; i++) { \
|
for (size_t i = 0; i < array->size; i++) { \
|
||||||
const type *item = M_C3(array_, name, _cget)(array, i); \
|
const type *item = M_C(name, _cget)(array, i); \
|
||||||
M_GET_OUT_STR oplist (file, *item); \
|
M_GET_OUT_STR oplist (file, *item); \
|
||||||
if (i != array->size-1) \
|
if (i != array->size-1) \
|
||||||
fputc (M_GET_SEPARATOR oplist, file); \
|
fputc (M_GET_SEPARATOR oplist, file); \
|
||||||
@@ -658,11 +660,11 @@
|
|||||||
\
|
\
|
||||||
M_IF_METHOD(IN_STR, oplist)( \
|
M_IF_METHOD(IN_STR, oplist)( \
|
||||||
static inline bool \
|
static inline bool \
|
||||||
M_C3(array_, name, _in_str)(array_t array, FILE *file) \
|
M_C(name, _in_str)(array_t array, FILE *file) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(array); \
|
ARRAYI_CONTRACT(array); \
|
||||||
assert (file != NULL); \
|
assert (file != NULL); \
|
||||||
M_C3(array_, name,_clean)(array); \
|
M_C(name,_clean)(array); \
|
||||||
char c = fgetc(file); \
|
char c = fgetc(file); \
|
||||||
if (c != '[') return false; \
|
if (c != '[') return false; \
|
||||||
c = fgetc(file); \
|
c = fgetc(file); \
|
||||||
@@ -674,7 +676,7 @@
|
|||||||
bool b = M_GET_IN_STR oplist (item, file); \
|
bool b = M_GET_IN_STR oplist (item, file); \
|
||||||
c = fgetc(file); \
|
c = fgetc(file); \
|
||||||
if (!b) { break; } \
|
if (!b) { break; } \
|
||||||
M_C3(array_, name, _push_back)(array, item); \
|
M_C(name, _push_back)(array, item); \
|
||||||
} while (c == M_GET_SEPARATOR oplist && !feof(file) && !ferror(file)); \
|
} while (c == M_GET_SEPARATOR oplist && !feof(file) && !ferror(file)); \
|
||||||
M_GET_CLEAR oplist (item); \
|
M_GET_CLEAR oplist (item); \
|
||||||
ARRAYI_CONTRACT(array); \
|
ARRAYI_CONTRACT(array); \
|
||||||
@@ -684,16 +686,16 @@
|
|||||||
\
|
\
|
||||||
M_IF_METHOD(EQUAL, oplist)( \
|
M_IF_METHOD(EQUAL, oplist)( \
|
||||||
static inline bool \
|
static inline bool \
|
||||||
M_C3(array_, name, _equal_p)(const array_t array1, \
|
M_C(name, _equal_p)(const array_t array1, \
|
||||||
const array_t array2) \
|
const array_t array2) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(array1); \
|
ARRAYI_CONTRACT(array1); \
|
||||||
ARRAYI_CONTRACT(array2); \
|
ARRAYI_CONTRACT(array2); \
|
||||||
if (array1->size != array2->size) return false; \
|
if (array1->size != array2->size) return false; \
|
||||||
size_t i; \
|
size_t i; \
|
||||||
for(i = 0; i < array1->size; i++) { \
|
for(i = 0; i < array1->size; i++) { \
|
||||||
const type *item1 = M_C3(array_, name, _cget)(array1, i); \
|
const type *item1 = M_C(name, _cget)(array1, i); \
|
||||||
const type *item2 = M_C3(array_, name, _cget)(array2, i); \
|
const type *item2 = M_C(name, _cget)(array2, i); \
|
||||||
bool b = M_GET_EQUAL oplist (*item1, *item2); \
|
bool b = M_GET_EQUAL oplist (*item1, *item2); \
|
||||||
if (!b) return false; \
|
if (!b) return false; \
|
||||||
} \
|
} \
|
||||||
@@ -703,7 +705,7 @@
|
|||||||
\
|
\
|
||||||
M_IF_METHOD(HASH, oplist)( \
|
M_IF_METHOD(HASH, oplist)( \
|
||||||
static inline size_t \
|
static inline size_t \
|
||||||
M_C3(array_, name, _hash)(const array_t array) \
|
M_C(name, _hash)(const array_t array) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(array); \
|
ARRAYI_CONTRACT(array); \
|
||||||
M_HASH_DECL(hash); \
|
M_HASH_DECL(hash); \
|
||||||
|
|||||||
@@ -40,7 +40,7 @@
|
|||||||
, \
|
, \
|
||||||
LIST_DEF(M_C(list_dict_pair_, name), M_C3(dict_pair_,name,_t), TUPLE_OPLIST(M_C(dict_pair_, name), key_oplist, value_oplist)) \
|
LIST_DEF(M_C(list_dict_pair_, name), M_C3(dict_pair_,name,_t), TUPLE_OPLIST(M_C(dict_pair_, name), key_oplist, value_oplist)) \
|
||||||
) \
|
) \
|
||||||
ARRAY_DEF(M_C(list_dict_pair_,name), M_C3(list_dict_pair_,name,_t), LIST_OPLIST(M_C(list_dict_pair_, name), TUPLE_OPLIST(M_C(dict_pair_, name), key_oplist, value_oplist))) \
|
ARRAY_DEF(M_C(array_list_dict_pair_,name), M_C3(list_dict_pair_,name,_t), LIST_OPLIST(M_C(list_dict_pair_, name), TUPLE_OPLIST(M_C(dict_pair_, name), key_oplist, value_oplist))) \
|
||||||
\
|
\
|
||||||
DICTI_DEF2_FUNC(name, key_type, key_oplist, value_type, value_oplist, 0, M_C3(dict_, name, _t), M_C3(dict_it_, name, _t))
|
DICTI_DEF2_FUNC(name, key_type, key_oplist, value_type, value_oplist, 0, M_C3(dict_, name, _t), M_C3(dict_it_, name, _t))
|
||||||
|
|
||||||
@@ -64,7 +64,7 @@
|
|||||||
, \
|
, \
|
||||||
LIST_DEF(M_C(list_dict_pair_, name), M_C3(dict_pair_,name,_t), TUPLE_OPLIST(M_C(dict_pair_, name), key_oplist)) \
|
LIST_DEF(M_C(list_dict_pair_, name), M_C3(dict_pair_,name,_t), TUPLE_OPLIST(M_C(dict_pair_, name), key_oplist)) \
|
||||||
) \
|
) \
|
||||||
ARRAY_DEF(M_C(list_dict_pair_,name), M_C3(list_dict_pair_,name,_t), LIST_OPLIST(M_C(list_dict_pair_, name), TUPLE_OPLIST(M_C(dict_pair_, name), key_oplist))) \
|
ARRAY_DEF(M_C(array_list_dict_pair_,name), M_C3(list_dict_pair_,name,_t), LIST_OPLIST(M_C(list_dict_pair_, name), TUPLE_OPLIST(M_C(dict_pair_, name), key_oplist))) \
|
||||||
\
|
\
|
||||||
DICTI_DEF2_FUNC(name, key_type, key_oplist, key_type, \
|
DICTI_DEF2_FUNC(name, key_type, key_oplist, key_type, \
|
||||||
(INIT(M_EMPTY_DEFAULT), INIT_SET(M_EMPTY_DEFAULT), SET(M_EMPTY_DEFAULT), CLEAR(M_EMPTY_DEFAULT), \
|
(INIT(M_EMPTY_DEFAULT), INIT_SET(M_EMPTY_DEFAULT), SET(M_EMPTY_DEFAULT), CLEAR(M_EMPTY_DEFAULT), \
|
||||||
@@ -99,7 +99,7 @@
|
|||||||
} dict_t[1]; \
|
} dict_t[1]; \
|
||||||
\
|
\
|
||||||
typedef struct M_C3(dict_it_, name, _s) { \
|
typedef struct M_C3(dict_it_, name, _s) { \
|
||||||
M_C3(array_it_list_dict_pair_, name, _t) array_it; \
|
M_C3(array_list_dict_pair_, name, _it_t) array_it; \
|
||||||
M_C3(list_dict_pair_, name, _it_t) list_it; \
|
M_C3(list_dict_pair_, name, _it_t) list_it; \
|
||||||
} dict_it_t[1]; \
|
} dict_it_t[1]; \
|
||||||
\
|
\
|
||||||
@@ -588,7 +588,7 @@ typedef enum {
|
|||||||
} M_C3(dict_pair_,name,_t); \
|
} M_C3(dict_pair_,name,_t); \
|
||||||
\
|
\
|
||||||
/* NOTE: We don't want a real oplist for this type */ \
|
/* NOTE: We don't want a real oplist for this type */ \
|
||||||
ARRAY_DEF(M_C(dicti_,name), M_C3(dict_pair_,name,_t), \
|
ARRAY_DEF(M_C(array_dicti_,name), M_C3(dict_pair_,name,_t), \
|
||||||
(INIT(M_NOTHING_DEFAULT), SET(M_MEMCPY_DEFAULT), \
|
(INIT(M_NOTHING_DEFAULT), SET(M_MEMCPY_DEFAULT), \
|
||||||
INIT_SET(M_MEMCPY_DEFAULT), CLEAR(M_NOTHING_DEFAULT))) \
|
INIT_SET(M_MEMCPY_DEFAULT), CLEAR(M_NOTHING_DEFAULT))) \
|
||||||
\
|
\
|
||||||
|
|||||||
+14
-14
@@ -3,13 +3,13 @@
|
|||||||
#include "m-string.h"
|
#include "m-string.h"
|
||||||
#include "m-algo.h"
|
#include "m-algo.h"
|
||||||
|
|
||||||
ARRAY_DEF(int, int)
|
ARRAY_DEF(array_int, int)
|
||||||
LIST_DEF(list_int, int)
|
LIST_DEF(list_int, int)
|
||||||
LIST_DEF(list_string, string_t, STRING_OPLIST)
|
LIST_DEF(list_string, string_t, STRING_OPLIST)
|
||||||
|
|
||||||
#include "coverage.h"
|
#include "coverage.h"
|
||||||
START_COVERAGE
|
START_COVERAGE
|
||||||
ALGO_DEF(algo_array, ARRAY_OPLIST(int))
|
ALGO_DEF(algo_array, ARRAY_OPLIST(array_int))
|
||||||
|
|
||||||
ALGO_DEF(algo_list, LIST_OPLIST(list_int))
|
ALGO_DEF(algo_list, LIST_OPLIST(list_int))
|
||||||
|
|
||||||
@@ -101,7 +101,7 @@ static void test_array(void)
|
|||||||
assert( algo_array_count(l, -1) == 0);
|
assert( algo_array_count(l, -1) == 0);
|
||||||
assert( algo_array_sort_p(l) == false);
|
assert( algo_array_sort_p(l) == false);
|
||||||
|
|
||||||
array_it_int_t it;
|
array_int_it_t it;
|
||||||
algo_array_find_last(it, l, 17);
|
algo_array_find_last(it, l, 17);
|
||||||
assert (!array_int_end_p (it));
|
assert (!array_int_end_p (it));
|
||||||
assert (array_int_last_p (it));
|
assert (array_int_last_p (it));
|
||||||
@@ -111,7 +111,7 @@ static void test_array(void)
|
|||||||
assert (array_int_end_p (it));
|
assert (array_int_end_p (it));
|
||||||
|
|
||||||
#define f(x) assert((x) >= 0 && (x) < 100);
|
#define f(x) assert((x) >= 0 && (x) < 100);
|
||||||
ALGO_MAP(l, ARRAY_OPLIST(int), f);
|
ALGO_MAP(l, ARRAY_OPLIST(array_int), f);
|
||||||
|
|
||||||
g_min = 0;
|
g_min = 0;
|
||||||
g_max = 99;
|
g_max = 99;
|
||||||
@@ -165,7 +165,7 @@ static void test_array(void)
|
|||||||
|
|
||||||
array_int_clear(l);
|
array_int_clear(l);
|
||||||
|
|
||||||
ALGO_INIT_VA(l, ARRAY_OPLIST(int), 1, 2, 3, 4, 5);
|
ALGO_INIT_VA(l, ARRAY_OPLIST(array_int), 1, 2, 3, 4, 5);
|
||||||
assert (array_int_size(l) == 5);
|
assert (array_int_size(l) == 5);
|
||||||
array_int_clear(l);
|
array_int_clear(l);
|
||||||
}
|
}
|
||||||
@@ -206,30 +206,30 @@ static void test_extract(void)
|
|||||||
array_int_t a;
|
array_int_t a;
|
||||||
array_int_init(a);
|
array_int_init(a);
|
||||||
#define cond(d) ((d) > 0)
|
#define cond(d) ((d) > 0)
|
||||||
ALGO_EXTRACT(a, ARRAY_OPLIST(int), l, LIST_OPLIST(list_int), cond);
|
ALGO_EXTRACT(a, ARRAY_OPLIST(array_int), l, LIST_OPLIST(list_int), cond);
|
||||||
assert(array_int_size(a) == 99);
|
assert(array_int_size(a) == 99);
|
||||||
#define cond2(c, d) ((d) > (c))
|
#define cond2(c, d) ((d) > (c))
|
||||||
ALGO_EXTRACT(a, ARRAY_OPLIST(int), l, LIST_OPLIST(list_int), cond2, 10);
|
ALGO_EXTRACT(a, ARRAY_OPLIST(array_int), l, LIST_OPLIST(list_int), cond2, 10);
|
||||||
assert(array_int_size(a) == 89);
|
assert(array_int_size(a) == 89);
|
||||||
|
|
||||||
int dst = 0;
|
int dst = 0;
|
||||||
#define inc(d, c) (d) += (c)
|
#define inc(d, c) (d) += (c)
|
||||||
ALGO_REDUCE(dst, a, ARRAY_OPLIST(int), inc);
|
ALGO_REDUCE(dst, a, ARRAY_OPLIST(array_int), inc);
|
||||||
assert (dst == 100*99/2-10*11/2);
|
assert (dst == 100*99/2-10*11/2);
|
||||||
#define sqr(d, c) (d) = (c)*(c)
|
#define sqr(d, c) (d) = (c)*(c)
|
||||||
ALGO_REDUCE(dst, a, ARRAY_OPLIST(int), inc, sqr);
|
ALGO_REDUCE(dst, a, ARRAY_OPLIST(array_int), inc, sqr);
|
||||||
assert (dst == 327965);
|
assert (dst == 327965);
|
||||||
#define sqr2(d, f, c) (d) = (f) * (c)
|
#define sqr2(d, f, c) (d) = (f) * (c)
|
||||||
ALGO_REDUCE(dst, a, ARRAY_OPLIST(int), inc, sqr2, 4);
|
ALGO_REDUCE(dst, a, ARRAY_OPLIST(array_int), inc, sqr2, 4);
|
||||||
assert (dst == (100*99/2-10*11/2) *4 );
|
assert (dst == (100*99/2-10*11/2) *4 );
|
||||||
|
|
||||||
ALGO_REDUCE(dst, a, ARRAY_OPLIST(int), sum);
|
ALGO_REDUCE(dst, a, ARRAY_OPLIST(array_int), sum);
|
||||||
assert (dst == 100*99/2-10*11/2);
|
assert (dst == 100*99/2-10*11/2);
|
||||||
ALGO_REDUCE(dst, a, ARRAY_OPLIST(int), add);
|
ALGO_REDUCE(dst, a, ARRAY_OPLIST(array_int), add);
|
||||||
assert (dst == 100*99/2-10*11/2);
|
assert (dst == 100*99/2-10*11/2);
|
||||||
ALGO_REDUCE(dst, a, ARRAY_OPLIST(int), and);
|
ALGO_REDUCE(dst, a, ARRAY_OPLIST(array_int), and);
|
||||||
assert (dst == 0);
|
assert (dst == 0);
|
||||||
ALGO_REDUCE(dst, a, ARRAY_OPLIST(int), or);
|
ALGO_REDUCE(dst, a, ARRAY_OPLIST(array_int), or);
|
||||||
assert (dst == 127);
|
assert (dst == 127);
|
||||||
|
|
||||||
array_int_clear(a);
|
array_int_clear(a);
|
||||||
|
|||||||
+5
-5
@@ -51,13 +51,13 @@ static void my_mpz_str(string_t str, const mpz_t z, bool append)
|
|||||||
|
|
||||||
#include "coverage.h"
|
#include "coverage.h"
|
||||||
START_COVERAGE
|
START_COVERAGE
|
||||||
ARRAY_DEF(uint, unsigned int)
|
ARRAY_DEF(array_uint, unsigned int)
|
||||||
ARRAY_DEF(mpz, mpz_t,
|
ARRAY_DEF(array_mpz, mpz_t,
|
||||||
(INIT(mpz_init), INIT_SET(mpz_init_set), SET(mpz_set), CLEAR(mpz_clear), \
|
(INIT(mpz_init), INIT_SET(mpz_init_set), SET(mpz_set), CLEAR(mpz_clear), \
|
||||||
OUT_STR(my_mpz_out_str), IN_STR(my_mpz_in_str), EQUAL(my_mpz_equal_p), \
|
OUT_STR(my_mpz_out_str), IN_STR(my_mpz_in_str), EQUAL(my_mpz_equal_p), \
|
||||||
GET_STR(my_mpz_str) ))
|
GET_STR(my_mpz_str) ))
|
||||||
END_COVERAGE
|
END_COVERAGE
|
||||||
#define ARRAY_UINT_OPLIST ARRAY_OPLIST(uint)
|
#define ARRAY_UINT_OPLIST ARRAY_OPLIST(array_uint)
|
||||||
|
|
||||||
static void test_uint(void)
|
static void test_uint(void)
|
||||||
{
|
{
|
||||||
@@ -265,7 +265,7 @@ static void test_d(void)
|
|||||||
for(int i = 10; i < 210; i++) {
|
for(int i = 10; i < 210; i++) {
|
||||||
assert (*array_uint_get (a1, i) == 0);
|
assert (*array_uint_get (a1, i) == 0);
|
||||||
}
|
}
|
||||||
array_it_uint_t it;
|
array_uint_it_t it;
|
||||||
array_uint_it(it, a1);
|
array_uint_it(it, a1);
|
||||||
array_uint_remove (a1, it);
|
array_uint_remove (a1, it);
|
||||||
assert (array_uint_size(a1) == 299);
|
assert (array_uint_size(a1) == 299);
|
||||||
@@ -276,7 +276,7 @@ static void test_d(void)
|
|||||||
assert (array_uint_end_p(it));
|
assert (array_uint_end_p(it));
|
||||||
array_uint_previous (it);
|
array_uint_previous (it);
|
||||||
assert (array_uint_last_p(it));
|
assert (array_uint_last_p(it));
|
||||||
array_it_uint_t it2;
|
array_uint_it_t it2;
|
||||||
array_uint_it_set (it2, it);
|
array_uint_it_set (it2, it);
|
||||||
assert (array_uint_it_equal_p(it2, it));
|
assert (array_uint_it_equal_p(it2, it));
|
||||||
assert (*array_uint_ref(it2) == 0);
|
assert (*array_uint_ref(it2) == 0);
|
||||||
|
|||||||
+1
-1
@@ -45,7 +45,7 @@ END_COVERAGE
|
|||||||
DICT_SET_DEF2(setstr, string_t, STRING_OPLIST)
|
DICT_SET_DEF2(setstr, string_t, STRING_OPLIST)
|
||||||
|
|
||||||
/* Helper structure */
|
/* Helper structure */
|
||||||
ARRAY_DEF(string, string_t, STRING_OPLIST)
|
ARRAY_DEF(array_string, string_t, STRING_OPLIST)
|
||||||
array_string_t v_str;
|
array_string_t v_str;
|
||||||
|
|
||||||
static void init_data(int data_size)
|
static void init_data(int data_size)
|
||||||
|
|||||||
Reference in new issue
Block a user