int64

Overview

Modue with functions and types to work with int64_t values.

Types and Definitions

Generated

cInt64Slice

struct cInt64Slice
{
   int64_t s;
   int64_t const* v;
};
typedef struct cInt64Slice cInt64Slice;

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

/* init */
cInt64Slice int64_slice_c( int64_t s, int64_t const* v );
cInt64Slice make_int64_slice_c( int64_t const* beg, int64_t const* end );
cInt64Slice empty_int64_slice_c( void );
/* sub */
cInt64Slice left_int64_slice_c( cInt64Slice slice, int64_t maxLen );
cInt64Slice mid_int64_slice_c( cInt64Slice slice, int64_t index );
cInt64Slice right_int64_slice_c( cInt64Slice slice, int64_t maxLen );
cInt64Slice sub_int64_slice_c( cInt64Slice slice,
                               int64_t begIdx,
                               int64_t endIdx );

cVarInt64Slice

struct cVarInt64Slice
{
   int64_t s;
   int64_t* v;
};
typedef struct cVarInt64Slice cVarInt64Slice;

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

/* init */
cVarInt64Slice var_int64_slice_c( int64_t s, int64_t const* v );
cVarInt64Slice make_var_int64_slice_c( int64_t* beg, int64_t* end );
cVarInt64Slice empty_var_int64_slice_c( void );
/* sub */
cVarInt64Slice left_var_int64_slice_c( cVarInt64Slice slice, int64_t maxLen );
cVarInt64Slice mid_var_int64_slice_c( cVarInt64Slice slice, int64_t index );
cVarInt64Slice right_var_int64_slice_c( cVarInt64Slice slice, int64_t maxLen );
cVarInt64Slice sub_var_int64_slice_c( cVarInt64Slice slice,
                                      int64_t begIdx,
                                      int64_t endIdx );
/* var slice */
cInt64Slice as_int64_slice_c( cVarInt64Slice slice );
cVarInt64Slice cast_int64_slice_c( cVarInt64Slice slice, cInt64Slice sub );
int64_t set_int64_slice_c( cVarInt64Slice dst, cInt64Slice src );

cInt64Chunk

struct cInt64Chunk
{
   int64_t s;
   int64_t const* v;
   int64_t favSize;
   cInt64Slice slice;
};
typedef struct cInt64Chunk cInt64Chunk;

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_int64_chunk_c( cInt64Chunk chunk[static 1],
                              int64_t s,
                              cInt64Slice slice );
void init_front_int64_chunk_c( cInt64Chunk chunk[static 1],
                               int64_t s,
                               cInt64Slice slice );

cVarInt64Chunk

struct cVarInt64Chunk
{
   int64_t s;
   int64_t* v;
   int64_t favSize;
   cInt64Slice slice;
};
typedef struct cVarInt64Chunk cVarInt64Chunk;

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_int64_chunk_c( cVarInt64Chunk chunk[static 1],
                                  int64_t s,
                                  cVarInt64Slice slice );
void init_front_var_int64_chunk_c( cVarInt64Chunk chunk[static 1],
                                   int64_t s,
                                   cVarInt64Slice slice );

cInt64Window

struct cInt64Window
{
   int64_t s;
   int64_t const* v;
   int64_t favSize;
   cInt64Slice slice;
};
typedef struct cInt64Window cInt64Window;

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_int64_window_c( cInt64Window window[static 1],
                               int64_t s,
                               cInt64Slice slice );
void init_front_int64_window_c( cInt64Window window[static 1],
                                int64_t s,
                                cInt64Slice slice );

cVarInt64Window

struct cVarInt64Window
{
   int64_t s;
   int64_t* v;
   int64_t favSize;
   cVarInt64Slice slice;
};
typedef struct cVarInt64Window cVarInt64Window;

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_int64_window_c( cVarInt64Window window[static 1],
                                   int64_t s,
                                   cVarInt64Slice slice );
void init_front_var_int64_window_c( cVarInt64Window window[static 1],
                                    int64_t s,
                                    cVarInt64Slice slice );

Functions

overall

cmp_int64_c

int cmp_int64_c( int64_t a, int64_t b );

Compares two int64_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/int64.h"

int main( void )
{
   init_tap_c_();

   expect_lt_c_( cmp_int64_c( -9223372036854775807-1, 0 ) );
   expect_lt_c_( cmp_int64_c(                     -1, 0 ) );
   expect_eq_c_( cmp_int64_c(                      0, 0 ) );
   expect_gt_c_( cmp_int64_c(                      1, 0 ) );
   expect_gt_c_( cmp_int64_c(    9223372036854775807, 0 ) );

   return finish_tap_c_();
}

int64_c_

#define int64_c_( Value )

Macro function that casts the Value as int64_t.

conv

uint64_to_int64_c

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

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

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

int main( void )
{
   init_tap_c_();

   int64_t i64 = 0;

   // ----------------------------------------------------------------- uint64_t
   uint64_t u64 = 9223372036854775807; // INT64_MAX
   expect_c_( uint64_to_int64_c( u64, &i64 ) );
   expect_c_( i64 == 9223372036854775807 );

   ++u64;   // 9223372036854775808
   expect_c_( not uint64_to_int64_c( u64, &i64 ) );

   return finish_tap_c_();
}

swap

swap_int64_c

int64_t swap_int64_c( int64_t val );

Returns val with a changed byte order.

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

int main( void )
{
   init_tap_c_();

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

   return finish_tap_c_();
}

swap_int64_from_c

int64_t swap_int64_from_c( int64_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/int64.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_int64_from_c( 0x0123456789abcdef, sysOrder ) ==
                                 0x0123456789abcdef );

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

   return finish_tap_c_();
}

swap_int64_to_c

int64_t swap_int64_to_c( int64_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/int64.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_int64_to_c( 0x0123456789abcdef, sysOrder ) ==
                               0x0123456789abcdef );

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

   return finish_tap_c_();
}

math

hash_int64_c

uint64_t hash_int64_c( int64_t val );

Returns a hash value of the int64_t value.

next_pow2_int64_c

int64_t next_pow2_int64_c( int64_t val );

Returns the next power of two value.

algo

bsearch_int64_c

int64_t const* bsearch_int64_c( cInt64Slice slice, int64_t val );

Via the macro BSEARCH_C_ implemented function.

cmp_int64_slice_c

int cmp_int64_slice_c( cInt64Slice a, cInt64Slice b );

Via the macro CMP_SLICE_C_ implemented function.

count_eq_int64_c

int64_t count_eq_int64_c( cInt64Slice slice, int64_t val );

Via the macro COUNT_EQ_C_ implemented function.

find_int64_c

int64_t const* find_int64_c( cInt64Slice slice, int64_t val );

Via the macro FIND_VAL_C_ implemented function.

max_int64_c

int64_t const* max_int64_c( cInt64Slice slice );

Via the macro FIND_MAX_C_ implemented function.

min_int64_c

int64_t const* min_int64_c( cInt64Slice slice );

Via the macro FIND_MIN_C_ implemented function.

prod_int64_c

bool prod_int64_c( cInt64Slice 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_int64_slice_c

void qsort_int64_slice_c( cVarInt64Slice slice );

Via the macro QSORT_C_ implemented function.

reverse_int64_slice_c

void reverse_int64_slice_c( cVarInt64Slice slice );

Via the macro REVERSE_C_ implemented function.

rotate_int64_slice_c

void rotate_int64_slice_c( cVarInt64Slice slice, int64_t distance );

Via the macro ROTATE_C_ implemented function.

sum_int64_c

bool sum_int64_c( cInt64Slice 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.