array.h File Reference

Higher level arrays and associated functions. More...

#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_talloc_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_talloc_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_talloc_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_talloc_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_talloc_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.


Detailed Description

Higher level arrays and associated functions.

Author:
Jerome Milan
Date:
Fri Jun 10 2011
Version:
2011-06-10
This file defines higher level arrays together with some associated functions.

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:

Warning:
Since version 1.2.1 memory management changed. See the alloc_*_array and clear_*_array functions for more information.

Definition in file array.h.


Define Documentation

#define _TIFA_ARRAY_H_

Standard include guard.

Definition at line 47 of file array.h.

#define ARRAY_IS_FULL ( ARRAY_PTR   )     ((ARRAY_PTR)->length == (ARRAY_PTR)->alloced)

Returns true if the *_array_t pointed by ARRAY_PTR is full (i.e. no more element can be added to the array without resizing it).

Returns false otherwise.

Definition at line 84 of file array.h.

#define ELONGATION   16

Incremental size used when automatically expanding the capacity of a *_array_t.

Note:
This is, of course, an hint to GMP's limbs and nails :-)

Definition at line 68 of file array.h.

#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.

Parameters:
[in] array A pointer to the binary_array_t to reset.

Definition at line 1197 of file array.h.

#define reset_byte_array ( ARRAY   )     do {(ARRAY)->length = 0;} while (0)

Resets a byte_array_t.

Resets the length field of array to zero.

Note that its alloced field is left unchanged and that memory for alloced byte_t elements is still allocated.

Parameters:
[in] array A pointer to the byte_array_t to reset.

Definition at line 163 of file array.h.

#define reset_int32_array ( ARRAY   )     do {(ARRAY)->length = 0;} while (0)

Resets an int32_array_t.

Resets the length field of array to zero.

Note that its alloced field is left unchanged and that memory for alloced int32_t elements is still allocated.

Parameters:
[in] array A pointer to the int32_array_t to reset.

Definition at line 683 of file array.h.

#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).

Warning:
Prior to 1.2 when the semantic was different, this function used to mpz_clear all positions in array->data. This is no longer true.
Parameters:
[in] array A pointer to the mpz_array_t to clear.

Definition at line 934 of file array.h.

#define reset_uint32_array ( ARRAY   )     do {(ARRAY)->length = 0;} while (0)

Resets a uint32_array_t.

Resets the length field of array to zero.

Note that its alloced field is left unchanged and that memory for alloced uint32_t elements is still allocated.

Parameters:
[in] array A pointer to the uint32_array_t to reset.

Definition at line 423 of file array.h.


Function Documentation

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:

  • its alloced field is set to the minimum number of TIFA_BITSTRING_T variables needed to store length bits.
  • its length field is set to zero.
  • its data array is completely filled with zeroes.
Parameters:
[in] length The maximum bitlength of the uint32_array_t to allocate.
Returns:
A pointer to the newly allocated 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:

  • its alloced field is set to the parameter length.
  • its length field is set to zero.
  • its data array is completely filled with zeroes.
Parameters:
[in] length The maximum length of the byte_array_t to allocate.
Returns:
A pointer to the newly allocated 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:

  • its alloced field is set to the parameter length.
  • its length field is set to zero.
  • its data array is completely filled with zeroes.
Parameters:
[in] length The maximum length of the int32_array_t to allocate.
Returns:
A pointer to the newly allocated 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:

  • its alloced field is set to the parameter length.
  • its length field is set to zero.
  • its data array is fully mpz_init'ed.
Parameters:
[in] length The maximum length of the mpz_array_t to allocate.
Returns:
A pointer to the newly allocated mpz_array_t structure.
Warning:
Since version 1.2, the 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:

  • its alloced field is set to the parameter length.
  • its length field is set to zero.
  • its data array is completely filled with zeroes.
Parameters:
[in] length The maximum length of the uint32_array_t to allocate.
Returns:
A pointer to the newly allocated 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.

Parameters:
[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.

Parameters:
[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.

Parameters:
[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.

Parameters:
[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.

Parameters:
[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.

Parameters:
[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.

Parameters:
[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.

Parameters:
[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.

Parameters:
[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.

Parameters:
[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.

Warning:
Before version 1.2.1, the array pointer was not freed which required explicit calls to free(...) in client code.
Parameters:
[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.

Warning:
Before version 1.2.1, the array pointer was not freed which required explicit calls to free(...) in client code.
Parameters:
[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.

Warning:
Before version 1.2.1, the array pointer was not freed which required explicit calls to free(...) in client code.
Parameters:
[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.

Warning:
Before version 1.2.1, the array pointer was not freed which required explicit calls to free(...) in client code.
Parameters:
[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.

Warning:
Before version 1.2.1, the array pointer was not freed which required explicit calls to free(...) in client code.
Parameters:
[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.

Parameters:
[in] index The position of the bit to read.
[in] array A pointer to the binary_array_t.
Returns:
The value of the 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.

Note:
The 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.

Parameters:
[in] to_find The byte to find in the byte_array_t.
[in] array A pointer to the byte_array_t.
Returns:
The index of 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.

Note:
The 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.

Parameters:
[in] to_find The integer to find in the int32_array_t.
[in] array A pointer to the int32_array_t.
Returns:
The index of 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.

Note:
The NOT_IN_ARRAY value is actually -1 if interpreted as a signed int32_t.
Parameters:
[in] to_find The mpz_t integer to find in the mpz_array_t.
[in] array A pointer to the mpz_array_t.
Returns:
The index of 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.

Note:
The NOT_IN_ARRAY value is actually -1 if interpreted as a signed int32_t.
Parameters:
[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.
Returns:
The index of 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.

Note:
The NOT_IN_ARRAY value is actually -1 if interpreted as a signed int32_t.
Parameters:
[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.
Returns:
The index of 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.

Note:
The NOT_IN_ARRAY value is actually -1 if interpreted as a signed int32_t.
Parameters:
[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.
Returns:
The index of 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.

Note:
The NOT_IN_ARRAY value is actually -1 if interpreted as a signed int32_t.
Parameters:
[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.
Returns:
The index of 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.

Note:
The 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.

Parameters:
[in] to_find The integer to find in the uint32_array_t.
[in] array A pointer to the uint32_array_t.
Returns:
The index of 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.

Parameters:
[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.

Parameters:
[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.

Parameters:
[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.

Note:
If the array is already sorted, the more efficient function is_in_sorted_byte_array can be used as it uses a basic binary search instead of a complete scanning of the array.
Parameters:
[in] to_find The integer to find in the byte_array_t.
[in] array A pointer to the byte_array_t.
Returns:
true if 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.

Note:
If the array is already sorted, the more efficient function is_in_sorted_int32_array can be used as it uses a basic binary search instead of a complete scanning of the array.
Parameters:
[in] to_find The integer to find in the int32_array_t.
[in] array A pointer to the int32_array_t.
Returns:
true if 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.

Note:
If the array is already sorted, the more efficient function is_in_sorted_mpz_array can be used as it uses a basic binary search instead of a complete scanning of the array.
Parameters:
[in] to_find The integer to find in the mpz_array_t.
[in] array A pointer to the mpz_array_t.
Returns:
true if 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.

Parameters:
[in] to_find The byte to find in the byte_array_t.
[in] array A pointer to the sorted byte_array_t.
Returns:
true if 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.

Parameters:
[in] to_find The integer to find in the int32_array_t.
[in] array A pointer to the sorted int32_array_t.
Returns:
true if 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.

Parameters:
[in] to_find The integer to find in the mpz_array_t.
[in] array A pointer to the sorted mpz_array_t.
Returns:
true if 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.

Parameters:
[in] to_find The integer to find in the uint32_array_t.
[in] array A pointer to the sorted uint32_array_t.
Returns:
true if 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.

Note:
If the array is already sorted, the more efficient function is_in_sorted_uint32_array can be used as it uses a basic binary search instead of a complete scanning of the array.
Parameters:
[in] to_find The integer to find in the uint32_array_t.
[in] array A pointer to the uint32_array_t.
Returns:
true if 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.

Parameters:
[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.

Note:
This function is mostly intended for debugging purposes as the output is not particularly well structured.
Parameters:
[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.

Note:
This function is mostly intended for debugging purposes as the output is not particularly well structured.
Parameters:
[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.

Note:
This function is mostly intended for debugging purposes as the output is not particularly well structured.
Parameters:
[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.

Note:
This function is mostly intended for debugging purposes as the output is not particularly well structured.
Parameters:
[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.

Note:
This function relies on the C library implementation of the quick sort provided by the function qsort.
Parameters:
[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.

Note:
This function relies on the C library implementation of the quick sort provided by the function qsort.
Parameters:
[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.

Note:
This function relies on the C library implementation of the quick sort provided by the function qsort.
Parameters:
[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.

Parameters:
[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.

Parameters:
[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.

Parameters:
[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.

Parameters:
[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.

Parameters:
[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.

Parameters:
[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.

Parameters:
[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.

Note:
In some case, pointer swapping is inappropriate (for example, if the pointers are passed as function arguments!), hence the need for such a swapping function.
Parameters:
[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.

Note:
In some case, pointer swapping is inappropriate (for example, if the pointers are passed as function arguments!), hence the need for such a swapping function.
Parameters:
[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.

Note:
In some case, pointer swapping is inappropriate (for example, if the pointers are passed as function arguments!), hence the need for such a swapping function.
Parameters:
[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.

Note:
In some case, pointer swapping is inappropriate (for example, if the pointers are passed as function arguments!), hence the need for such a swapping function.
Parameters:
[in] a A pointer to the first uint32_array_t to swap.
[in] b A pointer to the second uint32_array_t to swap.


Generated on Fri Jun 17 11:10:11 2011 for TIFA by Doxygen 1.5.5