#include "tifa_config.h"
#include <inttypes.h>
#include <stdbool.h>
#include <gmp.h>
#include "bitstring_t.h"
Go to the source code of this file.
Data Structures | |
struct | struct_byte_array_t |
Defines an array of bytes. More... | |
struct | struct_uint32_array_t |
Defines an array of uint32 . More... | |
struct | struct_int32_array_t |
Defines an array of int32 . More... | |
struct | struct_mpz_array_t |
Defines an array of mpz_t elements from the GMP library. More... | |
struct | struct_binary_array_t |
Defines an array of bits. More... | |
Defines | |
#define | _TIFA_ARRAY_H_ |
#define | ELONGATION 16 |
#define | NOT_IN_ARRAY UINT32_MAX |
#define | ARRAY_IS_FULL(ARRAY_PTR) ((ARRAY_PTR)->length == (ARRAY_PTR)->alloced) |
#define | reset_byte_array(ARRAY) do {(ARRAY)->length = 0;} while (0) |
Resets a byte_array_t . | |
#define | reset_uint32_array(ARRAY) do {(ARRAY)->length = 0;} while (0) |
Resets a uint32_array_t . | |
#define | reset_int32_array(ARRAY) do {(ARRAY)->length = 0;} while (0) |
Resets an int32_array_t . | |
#define | reset_mpz_array(ARRAY) do {(ARRAY)->length = 0;} while (0) |
Resets an mpz_array_t . | |
#define | reset_binary_array(ARRAY) do {(ARRAY)->length = 0;} while (0) |
Resets a binary_array_t . | |
Typedefs | |
typedef struct struct_byte_array_t | byte_array_t |
Equivalent to struct struct_byte_array_t . | |
typedef struct struct_uint32_array_t | uint32_array_t |
Equivalent to struct struct_uint32_array_t . | |
typedef struct struct_int32_array_t | int32_array_t |
Equivalent to struct struct_int32_array_t . | |
typedef struct struct_mpz_array_t | mpz_array_t |
Equivalent to struct struct_mpz_array_t . | |
typedef struct struct_binary_array_t | binary_array_t |
Equivalent to struct struct_binary_array_t . | |
Functions | |
byte_array_t * | alloc_byte_array (uint32_t length) |
Allocates and returns a new byte_array_t . | |
void | free_byte_array (byte_array_t *array) |
Frees a byte_array_t . | |
void | resize_byte_array (byte_array_t *const array, uint32_t alloced) |
Resizes the allocated memory of a byte_array_t . | |
void | append_byte_to_array (byte_array_t *array, const unsigned char to_append) |
Appends a uint32_t to an byte_array_t . | |
void | append_byte_array (byte_array_t *const array, const byte_array_t *const to_append) |
Appends the content of a byte_array_t to another one. | |
void | swap_byte_array (byte_array_t *const a, byte_array_t *const b) |
Swaps two byte_array_t 's contents. | |
void | print_byte_array (const byte_array_t *const array) |
Prints a byte_array_t . | |
void | ins_sort_byte_array (byte_array_t *const array) |
Sorts the elements of a byte_array_t . | |
void | qsort_byte_array (byte_array_t *const array) |
Sorts the elements of a byte_array_t with a quick sort. | |
uint32_t | index_in_byte_array (unsigned char to_find, const byte_array_t *const array) |
Returns the position of a byte in a byte_array_t . | |
static bool | is_in_byte_array (unsigned char to_find, const byte_array_t *const array) |
Returns true if a given byte is in a given array. | |
uint32_t | index_in_sorted_byte_array (unsigned char to_find, const byte_array_t *const sorted_array, uint32_t min_index, uint32_t max_index) |
Returns the position of an integer in a sorted portion of a byte_array_t . | |
static bool | is_in_sorted_byte_array (unsigned char to_find, const byte_array_t *const array) |
Returns true if a given byte is in a sorted byte_array_t . | |
uint32_array_t * | alloc_uint32_array (uint32_t length) |
Allocates and returns a new uint32_array_t . | |
void | free_uint32_array (uint32_array_t *array) |
Frees a uint32_array_t . | |
void | resize_uint32_array (uint32_array_t *const array, uint32_t alloced) |
Resizes the allocated memory of an uint32_array_t . | |
void | append_uint32_to_array (uint32_array_t *array, const uint32_t to_append) |
Appends a uint32_t to an uint32_array_t . | |
void | append_uint32_array (uint32_array_t *const array, const uint32_array_t *const to_append) |
Appends the content of a uint32_array_t to another one. | |
void | swap_uint32_array (uint32_array_t *const a, uint32_array_t *const b) |
Swaps two uint32_array_t 's contents. | |
void | print_uint32_array (const uint32_array_t *const array) |
Prints a uint32_array_t . | |
void | ins_sort_uint32_array (uint32_array_t *const array) |
Sorts the uint32_t elements of a uint32_array_t . | |
void | qsort_uint32_array (uint32_array_t *const array) |
Sorts the uint32_t elements of a uint32_array_t with a quick sort. | |
uint32_t | index_in_uint32_array (uint32_t to_find, const uint32_array_t *const array) |
Returns the position of an integer in a uint32_array_t . | |
static bool | is_in_uint32_array (uint32_t to_find, const uint32_array_t *const array) |
Returns true if a given integer is in a given array. | |
uint32_t | index_in_sorted_uint32_array (uint32_t to_find, const uint32_array_t *const sorted_array, uint32_t min_index, uint32_t max_index) |
Returns the position of an integer in a sorted portion of a uint32_array_t . | |
static bool | is_in_sorted_uint32_array (uint32_t to_find, const uint32_array_t *const array) |
Returns true if a given integer is in a given array. | |
int32_array_t * | alloc_int32_array (uint32_t length) |
Allocates and returns a new int32_array_t . | |
void | free_int32_array (int32_array_t *array) |
Frees a int32_array_t . | |
void | resize_int32_array (int32_array_t *const array, uint32_t alloced) |
Resizes the allocated memory of an int32_array_t . | |
void | append_int32_to_array (int32_array_t *array, const int32_t to_append) |
Appends a int32_t to an int32_array_t . | |
void | append_int32_array (int32_array_t *const array, const int32_array_t *const to_append) |
Appends the content of an int32_array_t to another one. | |
void | swap_int32_array (int32_array_t *const a, int32_array_t *const b) |
Swaps two int32_array_t 's contents. | |
void | print_int32_array (const int32_array_t *const array) |
Prints a int32_array_t . | |
uint32_t | index_in_int32_array (int32_t to_find, const int32_array_t *const array) |
Returns the position of an integer in a int32_array_t . | |
static bool | is_in_int32_array (int32_t to_find, const int32_array_t *const array) |
Returns true if a given integer is in a given array. | |
uint32_t | index_in_sorted_int32_array (int32_t to_find, const int32_array_t *const sorted_array, uint32_t min_index, uint32_t max_index) |
Returns the position of an integer in a sorted portion of a int32_array_t . | |
static bool | is_in_sorted_int32_array (int32_t to_find, const int32_array_t *const array) |
Returns true if a given integer is in a given array. | |
mpz_array_t * | alloc_mpz_array (uint32_t length) |
Allocates and returns a new mpz_array_t . | |
void | free_mpz_array (mpz_array_t *array) |
Frees a mpz_array_t . | |
void | resize_mpz_array (mpz_array_t *const array, uint32_t alloced) |
Resizes the allocated memory of an mpz_array_t . | |
void | swap_mpz_array (mpz_array_t *const a, mpz_array_t *const b) |
Swaps two mpz_array_t 's contents. | |
void | append_mpz_to_array (mpz_array_t *array, const mpz_t to_append) |
Appends an mpz_t to an mpz_array_t . | |
void | append_mpz_array (mpz_array_t *const array, const mpz_array_t *const to_append) |
Appends the content of an mpz_array_t to another one. | |
void | print_mpz_array (const mpz_array_t *const array) |
Prints a mpz_array_t . | |
uint32_t | index_in_mpz_array (const mpz_t to_find, const mpz_array_t *const array) |
Returns the position of a mpz_t in a mpz_array_t . | |
uint32_t | index_in_sorted_mpz_array (const mpz_t to_find, const mpz_array_t *const sorted_array, uint32_t min_index, uint32_t max_index) |
Returns the position of an mpz_t in a sorted portion of an mpz_array_t . | |
static bool | is_in_mpz_array (const mpz_t to_find, const mpz_array_t *const array) |
Returns true if a given integer is in a given array. | |
void | ins_sort_mpz_array (mpz_array_t *const array) |
Sorts the mpz_t elements of a mpz_array_t . | |
void | qsort_mpz_array (mpz_array_t *const array) |
Sorts the mpz_t elements of a mpz_array_t with a quick sort. | |
static bool | is_in_sorted_mpz_array (const mpz_t to_find, const mpz_array_t *const array) |
Returns true if a given integer is in a given array. | |
binary_array_t * | alloc_binary_array (uint32_t length) |
Allocates and returns a new binary_array_t . | |
void | free_binary_array (binary_array_t *array) |
Frees a binary_array_t . | |
void | resize_binary_array (binary_array_t *const array, uint32_t alloced) |
Resizes the allocated memory of a binary_array_t . | |
void | append_bit_to_array (binary_array_t *array, const unsigned int to_append) |
Appends a bit to a binary_array_t . | |
void | print_binary_array (const binary_array_t *const array) |
Prints a binary_array_t . | |
static uint8_t | get_array_bit (uint32_t index, const binary_array_t *const array) |
Returns the value of a given bit in a binary_array_t . | |
static void | set_array_bit_to_one (uint32_t index, binary_array_t *const array) |
Sets a given bit to one in a binary_array_t . | |
static void | set_array_bit_to_zero (uint32_t index, binary_array_t *const array) |
Sets a given bit to zero in a binary_array_t . | |
static void | flip_array_bit (uint32_t index, binary_array_t *const array) |
Flips a given bit to zero in a binary_array_t . |
The *_array_t
types and their associated functions are quite similar, the only differences being the type of the elements these arrays hold. Each *_array_t
type is a structure composed of three fields:
alloced
- The maximum number of element the array can accomodate length
- The current number of element in the array data
- A pointer to the allocated memory space of alloced
elementsalloc_*_array
and clear_*_array
functions for more information. Definition in file array.h.
#define ARRAY_IS_FULL | ( | ARRAY_PTR | ) | ((ARRAY_PTR)->length == (ARRAY_PTR)->alloced) |
#define ELONGATION 16 |
#define NOT_IN_ARRAY UINT32_MAX |
Value returned by the index_in_*_array(x, array, ...)
functions if the element x
is not in the array array
.
Definition at line 75 of file array.h.
Referenced by is_in_byte_array(), is_in_int32_array(), is_in_mpz_array(), is_in_sorted_byte_array(), is_in_sorted_int32_array(), is_in_sorted_mpz_array(), is_in_sorted_uint32_array(), and is_in_uint32_array().
#define reset_binary_array | ( | ARRAY | ) | do {(ARRAY)->length = 0;} while (0) |
Resets a binary_array_t
.
Resets the length
field of array
to zero.
Note that its alloced
field is left unchanged and that memory for alloced * CHAR_BIT * sizeof(TIFA_BITSTRING_T)
bits is still allocated.
[in] | array | A pointer to the binary_array_t to reset. |
#define reset_byte_array | ( | ARRAY | ) | do {(ARRAY)->length = 0;} while (0) |
#define reset_int32_array | ( | ARRAY | ) | do {(ARRAY)->length = 0;} while (0) |
#define reset_mpz_array | ( | ARRAY | ) | do {(ARRAY)->length = 0;} while (0) |
Resets an mpz_array_t
.
Resets the length
field of array
to zero.
Note that its alloced
field is left unchanged and that memory for alloced
mpz_t
elements is still allocated (all the elements remaining fully mpz_init'ed
).
mpz_clear
all positions in array->data
. This is no longer true.[in] | array | A pointer to the mpz_array_t to clear. |
#define reset_uint32_array | ( | ARRAY | ) | do {(ARRAY)->length = 0;} while (0) |
binary_array_t* alloc_binary_array | ( | uint32_t | length | ) |
Allocates and returns a new binary_array_t
.
Allocates and returns a new binary_array_t
such that:
alloced
field is set to the minimum number of TIFA_BITSTRING_T
variables needed to store length bits. length
field is set to zero. data
array is completely filled with zeroes.[in] | length | The maximum bitlength of the uint32_array_t to allocate. |
uint32_array_t
structure. Note that this array may hold more that length bits if length is not a multiple of 8 * sizeof(TIFA_BITSTRING_T)
. byte_array_t* alloc_byte_array | ( | uint32_t | length | ) |
Allocates and returns a new byte_array_t
.
Allocates and returns a new byte_array_t
such that:
alloced
field is set to the parameter length. length
field is set to zero. data
array is completely filled with zeroes.[in] | length | The maximum length of the byte_array_t to allocate. |
byte_array_t
structure. int32_array_t* alloc_int32_array | ( | uint32_t | length | ) |
Allocates and returns a new int32_array_t
.
Allocates and returns a new int32_array_t
such that:
alloced
field is set to the parameter length. length
field is set to zero. data
array is completely filled with zeroes.[in] | length | The maximum length of the int32_array_t to allocate. |
int32_array_t
structure. mpz_array_t* alloc_mpz_array | ( | uint32_t | length | ) |
Allocates and returns a new mpz_array_t
.
Allocates and returns a new mpz_array_t
such that:
alloced
field is set to the parameter length. length
field is set to zero. data
array is fully mpz_init'ed
.[in] | length | The maximum length of the mpz_array_t to allocate. |
mpz_array_t
structure.data
field is completely mpz_init'ed
(from data
[0] to data
[alloced
-1]) whereas older versions did not mpz_init
anything. This change in behaviour was prompted by the need to avoid multiple memory deallocations and reallocations when using the same mpz_array_t
repeatedly. uint32_array_t* alloc_uint32_array | ( | uint32_t | length | ) |
Allocates and returns a new uint32_array_t
.
Allocates and returns a new uint32_array_t
such that:
alloced
field is set to the parameter length. length
field is set to zero. data
array is completely filled with zeroes.[in] | length | The maximum length of the uint32_array_t to allocate. |
uint32_array_t
structure. void append_bit_to_array | ( | binary_array_t * | array, | |
const unsigned int | to_append | |||
) |
Appends a bit to a binary_array_t
.
Appends a bit (set to one if to_append != 0
, set to zero otherwise) to array
. If array
has not enough capacity to accommodate this extra element it will be resized via a call to resize_binary_array
adding ELONGATION * BITSTRING_T_BITSIZE
bit slots to avoid too frequent resizes.
[in] | array | A pointer to the recipient binary_array_t . |
[in] | to_append | The bit to append (1 if to_append != 0 , 0 otherwise). |
void append_byte_array | ( | byte_array_t *const | array, | |
const byte_array_t *const | to_append | |||
) |
Appends the content of a byte_array_t
to another one.
Appends the content of the to_append
array to the byte_array_t
named array
. If array
has not enough capacity to accommodate all elements from to_append
, it will be resized via a call to resize_byte_array
with extra room for ELONGATION
unused slots to avoid too frequent resizes.
[in] | array | A pointer to the recipient byte_array_t . |
[in] | to_append | A pointer to the byte_array_t to append. |
void append_byte_to_array | ( | byte_array_t * | array, | |
const unsigned char | to_append | |||
) |
Appends a uint32_t
to an byte_array_t
.
Appends the byte to_append
to array
. If array
has not enough capacity to accommodate this extra element it will be resized via a call to resize_byte_array
adding ELONGATION
byte slots to avoid too frequent resizes.
[in] | array | A pointer to the recipient byte_array_t . |
[in] | to_append | The byte to append. |
void append_int32_array | ( | int32_array_t *const | array, | |
const int32_array_t *const | to_append | |||
) |
Appends the content of an int32_array_t
to another one.
Appends the content of the to_append
array to the int32_array_t
named array
. If array
has not enough capacity to accommodate all elements from to_append
, it will be resized via a call to resize_int32_array
with extra room for ELONGATION
unused int32_t
slots to avoid too frequent resizes.
[in] | array | A pointer to the recipient int32_array_t . |
[in] | to_append | A pointer to the int32_array_t to append. |
void append_int32_to_array | ( | int32_array_t * | array, | |
const int32_t | to_append | |||
) |
Appends a int32_t
to an int32_array_t
.
Appends the int32_t
integer to_append
to array
. If array
has not enough capacity to accommodate this extra element it will be resized via a call to resize_int32_array
adding ELONGATION
int32_t
slots to avoid too frequent resizes.
[in] | array | A pointer to the recipient int32_array_t . |
[in] | to_append | The integer to append. |
void append_mpz_array | ( | mpz_array_t *const | array, | |
const mpz_array_t *const | to_append | |||
) |
Appends the content of an mpz_array_t
to another one.
Appends the content of the to_append
array to the mpz_array_t
named array
. If array
has not enough capacity to accommodate all elements from to_append
, it will be resized via a call to resize_mpz_array
with extra room for ELONGATION
unused mpz_t
slots to avoid too frequent resizes.
[in] | array | A pointer to the recipient mpz_array_t . |
[in] | to_append | A pointer to the mpz_array_t to append. |
void append_mpz_to_array | ( | mpz_array_t * | array, | |
const mpz_t | to_append | |||
) |
Appends an mpz_t
to an mpz_array_t
.
Appends the mpz_t
integer to_append
to array
. If array
has not enough capacity to accommodate this extra element it will be resized via a call to resize_mpz_array
adding ELONGATION
mpz_t
slots to avoid too frequent resizes.
[in] | array | A pointer to the recipient mpz_array_t . |
[in] | to_append | The mpz_t to append. |
void append_uint32_array | ( | uint32_array_t *const | array, | |
const uint32_array_t *const | to_append | |||
) |
Appends the content of a uint32_array_t
to another one.
Appends the content of the to_append
array to the uint32_array_t
named array
. If array
has not enough capacity to accommodate all elements from to_append
, it will be resized via a call to resize_uint32_array
with extra room for ELONGATION
unused uint32_t
slots to avoid too frequent resizes.
[in] | array | A pointer to the recipient uint32_array_t . |
[in] | to_append | A pointer to the uint32_array_t to append. |
void append_uint32_to_array | ( | uint32_array_t * | array, | |
const uint32_t | to_append | |||
) |
Appends a uint32_t
to an uint32_array_t
.
Appends the uint32_t
integer to_append
to array
. If array
has not enough capacity to accommodate this extra element it will be resized via a call to resize_uint32_array
adding ELONGATION
uint32_t
slots to avoid too frequent resizes.
[in] | array | A pointer to the recipient uint32_array_t . |
[in] | to_append | The integer to append. |
static void flip_array_bit | ( | uint32_t | index, | |
binary_array_t *const | array | |||
) | [inline, static] |
Flips a given bit to zero in a binary_array_t
.
Flips the index
-th bit of the binary_array_t
pointed to by array
.
[in] | index | The position of the bit to flip. |
[in] | array | A pointer to the binary_array_t . |
Definition at line 1318 of file array.h.
References struct_binary_array_t::data.
void free_binary_array | ( | binary_array_t * | array | ) |
Frees a binary_array_t
.
Frees the binary_array_t
pointed to by array
, i.e. frees the memory space used by the C-style array pointed by array->data
and frees the array
pointer.
array
pointer was not freed which required explicit calls to free
(...) in client code.[in] | array | A pointer to the binary_array_t to clear. |
void free_byte_array | ( | byte_array_t * | array | ) |
Frees a byte_array_t
.
Frees the byte_array_t
pointed to by array
, i.e. frees the memory space used by the C-style array pointed by array->data
and frees the array
pointer.
array
pointer was not freed which required explicit calls to free
(...) in client code.[in] | array | A pointer to the byte_array_t to clear. |
void free_int32_array | ( | int32_array_t * | array | ) |
Frees a int32_array_t
.
Frees the int32_array_t
pointed to by array
, i.e. frees the memory space used by the C-style array pointed by array->data
and frees the array
pointer.
array
pointer was not freed which required explicit calls to free
(...) in client code.[in] | array | A pointer to the int32_array_t to clear. |
void free_mpz_array | ( | mpz_array_t * | array | ) |
Frees a mpz_array_t
.
Frees the mpz_array_t
pointed to by array
, i.e. frees the memory space used by the C-style array pointed by array->data
and frees the array
pointer.
array
pointer was not freed which required explicit calls to free
(...) in client code.[in] | array | A pointer to the mpz_array_t to clear. |
void free_uint32_array | ( | uint32_array_t * | array | ) |
Frees a uint32_array_t
.
Frees the uint32_array_t
pointed to by array
, i.e. frees the memory space used by the C-style array pointed by array->data
and frees the array
pointer.
array
pointer was not freed which required explicit calls to free
(...) in client code.[in] | array | A pointer to the uint32_array_t to clear. |
static uint8_t get_array_bit | ( | uint32_t | index, | |
const binary_array_t *const | array | |||
) | [inline, static] |
Returns the value of a given bit in a binary_array_t
.
Returns the value of the index
-th bit of the binary_array_t
pointed to by array
, as either 0 or 1.
[in] | index | The position of the bit to read. |
[in] | array | A pointer to the binary_array_t . |
index
-th bit: either 0 or 1. Definition at line 1248 of file array.h.
References struct_binary_array_t::data.
uint32_t index_in_byte_array | ( | unsigned char | to_find, | |
const byte_array_t *const | array | |||
) |
Returns the position of a byte in a byte_array_t
.
Returns the position of the byte to_find
in the byte_array_t
pointed to by array
. If the byte to_find
is not found in the byte_array_t
, returns NOT_IN_ARRAY
.
NOT_IN_ARRAY
value is actually -1 if interpreted as a signed int32_t
.
If the array is already sorted, the more efficient function index_in_sorted_byte_array
can be used as it uses a basic binary search instead of a complete scanning of the array.
[in] | to_find | The byte to find in the byte_array_t . |
[in] | array | A pointer to the byte_array_t . |
to_find
in the array if to_find
is found.
NOT_IN_ARRAY
otherwise.
Referenced by is_in_byte_array().
uint32_t index_in_int32_array | ( | int32_t | to_find, | |
const int32_array_t *const | array | |||
) |
Returns the position of an integer in a int32_array_t
.
Returns the position of the integer to_find
in the int32_array_t
pointed to by array
. If the integer to_find
is not found in the int32_array_t
, returns NOT_IN_ARRAY
.
NOT_IN_ARRAY
value is actually -1 if interpreted as a signed int32_t
.
If the array is already sorted, the more efficient function index_in_sorted_int32_array
can be used as it uses a basic binary search instead of a complete scanning of the array.
[in] | to_find | The integer to find in the int32_array_t . |
[in] | array | A pointer to the int32_array_t . |
to_find
in the array if to_find
is found.
NOT_IN_ARRAY
otherwise.
Referenced by is_in_int32_array().
uint32_t index_in_mpz_array | ( | const mpz_t | to_find, | |
const mpz_array_t *const | array | |||
) |
Returns the position of a mpz_t
in a mpz_array_t
.
Returns the position of the mpz_t
to_find
in the mpz_array_t
pointed to by array
. If the integer to_find
is not found in the mpz_array_t
, returns NOT_IN_ARRAY
.
NOT_IN_ARRAY
value is actually -1 if interpreted as a signed int32_t
.[in] | to_find | The mpz_t integer to find in the mpz_array_t . |
[in] | array | A pointer to the mpz_array_t . |
to_find
in the array if to_find
is found.
NOT_IN_ARRAY
otherwise.
Referenced by is_in_mpz_array().
uint32_t index_in_sorted_byte_array | ( | unsigned char | to_find, | |
const byte_array_t *const | sorted_array, | |||
uint32_t | min_index, | |||
uint32_t | max_index | |||
) |
Returns the position of an integer in a sorted portion of a byte_array_t
.
Returns the position of the byte to_find
in a sorted portion of the byte_array_t
pointed to by array
. If the byte to_find
is not found in the portion delimited by min_index
and max_index
, returns NOT_IN_ARRAY
.
NOT_IN_ARRAY
value is actually -1 if interpreted as a signed int32_t
.[in] | to_find | The byte to find in the byte_array_t . |
[in] | sorted_array | A pointer to the byte_array_t . |
[in] | min_index | The beginning of the sorted array portion to search in. |
[in] | max_index | The end of the sorted array portion to search in. |
to_find
in the array if to_find
is found in the sorted array portion.
NOT_IN_ARRAY
otherwise.
Referenced by is_in_sorted_byte_array().
uint32_t index_in_sorted_int32_array | ( | int32_t | to_find, | |
const int32_array_t *const | sorted_array, | |||
uint32_t | min_index, | |||
uint32_t | max_index | |||
) |
Returns the position of an integer in a sorted portion of a int32_array_t
.
Returns the position of the integer to_find
in a sorted portion of the int32_array_t
pointed to by array
. If the integer to_find
is not found in the portion delimited by min_index
and max_index
, returns NOT_IN_ARRAY
.
NOT_IN_ARRAY
value is actually -1 if interpreted as a signed int32_t
.[in] | to_find | The integer to find in the int32_array_t . |
[in] | sorted_array | A pointer to the int32_array_t . |
[in] | min_index | The beginning of the sorted array portion to search in. |
[in] | max_index | The end of the sorted array portion to search in. |
to_find
in the array if to_find
is found in the sorted array portion.
NOT_IN_ARRAY
otherwise.
Referenced by is_in_sorted_int32_array().
uint32_t index_in_sorted_mpz_array | ( | const mpz_t | to_find, | |
const mpz_array_t *const | sorted_array, | |||
uint32_t | min_index, | |||
uint32_t | max_index | |||
) |
Returns the position of an mpz_t
in a sorted portion of an mpz_array_t
.
Returns the position of the mpz_t
to_find
in the sorted portion of the mpz_array_t
pointed to by array
. If the integer to_find
is not found in this portion, returns NOT_IN_ARRAY
.
NOT_IN_ARRAY
value is actually -1 if interpreted as a signed int32_t
.[in] | to_find | The mpz_t integer to find in the mpz_array_t . |
[in] | sorted_array | A pointer to the sorted mpz_array_t . |
[in] | min_index | The beginning of the sorted array portion to search in. |
[in] | max_index | The end of the sorted array portion to search in. |
to_find
in the array if to_find
is found.
NOT_IN_ARRAY
otherwise.
Referenced by is_in_sorted_mpz_array().
uint32_t index_in_sorted_uint32_array | ( | uint32_t | to_find, | |
const uint32_array_t *const | sorted_array, | |||
uint32_t | min_index, | |||
uint32_t | max_index | |||
) |
Returns the position of an integer in a sorted portion of a uint32_array_t
.
Returns the position of the integer to_find
in a sorted portion of the uint32_array_t
pointed to by array
. If the integer to_find
is not found in the portion delimited by min_index
and max_index
, returns NOT_IN_ARRAY
.
NOT_IN_ARRAY
value is actually -1 if interpreted as a signed int32_t
.[in] | to_find | The integer to find in the uint32_array_t . |
[in] | sorted_array | A pointer to the uint32_array_t . |
[in] | min_index | The beginning of the sorted array portion to search in. |
[in] | max_index | The end of the sorted array portion to search in. |
to_find
in the array if to_find
is found in the sorted array portion.
NOT_IN_ARRAY
otherwise.
Referenced by is_in_sorted_uint32_array().
uint32_t index_in_uint32_array | ( | uint32_t | to_find, | |
const uint32_array_t *const | array | |||
) |
Returns the position of an integer in a uint32_array_t
.
Returns the position of the integer to_find
in the uint32_array_t
pointed to by array
. If the integer to_find
is not found in the uint32_array_t
, returns NOT_IN_ARRAY
.
NOT_IN_ARRAY
value is actually -1 if interpreted as a signed int32_t
.
If the array is already sorted, the more efficient function index_in_sorted_uint32_array
can be used as it uses a basic binary search instead of a complete scanning of the array.
[in] | to_find | The integer to find in the uint32_array_t . |
[in] | array | A pointer to the uint32_array_t . |
to_find
in the array if to_find
is found.
NOT_IN_ARRAY
otherwise.
Referenced by is_in_uint32_array().
void ins_sort_byte_array | ( | byte_array_t *const | array | ) |
Sorts the elements of a byte_array_t
.
Sorts the elements of a byte_array_t
in natural order using a basic insertion sort.
[in] | array | A pointer to the byte_array_t to sort. |
void ins_sort_mpz_array | ( | mpz_array_t *const | array | ) |
Sorts the mpz_t elements of a mpz_array_t
.
Sorts the mpz_t elements of a mpz_array_t
in natural order using a basic insertion sort.
[in] | array | A pointer to the mpz_array_t to sort. |
void ins_sort_uint32_array | ( | uint32_array_t *const | array | ) |
Sorts the uint32_t
elements of a uint32_array_t
.
Sorts the uint32_t elements of a uint32_array_t
in natural order using a basic insertion sort.
[in] | array | A pointer to the uint32_array_t to sort. |
static bool is_in_byte_array | ( | unsigned char | to_find, | |
const byte_array_t *const | array | |||
) | [inline, static] |
Returns true if a given byte is in a given array.
Returns true if the byte to_find
is in the byte_array_t
pointed to by array
. Returns false otherwise.
is_in_sorted_byte_array
can be used as it uses a basic binary search instead of a complete scanning of the array.[in] | to_find | The integer to find in the byte_array_t . |
[in] | array | A pointer to the byte_array_t . |
to_find
is in the array array
. false otherwise.
Definition at line 296 of file array.h.
References index_in_byte_array(), and NOT_IN_ARRAY.
static bool is_in_int32_array | ( | int32_t | to_find, | |
const int32_array_t *const | array | |||
) | [inline, static] |
Returns true if a given integer is in a given array.
Returns true if the integer to_find
is in the int32_array_t
pointed to by array
. Returns false otherwise.
is_in_sorted_int32_array
can be used as it uses a basic binary search instead of a complete scanning of the array.[in] | to_find | The integer to find in the int32_array_t . |
[in] | array | A pointer to the int32_array_t . |
to_find
is in the array array
. false otherwise.
Definition at line 792 of file array.h.
References index_in_int32_array(), and NOT_IN_ARRAY.
static bool is_in_mpz_array | ( | const mpz_t | to_find, | |
const mpz_array_t *const | array | |||
) | [inline, static] |
Returns true if a given integer is in a given array.
Returns true if the mpz_t
integer to_find
is in the mpz_array_t
pointed to by array
. Returns false otherwise.
is_in_sorted_mpz_array
can be used as it uses a basic binary search instead of a complete scanning of the array.[in] | to_find | The integer to find in the mpz_array_t . |
[in] | array | A pointer to the mpz_array_t . |
to_find
is in the array array
. false otherwise.
Definition at line 1062 of file array.h.
References index_in_mpz_array(), and NOT_IN_ARRAY.
static bool is_in_sorted_byte_array | ( | unsigned char | to_find, | |
const byte_array_t *const | array | |||
) | [inline, static] |
Returns true if a given byte is in a sorted byte_array_t
.
Returns true if the byte to_find
is in the (already sorted) byte_array_t
pointed to by array
. Returns false otherwise.
[in] | to_find | The byte to find in the byte_array_t . |
[in] | array | A pointer to the sorted byte_array_t . |
to_find
is in the array array
. false otherwise.
Definition at line 337 of file array.h.
References index_in_sorted_byte_array(), struct_byte_array_t::length, and NOT_IN_ARRAY.
static bool is_in_sorted_int32_array | ( | int32_t | to_find, | |
const int32_array_t *const | array | |||
) | [inline, static] |
Returns true if a given integer is in a given array.
Returns true if the integer to_find
is in the (already sorted) int32_array_t
pointed to by array
. Returns false otherwise.
[in] | to_find | The integer to find in the int32_array_t . |
[in] | array | A pointer to the sorted int32_array_t . |
to_find
is in the array array
. false otherwise.
Definition at line 833 of file array.h.
References index_in_sorted_int32_array(), struct_int32_array_t::length, and NOT_IN_ARRAY.
static bool is_in_sorted_mpz_array | ( | const mpz_t | to_find, | |
const mpz_array_t *const | array | |||
) | [inline, static] |
Returns true if a given integer is in a given array.
Returns true if the mpz_t
integer to_find
is in the mpz_array_t
pointed to by array
. Returns false otherwise.
[in] | to_find | The integer to find in the mpz_array_t . |
[in] | array | A pointer to the sorted mpz_array_t . |
to_find
is in the array array
. false otherwise.
Definition at line 1102 of file array.h.
References index_in_sorted_mpz_array(), struct_mpz_array_t::length, and NOT_IN_ARRAY.
static bool is_in_sorted_uint32_array | ( | uint32_t | to_find, | |
const uint32_array_t *const | array | |||
) | [inline, static] |
Returns true if a given integer is in a given array.
Returns true if the integer to_find
is in the (already sorted) uint32_array_t
pointed to by array
. Returns false otherwise.
[in] | to_find | The integer to find in the uint32_array_t . |
[in] | array | A pointer to the sorted uint32_array_t . |
to_find
is in the array array
. false otherwise.
Definition at line 598 of file array.h.
References index_in_sorted_uint32_array(), struct_uint32_array_t::length, and NOT_IN_ARRAY.
static bool is_in_uint32_array | ( | uint32_t | to_find, | |
const uint32_array_t *const | array | |||
) | [inline, static] |
Returns true if a given integer is in a given array.
Returns true if the integer to_find
is in the uint32_array_t
pointed to by array
. Returns false otherwise.
is_in_sorted_uint32_array
can be used as it uses a basic binary search instead of a complete scanning of the array.[in] | to_find | The integer to find in the uint32_array_t . |
[in] | array | A pointer to the uint32_array_t . |
to_find
is in the array array
. false otherwise.
Definition at line 557 of file array.h.
References index_in_uint32_array(), and NOT_IN_ARRAY.
void print_binary_array | ( | const binary_array_t *const | array | ) |
Prints a binary_array_t
.
Prints a binary_array_t
's on the standard output.
[in] | array | A pointer to the binary_array_t to print. |
void print_byte_array | ( | const byte_array_t *const | array | ) |
Prints a byte_array_t
.
Prints a byte_array_t
's data
elements on the standard output.
[in] | array | A pointer to the byte_array_t to print. |
void print_int32_array | ( | const int32_array_t *const | array | ) |
Prints a int32_array_t
.
Prints a int32_array_t
's data
elements on the standard output.
[in] | array | A pointer to the int32_array_t to print. |
void print_mpz_array | ( | const mpz_array_t *const | array | ) |
Prints a mpz_array_t
.
Prints a mpz_array_t
's data
elements on the standard output.
[in] | array | A pointer to the mpz_array_t to print. |
void print_uint32_array | ( | const uint32_array_t *const | array | ) |
Prints a uint32_array_t
.
Prints a uint32_array_t
's data
elements on the standard output.
[in] | array | A pointer to the uint32_array_t to print. |
void qsort_byte_array | ( | byte_array_t *const | array | ) |
Sorts the elements of a byte_array_t
with a quick sort.
Sorts the elements of a byte_array_t
in natural order using the quick sort algorithm.
qsort
.[in] | array | A pointer to the byte_array_t to sort. |
void qsort_mpz_array | ( | mpz_array_t *const | array | ) |
Sorts the mpz_t elements of a mpz_array_t
with a quick sort.
Sorts the mpz_t elements of a mpz_array_t
in natural order using the quick sort algorithm.
qsort
.[in] | array | A pointer to the mpz_array_t to sort. |
void qsort_uint32_array | ( | uint32_array_t *const | array | ) |
Sorts the uint32_t elements of a uint32_array_t
with a quick sort.
Sorts the uint32_t elements of a uint32_array_t
in natural order using the quick sort algorithm.
qsort
.[in] | array | A pointer to the uint32_array_t to sort. |
void resize_binary_array | ( | binary_array_t *const | array, | |
uint32_t | alloced | |||
) |
Resizes the allocated memory of a binary_array_t
.
Resizes the storage available to an binary_array_t
to make room for alloced
integers, while preserving its content. If alloced
is less than the length of the array, then obviously some of its content will be lost.
[in] | alloced | The new maximum length of the binary_array_t to resize. |
[in] | array | A pointer to the binary_array_t to resize. |
void resize_byte_array | ( | byte_array_t *const | array, | |
uint32_t | alloced | |||
) |
Resizes the allocated memory of a byte_array_t
.
Resizes the storage available to an byte_array_t
to make room for alloced
integers, while preserving its content. If alloced
is less than the length of the array, then obviously some of its content will be lost.
[in] | alloced | The new maximum length of the byte_array_t to resize. |
[in] | array | A pointer to the byte_array_t to resize. |
void resize_int32_array | ( | int32_array_t *const | array, | |
uint32_t | alloced | |||
) |
Resizes the allocated memory of an int32_array_t
.
Resizes the storage available to an int32_array_t
to make room for alloced
integers, while preserving its content. If alloced
is less than the length of the array, then obviously some of its content will be lost.
[in] | alloced | The new maximum length of the int32_array_t to resize. |
[in] | array | A pointer to the int32_array_t to resize. |
void resize_mpz_array | ( | mpz_array_t *const | array, | |
uint32_t | alloced | |||
) |
Resizes the allocated memory of an mpz_array_t
.
Resizes the storage available to an mpz_array_t
to make room for alloced
integers, while preserving its content. If alloced
is less than the length of the array, then obviously some of its content will be freed and lost.
[in] | alloced | The new maximum length of the mpz_array_t to resize. |
[in] | array | A pointer to the mpz_array_t to resize. |
void resize_uint32_array | ( | uint32_array_t *const | array, | |
uint32_t | alloced | |||
) |
Resizes the allocated memory of an uint32_array_t
.
Resizes the storage available to an uint32_array_t
to make room for alloced
integers, while preserving its content. If alloced
is less than the length of the array, then obviously some of its content will be lost.
[in] | alloced | The new maximum length of the uint32_array_t to resize. |
[in] | array | A pointer to the uint32_array_t to resize. |
static void set_array_bit_to_one | ( | uint32_t | index, | |
binary_array_t *const | array | |||
) | [inline, static] |
Sets a given bit to one in a binary_array_t
.
Sets the index
-th bit of the binary_array_t
pointed to by array
to 1.
[in] | index | The position of the bit to set. |
[in] | array | A pointer to the binary_array_t . |
Definition at line 1274 of file array.h.
References struct_binary_array_t::data.
static void set_array_bit_to_zero | ( | uint32_t | index, | |
binary_array_t *const | array | |||
) | [inline, static] |
Sets a given bit to zero in a binary_array_t
.
Sets the index
-th bit of the binary_array_t
pointed to by array
to 0.
[in] | index | The position of the bit to set. |
[in] | array | A pointer to the binary_array_t . |
Definition at line 1296 of file array.h.
References struct_binary_array_t::data.
void swap_byte_array | ( | byte_array_t *const | a, | |
byte_array_t *const | b | |||
) |
Swaps two byte_array_t
's contents.
Swaps the contents of a
and b
, two byte_array_t
's.
[in] | a | A pointer to the first byte_array_t to swap. |
[in] | b | A pointer to the second byte_array_t to swap. |
void swap_int32_array | ( | int32_array_t *const | a, | |
int32_array_t *const | b | |||
) |
Swaps two int32_array_t
's contents.
Swaps the contents of a
and b
, two int32_array_t
's.
[in] | a | A pointer to the first int32_array_t to swap. |
[in] | b | A pointer to the second int32_array_t to swap. |
void swap_mpz_array | ( | mpz_array_t *const | a, | |
mpz_array_t *const | b | |||
) |
Swaps two mpz_array_t
's contents.
Swaps the contents of a
and b
, two mpz_array_t
's.
[in] | a | A pointer to the first mpz_array_t to swap. |
[in] | b | A pointer to the second mpz_array_t to swap. |
void swap_uint32_array | ( | uint32_array_t *const | a, | |
uint32_array_t *const | b | |||
) |
Swaps two uint32_array_t
's contents.
Swaps the contents of a
and b
, two uint32_array_t
's.
[in] | a | A pointer to the first uint32_array_t to swap. |
[in] | b | A pointer to the second uint32_array_t to swap. |