uint32
Overview
Module with functions and types to work with uint32_t values.
Types and Definitions
Generated
cUint32Slice
struct cUint32Slice { int64_t s; uint32_t const* v; }; typedef struct cUint32Slice cUint32Slice;
Via the macros SLICE_DEF_C_ and SLICE_IMPL_C_ declared and implemented struct. The macros declare and implement also the following functions.
/* init */ cUint32Slice uint32_slice_c( int64_t s, uint32_t const* v ); cUint32Slice make_uint32_slice_c( uint32_t const* beg, uint32_t const* end ); cUint32Slice empty_uint32_slice_c( void ); /* sub */ cUint32Slice left_uint32_slice_c( cUint32Slice slice, int64_t maxLen ); cUint32Slice mid_uint32_slice_c( cUint32Slice slice, int64_t index ); cUint32Slice right_uint32_slice_c( cUint32Slice slice, int64_t maxLen ); cUint32Slice sub_uint32_slice_c( cUint32Slice slice, int64_t begIdx, int64_t endIdx );
cVarUint32Slice
struct cVarUint32Slice { int64_t s; uint32_t* v; }; typedef struct cVarUint32Slice cVarUint32Slice;
Via the macros SLICE_DEF_C_ and SLICE_IMPL_C_ declared and implemented struct. The macros declare and implement also the following functions.
/* init */ cVarUint32Slice var_uint32_slice_c( int64_t s, uint32_t const* v ); cVarUint32Slice make_var_uint32_slice_c( uint32_t* beg, uint32_t* end ); cVarUint32Slice empty_var_uint32_slice_c( void ); /* sub */ cVarUint32Slice left_var_uint32_slice_c( cVarUint32Slice slice, int64_t maxLen ); cVarUint32Slice mid_var_uint32_slice_c( cVarUint32Slice slice, int64_t index ); cVarUint32Slice right_var_uint32_slice_c( cVarUint32Slice slice, int64_t maxLen ); cVarUint32Slice sub_var_uint32_slice_c( cVarUint32Slice slice, int64_t begIdx, int64_t endIdx ); /* var slice */ cUint32Slice as_uint32_slice_c( cVarUint32Slice slice ); cVarUint32Slice cast_uint32_slice_c( cVarUint32Slice slice, cUint32Slice sub ); int64_t set_uint32_slice_c( cVarUint32Slice dst, cUint32Slice src );
cUint32Chunk
struct cUint32Chunk { int64_t s; uint32_t const* v; int64_t favSize; cUint32Slice slice; }; typedef struct cUint32Chunk cUint32Chunk;
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_uint32_chunk_c( cUint32Chunk chunk[static 1], int64_t s, cUint32Slice slice ); void init_front_uint32_chunk_c( cUint32Chunk chunk[static 1], int64_t s, cUint32Slice slice );
cVarUint32Chunk
struct cVarUint32Chunk { int64_t s; uint32_t* v; int64_t favSize; cUint32Slice slice; }; typedef struct cVarUint32Chunk cVarUint32Chunk;
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_uint32_chunk_c( cVarUint32Chunk chunk[static 1], int64_t s, cVarUint32Slice slice ); void init_front_var_uint32_chunk_c( cVarUint32Chunk chunk[static 1], int64_t s, cVarUint32Slice slice );
cUint32Window
struct cUint32Window { int64_t s; uint32_t const* v; int64_t favSize; cUint32Slice slice; }; typedef struct cUint32Window cUint32Window;
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_uint32_window_c( cUint32Window window[static 1], int64_t s, cUint32Slice slice ); void init_front_uint32_window_c( cUint32Window window[static 1], int64_t s, cUint32Slice slice );
cVarUint32Window
struct cVarUint32Window { int64_t s; uint32_t* v; int64_t favSize; cVarUint32Slice slice; }; typedef struct cVarUint32Window cVarUint32Window;
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_uint32_window_c( cVarUint32Window window[static 1], int64_t s, cVarUint32Slice slice ); void init_front_var_uint32_window_c( cVarUint32Window window[static 1], int64_t s, cVarUint32Slice slice );
Functions
overall
cmp_uint32_c
int cmp_uint32_c( uint32_t a, uint32_t b );
Compares two uint32_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 to b
#include "clingo/lang/expect.h" #include "clingo/type/uint32.h" int main( void ) { init_tap_c_(); expect_lt_c_( cmp_uint32_c( 0, 2147483647 ) ); expect_lt_c_( cmp_uint32_c( 2147483646, 2147483647 ) ); expect_eq_c_( cmp_uint32_c( 2147483647, 2147483647 ) ); expect_gt_c_( cmp_uint32_c( 2147483648, 2147483647 ) ); expect_gt_c_( cmp_uint32_c( 4294967295, 2147483647 ) ); return finish_tap_c_(); }
uint32_c_
#define uint32_c_( Value )
Macro function that casts the Value as uint32_t.
conv
int64_to_uint32_c
bool int64_to_uint32_c( int64_t src, uint32_t dst[static 1] );
Via the macro CONV_C_ implemented function. Returns true if the int64_t value can be represented in a uint32_t variable, otherwise false.
#include "clingo/lang/expect.h" #include "clingo/type/uint32.h" int main( void ) { init_tap_c_(); uint32_t u32 = 0; // ------------------------------------------------------------ max - int64_t int64_t i64 = 4294967295; // UINT32_MAX expect_c_( int64_to_uint32_c( i64, &u32 ) ); expect_c_( u32 == 4294967295 ); ++i64; // 4294967296 expect_c_( not int64_to_uint32_c( i64, &u32 ) ); // ------------------------------------------------------------ min - int32_t int32_t i32 = 0; expect_c_( int64_to_uint32_c( i32, &u32 ) ); expect_c_( u32 == 0 ); --i32; // -1 expect_c_( not int64_to_uint32_c( i32, &u32 ) ); return finish_tap_c_(); }
uint64_to_uint32_c
bool uint64_to_uint32_c( uint64_t src, uint32_t dst[static 1] );
Via the macro CONV_C_ implemented function. Returns true if the uint64_t value can be represented in a uint32_t variable, otherwise false.
#include "clingo/lang/expect.h" #include "clingo/type/uint32.h" int main( void ) { init_tap_c_(); uint32_t u32 = 0; // ----------------------------------------------------------------- uint64_t uint64_t u64 = 4294967295; // UINT32_MAX expect_c_( uint64_to_uint32_c( u64, &u32 ) ); expect_c_( u64 == 4294967295 ); ++u64; // 4294967296 expect_c_( not uint64_to_uint32_c( u64, &u32 ) ); return finish_tap_c_(); }
swap
swap_uint32_c
uint32_t swap_uint32_c( uint32_t val );
Returns val with a changed byte order.
#include "clingo/lang/expect.h" #include "clingo/type/uint32.h" int main( void ) { init_tap_c_(); expect_c_( swap_uint32_c( 0xb7af0000 ) == 0x0000afb7 ); return finish_tap_c_(); }
swap_uint32_from_c
uint32_t swap_uint32_from_c( uint32_t val, c_ByteOrder order );
Changes the byte order of val from a known order to the system order if necessary.
#include "clingo/lang/expect.h" #include "clingo/type/uint32.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_uint32_from_c( 0xb7af0000, sysOrder ) == 0xb7af0000 ); expect_c_( swap_uint32_from_c( 0xb7af0000, othOrder ) == 0x0000afb7 ); return finish_tap_c_(); }
swap_uint32_to_c
uint32_t swap_uint32_to_c( uint32_t val, c_ByteOrder order );
Changes the byte order of val from the system order to a known order if necessary.
#include "clingo/lang/expect.h" #include "clingo/type/uint32.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_uint32_to_c( 0xb7af0000, sysOrder ) == 0xb7af0000 ); expect_c_( swap_uint32_to_c( 0xb7af0000, othOrder ) == 0x0000afb7 ); return finish_tap_c_(); }
math
next_pow2_uint32_c
uint32_t next_pow2_uint32_c( uint32_t val );
Smallest power of 2 greater than val.
algo
cmp_uint32_slice_c
int cmp_uint32_slice_c( cUint32Slice a, cUint32Slice b );
Via the macro CMP_SLICE_C_ implemented function.
count_eq_uint32_c
int64_t count_eq_uint32_c( cUint32Slice slice, uint32_t val );
Via the macro COUNT_EQ_C_ implemented function.
find_uint32_c
uint32_t const* find_uint32_c( cUint32Slice slice, uint32_t val );
Via the macro FIND_VAL_C_ implemented function.
max_uint32_c
uint32_t const* max_uint32_c( cUint32Slice slice );
Via the macro FIND_MAX_C_ implemented function.
min_uint32_c
uint32_t const* min_uint32_c( cUint32Slice slice );
Via the macro FIND_MIN_C_ implemented function.
prod_uint32_c
bool prod_uint32_c( cUint32Slice slice, uint64_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_uint32_slice_c
void qsort_uint32_slice_c( cVarUint32Slice slice );
Via the macro QSORT_C_ implemented function.
reverse_uint32_slice_c
void reverse_uint32_slice_c( cVarUint32Slice slice );
Via the macro REVERSE_C_ implemented function.
rotate_uint32_slice_c
void rotate_uint32_slice_c( cVarUint32Slice slice, int64_t distance );
Via the macro ROTATE_C_ implemented function.
sum_uint32_c
bool sum_uint32_c( cUint32Slice slice, uint64_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.