uint64

Overview

Module with functions and types to work with uint64_t values.

Types and Definitions

Generated

cUint64Slice

struct cUint64Slice
{
   int64_t s;
   uint64_t const* v;
};
typedef struct cUint64Slice cUint64Slice;

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

/* init */
cUint64Slice uint64_slice_c( int64_t s, uint64_t const* v );
cUint64Slice make_uint64_slice_c( uint64_t const* beg, uint64_t const* end );
cUint64Slice empty_uint64_slice_c( void );
/* sub */
cUint64Slice left_uint64_slice_c( cUint64Slice slice, int64_t maxLen );
cUint64Slice mid_uint64_slice_c( cUint64Slice slice, int64_t index );
cUint64Slice right_uint64_slice_c( cUint64Slice slice, int64_t maxLen );
cUint64Slice sub_uint64_slice_c( cUint64Slice slice,
                                 int64_t begIdx,
                                 int64_t endIdx );

cVarUint64Slice

struct cVarUint64Slice
{
   int64_t s;
   uint64_t* v;
};
typedef struct cVarUint64Slice cVarUint64Slice;

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

/* init */
cVarUint64Slice var_uint64_slice_c( int64_t s, uint64_t* v );
cVarUint64Slice make_var_uint64_slice_c( uint64_t* beg, uint64_t* end );
cVarUint64Slice empty_var_uint64_slice_c( void );
/* sub */
cVarUint64Slice left_var_uint64_slice_c( cVarUint64Slice slice, int64_t maxLen );
cVarUint64Slice mid_var_uint64_slice_c( cVarUint64Slice slice, int64_t index );
cVarUint64Slice right_var_uint64_slice_c( cVarUint64Slice slice, int64_t maxLen );
cVarUint64Slice sub_var_uint64_slice_c( cVarUint64Slice slice,
                                        int64_t begIdx,
                                        int64_t endIdx );
/* var slice */
cUint64Slice as_uint64_slice_c( cVarUint64Slice slice );
cVarUint64Slice cast_uint64_slice_c( cVarUint64Slice slice, cUint64Slice sub );
int64_t set_uint64_slice_c( cVarUint64Slice dst, cUint64Slice src );

cUint64Chunk

struct cUint64Chunk
{
   int64_t s;
   uint64_t const* v;
   int64_t favSize;
   cUint64Slice slice;
};
typedef struct cUint64Chunk cUint64Chunk;

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_uint64_chunk_c( cUint64Chunk chunk[static 1],
                               int64_t s,
                               cUint64Slice slice );
void init_front_uint64_chunk_c( cUint64Chunk chunk[static 1],
                                int64_t s,
                                cUint64Slice slice );

cVarUint64Chunk

struct cVarUint64Chunk
{
   int64_t s;
   uint64_t* v;
   int64_t favSize;
   cVarUint64Slice slice;
};
typedef struct cVarUint64Chunk cVarUint64Chunk;

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_uint64_chunk_c( cVarUint64Chunk chunk[static 1],
                                   int64_t s,
                                   cVarUint64Slice slice );
void init_front_var_uint64_chunk_c( cVarUint64Chunk chunk[static 1],
                                    int64_t s,
                                    cVarUint64Slice slice );

cUint64Window

struct cUint64Window
{
   int64_t s;
   uint64_t const* v;
   int64_t favSize;
   cUint64Slice slice;
};
typedef struct cUint64Window cUint64Window;

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_uint64_window_c( cUint64Window window[static 1],
                                int64_t s,
                                cUint64Slice slice );
void init_front_uint64_window_c( cUint64Window window[static 1],
                                 int64_t s,
                                 cUint64Slice slice );

cVarUint64Window

struct cVarUint64Window
{
   int64_t s;
   uint64_t* v;
   int64_t favSize;
   cVarUint64Slice slice;
};
typedef struct cVarUint64Window cVarUint64Window;

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_uint64_window_c( cVarUint64Window window[static 1],
                                    int64_t s,
                                    cVarUint64Slice slice );
void init_front_var_uint64_window_c( cVarUint64Window window[static 1],
                                     int64_t s,
                                     cVarUint64Slice slice );

Functions

overall

build_uint64_c_

#define build_uint64_c_( a, b )

Macro function that builds a uint64_t value by concatenating two uint32_t values.

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

int main( void )
{
   init_tap_c_();

   expect_c_( build_uint64_c_( 0x12345678, 0x90123456 ) ==
                               0x1234567890123456 );

   return finish_tap_c_();
}

cmp_uint64_c

int cmp_uint64_c( uint64_t a, uint64_t b );

Compares two uint64_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

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

int main( void )
{
   init_tap_c_();

   expect_lt_c_( cmp_uint64_c(                    0 , 9223372036854775807 ) );
   expect_lt_c_( cmp_uint64_c(  9223372036854775806 , 9223372036854775807 ) );
   expect_eq_c_( cmp_uint64_c(  9223372036854775807 , 9223372036854775807 ) );
   expect_gt_c_( cmp_uint64_c(  9223372036854775808U, 9223372036854775807 ) );
   expect_gt_c_( cmp_uint64_c( 18446744073709551615U, 9223372036854775807 ) );

   return finish_tap_c_();
}

uint64_c_

#define uint64_c_( Value )

Macro function that casts the Value as uint64_t.

conv

int64_to_uint64_c

bool int64_to_uint64_c( int64_t src, uint64_t dst[static 1] );

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

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

int main( void )
{
   init_tap_c_();

   uint64_t u64 = UINT64_MAX;

   // ------------------------------------------------------------------ int64_t
   int64_t i64 = 0;
   expect_c_( int64_to_uint64_c( i64, &u64 ) );
   expect_c_( i64 == 0 );

   --i64;
   expect_c_( not int64_to_uint64_c( i64, &u64 ) );

   return finish_tap_c_();
}

swap

swap_uint64_c

uint64_t swap_uint64_c( uint64_t val );

Returns val with a changed byte order.

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

int main( void )
{
   init_tap_c_();

   expect_c_( swap_uint64_c( 0x0123456789abcdef ) ==
                             0xefcdab8967452301 );

   return finish_tap_c_();
}

swap_uint64_from_c

uint64_t swap_uint64_from_c( uint64_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/uint64.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_uint64_from_c( 0x0123456789abcdef, sysOrder ) ==
                                  0x0123456789abcdef );

   expect_c_( swap_uint64_from_c( 0x0123456789abcdef, othOrder ) ==
                                  0xefcdab8967452301 );

   return finish_tap_c_();
}

swap_uint64_to_c

uint64_t swap_uint64_to_c( uint64_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/uint64.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_uint64_to_c( 0x0123456789abcdef, sysOrder ) ==
                                0x0123456789abcdef );

   expect_c_( swap_uint64_to_c( 0x0123456789abcdef, othOrder ) ==
                                0xefcdab8967452301 );

   return finish_tap_c_();
}

math

is_pow2_uint64_c

bool is_pow2_uint64_c( uint64_t val );

Check that returns true if val is an integral power of two, otherwise false.

Example

next_pow2_uint64_c

uint64_t next_pow2_uint64_c( uint64_t val );

Smallest power of 2 greater than val.

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

uint64_t check_range( uint64_t from, uint64_t exp )
{
   uint64_t val = from;
   for ( ; val <= exp; ++val )
   {
      if ( next_pow2_uint64_c( val ) != exp )
      {
         break;
      }
   }
   return val;
}

int main( void )
{
   init_tap_c_();

   expect_c_( check_range( 0, 0 ) == 1 );
   // --------------------------------------------------------------- first byte
   // HEX: oo oo oo oo oo oo oo o1 -> oo oo oo oo oo oo oo 8o
   expect_c_( check_range( 1, 1 ) == 2 );
   expect_c_( check_range( 2, 2 ) == 3 );
   expect_c_( check_range( 3, 4 ) == 5 );
   expect_c_( check_range( 5, 8 ) == 9 );

   expect_c_( check_range( 9, 16 ) == 17 );
   expect_c_( check_range( 17, 32 ) == 33 );
   expect_c_( check_range( 33, 64 ) == 65 );
   expect_c_( check_range( 65, 128 ) == 129 );

   // -------------------------------------------------------------- second byte
   // HEX: oo oo oo oo oo oo o1 oo -> oo oo oo oo oo oo 8o oo
   expect_c_( check_range( 129, 256 ) == 257 );
   expect_c_( check_range( 257, 512 ) == 513 );
   expect_c_( check_range( 513, 1024 ) == 1025 );
   expect_c_( check_range( 1025, 2048 ) == 2049 );

   expect_c_( check_range( 2049, 4096 ) == 4097 );
   expect_c_( check_range( 4097, 8192 ) == 8193 );
   expect_c_( check_range( 8193, 16384 ) == 16385 );
   expect_c_( check_range( 16385, 32768 ) == 32769 );

   // --------------------------------------------------------------- third byte
   // HEX: oo oo oo oo oo o1 oo oo -> oo oo oo oo oo 8o oo oo
   expect_c_( check_range( 32769, 65536 ) == 65537 );
   expect_c_( check_range( 65537, 131072 ) == 131073 );
   expect_c_( check_range( 131073, 262144 ) == 262145 );
   expect_c_( check_range( 262145, 524288 ) == 524289 );

   expect_c_( check_range( 524289, 1048576 ) == 1048577 );
   expect_c_( check_range( 1048577, 2097152 ) == 2097153 );
   expect_c_( check_range( 2097153, 4194304 ) == 4194305 );
   expect_c_( check_range( 4194305, 8388608 ) == 8388609 );

   return finish_tap_c_();
}

log2_uint64_c

uint8_t log2_uint64_c( uint64_t val );

Returns the binary (base-2) logarithm of val.

Example

algo

cmp_uint64_slice_c

int cmp_uint64_slice_c( cUint64Slice a, cUint64Slice b );

Via the macro CMP_SLICE_C_ implemented function.

count_eq_uint64_c

int64_t count_eq_uint64_c( cUint64Slice slice, uint64_t val );

Via the macro COUNT_EQ_C_ implemented function.

find_uint64_c

uint64_t const* find_uint64_c( cUint64Slice slice, uint64_t val );

Via the macro FIND_VAL_C_ implemented function.

max_uint64_c

uint64_t const* max_uint64_c( cUint64Slice slice );

Via the macro FIND_MAX_C_ implemented function.

min_uint64_c

uint64_t const* min_uint64_c( cUint64Slice slice );

Via the macro FIND_MIN_C_ implemented function.

prod_uint64_c

bool prod_uint64_c( cUint64Slice 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_uint64_slice_c

void qsort_uint64_slice_c( cVarUint64Slice slice );

Via the macro QSORT_C_ implemented function.

reverse_uint64_slice_c

void reverse_uint64_slice_c( cVarUint64Slice slice );

Via the macro REVERSE_C_ implemented function.

rotate_uint64_slice_c

void rotate_uint64_slice_c( cVarUint64Slice slice, int64_t distance );

Via the macro ROTATE_C_ implemented function.

sum_uint64_c

bool sum_uint64_c( cUint64Slice 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.