uint16

Overview

Module with functions and types to work with uint16_t values.

Types and Definitions

Generated

cUint16Slice

struct cUint16Slice
{
   int64_t s;
   uint16_t const* v;
};
typedef struct cUint16Slice cUint16Slice;

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

/* init */
cUint16Slice uint16_slice_c( int64_t s, uint16_t const* v );
cUint16Slice make_uint16_slice_c( uint16_t const* beg, uint16_t const* end );
cUint16Slice empty_uint16_slice_c( void );
/* sub */
cUint16Slice left_uint16_slice_c( cUint16Slice slice, int64_t maxLen );
cUint16Slice mid_uint16_slice_c( cUint16Slice slice, int64_t index );
cUint16Slice right_uint16_slice_c( cUint16Slice slice, int64_t maxLen );
cUint16Slice sub_uint16_slice_c( cUint16Slice slice,
                                 int64_t begIdx,
                                 int64_t endIdx );

cVarUint16Slice

struct cVarUint16Slice
{
   int64_t s;
   uint16_t* v;
};
typedef struct cVarUint16Slice cVarUint16Slice;

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

/* init */
cVarUint16Slice var_uint16_slice_c( int64_t s, uint16_t const* v );
cVarUint16Slice make_var_uint16_slice_c( uint16_t* beg, uint16_t* end );
cVarUint16Slice empty_var_uint16_slice_c( void );
/* sub */
cVarUint16Slice left_var_uint16_slice_c( cVarUint16Slice slice, int64_t maxLen );
cVarUint16Slice mid_var_uint16_slice_c( cVarUint16Slice slice, int64_t index );
cVarUint16Slice right_var_uint16_slice_c( cVarUint16Slice slice, int64_t maxLen );
cVarUint16Slice sub_var_uint16_slice_c( cVarUint16Slice slice,
                                        int64_t begIdx,
                                        int64_t endIdx );
/* var slice */
cUint16Slice as_uint16_slice_c( cVarUint16Slice slice );
cVarUint16Slice cast_uint16_slice_c( cVarUint16Slice slice, cUint16Slice sub );
int64_t set_uint16_slice_c( cVarUint16Slice dst, cUint16Slice src );

cUint16Chunk

struct cUint16Chunk
{
   int64_t s;
   uint16_t const* v;
   int64_t favSize;
   cUint16Slice slice;
};
typedef struct cUint16Chunk cUint16Chunk;

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_uint16_chunk_c( cUint16Chunk chunk[static 1],
                               int64_t s,
                               cUint16Slice slice );
void init_front_uint16_chunk_c( cUint16Chunk chunk[static 1],
                                int64_t s,
                                cUint16Slice slice );

cVarUint16Chunk

struct cVarUint16Chunk
{
   int64_t s;
   uint16_t* v;
   int64_t favSize;
   cUint16Slice slice;
};
typedef struct cVarUint16Chunk cVarUint16Chunk;

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_uint16_chunk_c( cVarUint16Chunk chunk[static 1],
                                   int64_t s,
                                   cVarUint16Slice slice );
void init_front_var_uint16_chunk_c( cVarUint16Chunk chunk[static 1],
                                    int64_t s,
                                    cVarUint16Slice slice );

cUint16Window

struct cUint16Window
{
   int64_t s;
   uint16_t const* v;
   int64_t favSize;
   cUint16Slice slice;
};
typedef struct cUint16Window cUint16Window;

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_uint16_window_c( cUint16Window window[static 1],
                                int64_t s,
                                cUint16Slice slice );
void init_front_uint16_window_c( cUint16Window window[static 1],
                                 int64_t s,
                                 cUint16Slice slice );

cVarUint16Window

struct cVarUint16Window
{
   int64_t s;
   uint16_t* v;
   int64_t favSize;
   cVarUint16Slice slice;
};
typedef struct cVarUint16Window cVarUint16Window;

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_uint16_window_c( cVarUint16Window window[static 1],
                                    int64_t s,
                                    cVarUint16Slice slice );
void init_front_var_uint16_window_c( cVarUint16Window window[static 1],
                                     int64_t s,
                                     cVarUint16Slice slice );

Functions

overall

cmp_uint16_c

int cmp_uint16_c( uint16_t a, uint16_t b );

Compares two uint16_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/uint16.h"

int main( void )
{
   init_tap_c_();

   expect_lt_c_( cmp_uint16_c(     0, 32767 ) );
   expect_lt_c_( cmp_uint16_c( 32766, 32767 ) );
   expect_eq_c_( cmp_uint16_c( 32767, 32767 ) );
   expect_gt_c_( cmp_uint16_c( 32768, 32767 ) );
   expect_gt_c_( cmp_uint16_c( 65535, 32767 ) );

   return finish_tap_c_();
}

uint16_c_

#define uint16_c_( Value )

Macro function that casts the Value as uint16_t.

conv

int64_to_uint16_c

bool int64_to_uint16_c( int64_t src, uint16_t dst[static 1] );

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

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

int main( void )
{
   init_tap_c_();

   uint16_t u16 = 0;

   // ------------------------------------------------------------ max - int32_t
   int32_t i32 = 65535; // UINT16_MAX
   expect_c_( int64_to_uint16_c( i32, &u16 ) );
   expect_c_( u16 == 65535 );

   ++i32;   // 65536
   expect_c_( not int64_to_uint16_c( i32, &u16 ) );

   // ------------------------------------------------------------ min - int16_t
   int16_t i16 = 0;
   expect_c_( int64_to_uint16_c( i16, &u16 ) );
   expect_c_( u16 == 0 );

   --i16;   // -1
   expect_c_( not int64_to_uint16_c( i16, &u16 ) );

   return finish_tap_c_();
}

uint64_to_uint16_c

bool uint64_to_uint16_c( uint64_t src, uint16_t dst[static 1] );

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

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

int main( void )
{
   init_tap_c_();

   uint16_t u16 = 0;

   // ----------------------------------------------------------------- uint32_t
   uint32_t u32 = 65535;   // UINT16_MAX
   expect_c_( uint64_to_uint16_c( u32, &u16 ) );
   expect_c_( u16 == 65535 );

   ++u32;   // 65536
   expect_c_( not uint64_to_uint16_c( u32, &u16 ) );

   return finish_tap_c_();
}

swap

swap_uint16_c

uint16_t swap_uint16_c( uint16_t val );

Returns val with a changed byte order.

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

int main( void )
{
   init_tap_c_();

   expect_c_( swap_uint16_c( 0x2080 ) ==
                             0x8020 );

   return finish_tap_c_();
}

swap_uint16_from_c

uint16_t swap_uint16_from_c( uint16_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/uint16.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_uint16_from_c( 0x2080, sysOrder ) ==
                                  0x2080 );

   expect_c_( swap_uint16_from_c( 0x2080, othOrder ) ==
                                  0x8020 );

   return finish_tap_c_();
}

swap_uint16_to_c

uint16_t swap_uint16_to_c( uint16_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/uint16.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_uint16_to_c( 0x2080, sysOrder ) ==
                                0x2080 );

   expect_c_( swap_uint16_to_c( 0x2080, othOrder ) ==
                                0x8020 );

   return finish_tap_c_();
}

algo

cmp_uint16_slice_c

int cmp_uint16_slice_c( cUint16Slice a, cUint16Slice b );

Via the macro CMP_SLICE_C_ implemented function.

count_eq_uint16_c

int64_t count_eq_uint16_c( cUint16Slice slice, uint16_t val );

Via the macro COUNT_EQ_C_ implemented function.

find_uint16_c

uint16_t const* find_uint16_c( cUint16Slice slice, uint16_t val );

Via the macro FIND_VAL_C_ implemented function.

max_uint16_c

uint16_t const* max_uint16_c( cUint16Slice slice );

Via the macro FIND_MAX_C_ implemented function.

min_uint16_c

uint16_t const* min_uint16_c( cUint16Slice slice );

Via the macro FIND_MIN_C_ implemented function.

prod_uint16_c

bool prod_uint16_c( cUint16Slice 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_uint16_slice_c

void qsort_uint16_slice_c( cVarUint16Slice slice );

Via the macro QSORT_C_ implemented function.

reverse_uint16_slice_c

void reverse_uint16_slice_c( cVarUint16Slice slice );

Via the macro REVERSE_C_ implemented function.

rotate_uint16_slice_c

void rotate_uint16_slice_c( cVarUint16Slice slice, int64_t distance );

Via the macro ROTATE_C_ implemented function.

sum_uint16_c

bool sum_uint16_c( cUint16Slice 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.