cRange
Overview
Module with functions and types to work with cRange values.
Types and Definitions
cRange
struct cRange { int64_t min; int64_t max; }; typedef struct cRange cRange;
A cRange is bounded inclusively below and above [min..max].
Generated
cRangeSlice
struct cRangeSlice { int64_t s; cRange const* v; }; typedef struct cRangeSlice cRangeSlice;
Via the macros SLICE_DEF_C_ and SLICE_IMPL_C_ declared and implemented struct. The macros declare and implement also the following functions.
/* init */ cRangeSlice range_slice_c( int64_t s, cRange const* v ); cRangeSlice make_range_slice_c( cRange const* beg, cRange const* end ); cRangeSlice null_range_slice_c( void ); /* sub */ cRangeSlice left_range_slice_c( cRangeSlice slice, int64_t maxLen ); cRangeSlice mid_range_slice_c( cRangeSlice slice, int64_t index ); cRangeSlice right_range_slice_c( cRangeSlice slice, int64_t maxLen ); cRangeSlice sub_range_slice_c( cRangeSlice slice, int64_t begIdx, int64_t endIdx);
cVarRangeSlice
struct cVarRangeSlice { int64_t s; cRange* v; }; typedef struct cVarRangeSlice cVarRangeSlice;
Via the macros SLICE_DEF_C_ and SLICE_IMPL_C_ declared and implemented struct. The macros declare and implement also the following functions.
/* init */ cVarRangeSlice var_range_slice_c( int64_t s, cRange* v ); cVarRangeSlice make_var_range_slice_c( cRange* beg, cRange* end ); cVarRangeSlice null_var_range_slice_c( void ); /* sub */ cVarRangeSlice left_var_range_slice_c( cVarRangeSlice slice, int64_t maxLen ); cVarRangeSlice mid_var_range_slice_c( cVarRangeSlice slice, int64_t index ); cVarRangeSlice right_var_range_slice_c( cVarRangeSlice slice, int64_t maxLen ); cVarRangeSlice sub_var_range_slice_c( cVarRangeSlice slice, int64_t begIdx, int64_t endIdx); /* var slice */ cVarRangeSlice as_var_range_slice_c( cVarRangeSlice slice ); cVarRangeSlice cast_var_range_slice_c( cVarRangeSlice slice, cRangeSlice sub ); int64_t set_range_slice_c( cVarRangeSlice dst, cRangeSlice src );
cRangeChunk
struct cRangeChunk { int64_t s; cRange const* v; int64_t favSize; cRangeSlice slice; } typedef struct cRangeChunk cRangeChunk;
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_range_chunk_c( cRangeChunk chunk[static 1], int64_t s, cRangeSlice slice ); void init_front_range_chunk_c( cRangeChunk chunk[static 1], int64_t s, cRangeSlice slice );
cVarRangeChunk
struct cVarRangeChunk { int64_t s; cRange* v; int64_t favSize; cVarRangeSlice slice; }; typedef struct cVarRangeChunk cVarRangeChunk;
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_range_chunk_c( cVarRangeChunk chunk[static 1], int64_t s, cVarRangeSlice slice ); void init_front_var_range_chunk_c( cVarRangeChunk chunk[static 1], int64_t s, cVarRangeSlice slice );
cRangeWindow
struct cRangeWindow { int64_t s; cRange const* v; cRangeSlice slice; }; typedef struct cRangeWindow cRangeWindow;
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_range_window_c( cRangeWindow window[static 1], int64_t s, cRangeSlice slice ); void init_front_range_window_c( cRangeWindow window[static 1], int64_t s, cRangeSlice slice );
cVarRangeWindow
struct cVarRangeWindow { int64_t s; cRange* v; cVarRangeSlice slice; }; typedef struct cVarRangeWindow cVarRangeWindow;
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_range_window_c( cVarRangeWindow window[static 1], int64_t s, cVarRangeSlice slice ); void init_front_var_range_window_c( cVarRangeWindow window[static 1], int64_t s, cVarRangeSlice slice );
Functions
init
closed_open_range_c_
#define closed_open_range_c_( Start, End )
Creates a half opened range [Start..End).
#include "clingo/lang/expect.h" #include "clingo/type/cRange.h" int main( void ) { init_tap_c_(); cRange range = closed_open_range_c_( -3, 3 ); expect_c_( range.min == -3 ); expect_c_( range.max == 2 ); return finish_tap_c_(); }
closed_range_c_
#define closed_range_c_( Start, End )
Creates a closed range [Start..End].
#include "clingo/lang/expect.h" #include "clingo/type/cRange.h" int main( void ) { init_tap_c_(); cRange range = closed_range_c_( -3, 3 ); expect_c_( range.min == -3 ); expect_c_( range.max == 3 ); return finish_tap_c_(); }
open_closed_range_c_
#define open_closed_range_c_( Start, End )
Creates a half opened range (Start..End].
#include "clingo/lang/expect.h" #include "clingo/type/cRange.h" int main( void ) { init_tap_c_(); cRange range = open_closed_range_c_( -3, 3 ); expect_c_( range.min == -2 ); expect_c_( range.max == 3 ); return finish_tap_c_(); }
open_range_c_
#define open_range_c_( Start, End )
Creates a open range (Start..End).
#include "clingo/lang/expect.h" #include "clingo/type/cRange.h" int main( void ) { init_tap_c_(); cRange rng = open_range_c_( -3, 3 ); expect_c_( rng.min == -2 ); expect_c_( rng.max == 2 ); return finish_tap_c_(); }
sized_range_c_
#define sized_range_c_( Start, Size )
Creates a range that uses Start as Min Value and contains Size values.
#include "clingo/lang/expect.h" #include "clingo/type/cRange.c" int main( void ) { init_tap_c_(); cRange range = sized_range_c_( -3, 7 ); expect_c_( range.min == -3 ); expect_c_( range.max == 3 ); return finish_tap_c_(); }
overall
clamp_into_range_c
int64_t clamp_into_range_c( cRange range, int64_t value );
Clamps the value into the defined range.
#include "clingo/lang/expect.h" #include "clingo/type/cRange.h" int main( void ) { init_tap_c_(); cRange range = { .min = 6, .max = 99 }; expect_c_( clamp_into_range_c( range, 1 ) == 6 ); expect_c_( clamp_into_range_c( range, 128 ) == 99 ); return finish_tap_c_(); }
eq_range_c
bool eq_range_c( cRange a, cRange b );
Returns true if both ranges are equal, otherwise false.
#include "clingo/lang/expect.h" #include "clingo/type/cRange.h" int main( void ) { init_tap_c_(); cRange a = { .min=22, .max=55 }; cRange b = { .min=22, .max=53 }; expect_c_( eq_range_c( a, a ) ); expect_c_( not eq_range_c( a, b ) ); return finish_tap_c_(); }
in_range_c
bool in_range_c( cRange range, int64_t value );
Returns true if the range contains value, otherwise false.
range_is_valid_c
bool range_is_valid_c( cRange range );
Returns true if the range is valid, otherwise false.
#include "clingo/lang/expect.h" #include "clingo/type/cRange.h" int main( void ) { init_tap_c_(); cRange valid = { .min = 0, .max = 10 }; expect_c_( range_is_valid_c( valid ) ); cRange invalid = { .min = 0, .max = -10 }; expect_c_( not range_is_valid_c( invalid ) ); return finish_tap_c_(); }
range_size_c
int64_t range_size_c( cRange range );
Returns the number of values the range contains.
#include "clingo/lang/expect.h" #include "clingo/type/cRange.h" int main( void ) { init_tap_c_(); cRange range = closed_range_c_( 18, 25 ); expect_c_( range_size_c( range ) == 8 ); range = sized_range_c_( 18, 8 ); expect_c_( range_size_c( range ) == 8 ); return finish_tap_c_(); }
shift_range_c
cRange shift_range_c( cRange range, int64_t distance );
Shifts the range forward(positive distance) or backwards(negative distance).
#include "clingo/lang/expect.h" #include "clingo/type/cRange.h" int main( void ) { init_tap_c_(); cRange range = closed_range_c_( 0, 9 ); cRange next = shift_range_c( range, range_size_c( range ) ); expect_c_( next.min == 10 ); expect_c_( next.max == 19 ); cRange prev = shift_range_c( range, -1 * range_size_c( range ) ); expect_c_( prev.min == -10 ); expect_c_( prev.max == -1 ); return finish_tap_c_(); }