int32

Overview

Module with functions and types to work with int32_t values.

Types and Definitions

Generated

cInt32Slice

struct cInt32Slice
{
   int64_t s;
   int32_t const* v;
};
typedef struct cInt32Slice cInt32Slice;

Via the macros SLICE_DEF_C_ and SLICE_IMPL_C_ declared and implemented struct. The macros declare and implement also the following functions.

/* init */
cInt32Slice int32_slice_c( int64_t s, int32_t const* v );
cInt32Slice make_int32_slice_c( int32_t const* beg, int32_t const* end );
cInt32Slice empty_int32_slice_c( void );
/* sub */
cInt32Slice left_int32_slice_c( cInt32Slice slice, int64_t maxLen );
cInt32Slice mid_int32_slice_c( cInt32Slice slice, int64_t index );
cInt32Slice right_int32_slice_c( cInt32Slice slice, int64_t maxLen );
cInt32Slice sub_int32_slice_c( cInt32Slice slice,
                               int64_t begIdx,
                               int64_t endIdx );

cVarInt32Slice

struct cVarInt32Slice
{
   int64_t s;
   int32_t* v;
};
typedef struct cVarInt32Slice cVarInt32Slice;

Via the macros SLICE_DEF_C_ and SLICE_IMPL_C_ declared and implemented struct. The macros declare and implement also the following functions.

/* init */
cVarInt32Slice var_int32_slice_c( int64_t s, int32_t const* v );
cVarInt32Slice make_var_int32_slice_c( int32_t* beg, int32_t* end );
cVarInt32Slice empty_var_int32_slice_c( void );
/* sub */
cVarInt32Slice left_var_int32_slice_c( cVarInt32Slice slice, int64_t maxLen );
cVarInt32Slice mid_var_int32_slice_c( cVarInt32Slice slice, int64_t index );
cVarInt32Slice right_var_int32_slice_c( cVarInt32Slice slice, int64_t maxLen );
cVarInt32Slice sub_var_int32_slice_c( cVarInt32Slice slice,
                                      int64_t begIdx,
                                      int64_t endIdx );
/* var slice */
cInt32Slice as_int32_slice_c( cVarInt32Slice slice );
cVarInt32Slice cast_int32_slice_c( cVarInt32Slice slice, cInt32Slice sub );
int64_t set_int32_slice_c( cVarInt32Slice dst, cInt32Slice src );

cInt32Chunk

struct cInt32Chunk
{
   int64_t s;
   int32_t const* v;
   int64_t favSize;
   cInt32Slice slice;
};
typedef struct cInt32Chunk cInt32Chunk;

Via the macros CHUNK_DEF_C_ and CHUNK_IMPL_C_ declared and implemented struct. The macros declare and implement also the following functions.

void init_back_int32_chunk_c( cInt32Chunk chunk[static 1],
                              int64_t s,
                              cInt32Slice slice );
void init_front_int32_chunk_c( cInt32Chunk chunk[static 1],
                               int64_t s,
                               cInt32Slice slice );

cVarInt32Chunk

struct cVarInt32Chunk
{
   int64_t s;
   int32_t* v;
   int64_t favSize;
   cInt32Slice slice;
};
typedef struct cVarInt32Chunk cVarInt32Chunk;

Via the macros CHUNK_DEF_C_ and CHUNK_IMPL_C_ declared and implemented struct. The macros declare and implement also the following functions.

void init_back_var_int32_chunk_c( cVarInt32Chunk chunk[static 1],
                                  int64_t s,
                                  cVarInt32Slice slice );
void init_front_var_int32_chunk_c( cVarInt32Chunk chunk[static 1],
                                   int64_t s,
                                   cVarInt32Slice slice );

cInt32Window

struct cInt32Window
{
   int64_t s;
   int32_t const* v;
   int64_t favSize;
   cInt32Slice slice;
};
typedef struct cInt32Window cInt32Window;

Via the macros WINDOW_DEF_C_ and WINDOW_IMPL_C_ declared and implemented struct. The macros declare and implement also the following functions.

void init_back_int32_window_c( cInt32Window window[static 1],
                               int64_t s,
                               cInt32Slice slice );
void init_front_int32_window_c( cInt32Window window[static 1],
                                int64_t s,
                                cInt32Slice slice );

cVarInt32Window

struct cVarInt32Window
{
   int64_t s;
   int32_t* v;
   int64_t favSize;
   cVarInt32Slice slice;
};
typedef struct cVarInt32Window cVarInt32Window;

Via the macros WINDOW_DEF_C_ and WINDOW_IMPL_C_ declared and implemented struct. The macros declare and implement also the following functions.

void init_back_var_int32_window_c( cVarInt32Window window[static 1],
                                   int64_t s,
                                   cVarInt32Slice slice );
void init_front_var_int32_window_c( cVarInt32Window window[static 1],
                                    int64_t s,
                                    cVarInt32Slice slice );

Functions

overall

cmp_int32_c

int cmp_int32_c( int32_t a, int32_t b );

Compares two int32_t values and returns the three possible results:

<0

means that a is less compared to b

0

means that a and b are equal

>0

means that a is greater compared to b

Example
#include "clingo/lang/expect.h"
#include "clingo/type/int32.h"

int main( void )
{
   init_tap_c_();

   expect_lt_c_( cmp_int32_c( -2147483648, 0 ) );
   expect_lt_c_( cmp_int32_c(          -1, 0 ) );
   expect_eq_c_( cmp_int32_c(           0, 0 ) );
   expect_gt_c_( cmp_int32_c(           1, 0 ) );
   expect_gt_c_( cmp_int32_c(  2147483647, 0 ) );

   return finish_tap_c_();
}

int32_c_

#define int32_c_( Value )

Macro function that casts the Value as int32_t.

conv

int64_to_int32_c

bool int64_to_int32_c( int64_t src, int32_t dst[static 1] );

Via the macro CONV_C_ implemented function. Returns true if the int64_t value can be represented in a int32_t variable, otherwise false.

Example
#include "clingo/lang/expect.h"
#include "clingo/type/int32.h"

int main( void )
{
   init_tap_c_();

   int32_t i32 = 0;

   // ---------------------------------------------------------------------- max
   int64_t i64 = 2147483647;  // INT32_MAX
   expect_c_( int64_to_int32_c( i64, &i32 ) );
   expect_c_( i32 == 2147483647 );

   ++i64;   // 2147483648
   expect_c_( not int64_to_int32_c( i64, &i32 ) );

   // ---------------------------------------------------------------------- min
   i64 = -2147483648;   // INT32_MIN
   expect_c_( int64_to_int32_c( i64, &i32 ) );
   expect_c_( i32 == -2147483648 );

   --i64;   // -2147483649
   expect_c_( not int64_to_int32_c( i64, &i32 ) );

   return finish_tap_c_();
}

uint64_to_int32_c

bool uint64_to_int32_c( uint64_t src, int32_t dst[static 1] );

Via the macro CONV_C_ implemented function. Returns true if the uint64_t value can be represented in a int32_t variable, otherwise false.

Example
#include "clingo/lang/expect.h"
#include "clingo/type/int32.h"

int main( void )
{
   init_tap_c_();

   int32_t i32 = 0;

   // ----------------------------------------------------------------- uint64_t
   uint64_t u64 = 2147483647; // INT32_MAX
   expect_c_( uint64_to_int32_c( u64, &i32 ) );
   expect_c_( u64 == 2147483647 );

   ++u64;   // 2147483648
   expect_c_( not uint64_to_int32_c( u64, &i32 ) );

   return finish_tap_c_();
}

swap

swap_int32_c

int32_t swap_int32_c( int32_t val );

Returns val with a changed byte order.

Example
#include "clingo/lang/expect.h"
#include "clingo/type/int32.h"

int main( void )
{
   init_tap_c_();

   expect_c_( swap_int32_c( 0x7caf0000 ) == 0x0000af7c );

   return finish_tap_c_();
}

swap_int32_from_c

int32_t swap_int32_from_c( int32_t val, c_ByteOrder order );

Changes the byte order of val from a known order to the system order if necessary.

Example
#include "clingo/lang/expect.h"
#include "clingo/type/int32.h"

int main( void )
{
   init_tap_c_();

   c_ByteOrder sysOrder = system_order_c();
   c_ByteOrder othOrder = system_order_is_c( c_BigEndian ) ? c_LittleEndian
                                                           : c_BigEndian;

   expect_c_( swap_int32_from_c( 0x7caf0000, sysOrder ) == 0x7caf0000 );

   expect_c_( swap_int32_from_c( 0x7caf0000, othOrder ) == 0x0000af7c );

   return finish_tap_c_();
}

swap_int32_to_c

int32_t swap_int32_to_c( int32_t val, c_ByteOrder order );

Changes the byte order of val from the system order to a known order if necessary.

Example
#include "clingo/lang/expect.h"
#include "clingo/type/int32.h"

int main( void )
{
   init_tap_c_();

   c_ByteOrder sysOrder = system_order_c();
   c_ByteOrder othOrder = system_order_is_c( c_BigEndian ) ? c_LittleEndian
                                                           : c_BigEndian;

   expect_c_( swap_int32_to_c( 0x7caf0000, sysOrder ) == 0x7caf0000 );

   expect_c_( swap_int32_to_c( 0x7caf0000, othOrder ) == 0x0000af7c );

   return finish_tap_c_();
}

algo

bsearch_int32_c

int32_t const* bsearch_int32_c( cInt32Slice slice, int32_t val );

Via the macro BSEARCH_C_ implemented function.

cmp_int32_slice_c

int cmp_int32_slice_c( cInt32Slice a, cInt32Slice b );

Via the macro CMP_SLICE_C_ implemented function.

count_eq_int32_c

int64_t count_eq_int32_c( cInt32Slice slice, int32_t val );

Via the macro COUNT_EQ_C_ implemented function.

find_int32_c

int32_t const* find_int32_c( cInt32Slice slice, int32_t val );

Via the macro FIND_VAL_C_ implemented function.

max_int32_c

int32_t const* max_int32_c( cInt32Slice slice );

Via the macro FIND_MAX_C_ implemented function.

min_int32_c

int32_t const* min_int32_c( cInt32Slice slice );

Via the macro FIND_MIN_C_ implemented function.

prod_int32_c

bool prod_int32_c( cInt32Slice slice, int64_t res[static 1] );

Builds the product all values in the slice and saves the result in res. Return false if a overflow occures, otherwise true.

qsort_int32_slice_c

void qsort_int32_slice_c( cVarInt32Slice slice );

Via the macro QSORT_C_ implemented function.

reverse_int32_slice_c

void reverse_int32_slice_c( cVarInt32Slice slice );

Via the macro REVERSE_C_ implemented function.

rotate_int32_slice_c

void rotate_int32_slice_c( cVarInt32Slice slice, int64_t distance );

Via the macro ROTATE_C_ implemented function.

sum_int32_c

bool sum_int32_c( cInt32Slice slice, int64_t res[static 1] );

Builds the sum of all values in the slice and saves the result in res. Returns false if a overflow occures, otherwise true.