|
Veritable Lasagna
An Allocator & Data Structure Library for C.
|
Include dependency graph for vl_algo.h:
This graph shows which files directly or indirectly include this file:Go to the source code of this file.
Macros | |
| #define | VL_MIN(a, b) ((a) < (b) ? (a) : (b)) |
| Returns the minimum of two values. | |
| #define | VL_MAX(a, b) ((a) > (b) ? (a) : (b)) |
| Returns the maximum of two values. | |
| #define | VL_ABS(x) ((x) < 0 ? -(x) : (x)) |
| Returns the absolute value of a number. | |
| #define | VL_CLAMP(x, min, max) VL_MAX(min, VL_MIN(x, max)) |
| Clamps a value between a minimum and maximum range. | |
Functions | |
| VL_API vl_uint_t | vlAlgoPopCount8 (vl_uint8_t value) |
| Counts the number of set bits (population count) in an 8-bit value. | |
| VL_API vl_uint_t | vlAlgoPopCount16 (vl_uint16_t value) |
| Counts the number of set bits (population count) in a 16-bit value. | |
| VL_API vl_uint_t | vlAlgoPopCount32 (vl_uint32_t value) |
| Counts the number of set bits (population count) in a 32-bit value. | |
| VL_API vl_uint_t | vlAlgoPopCount64 (vl_uint64_t value) |
| Counts the number of set bits (population count) in a 64-bit value. | |
| VL_API vl_uint_t | vlAlgoCLZ8 (vl_uint8_t value) |
| Counts the number of leading zero bits in an 8-bit value. | |
| VL_API vl_uint_t | vlAlgoCLZ16 (vl_uint16_t value) |
| Counts the number of leading zero bits in a 16-bit value. | |
| VL_API vl_uint_t | vlAlgoCLZ32 (vl_uint32_t value) |
| Counts the number of leading zero bits in a 32-bit value. | |
| VL_API vl_uint_t | vlAlgoCLZ64 (vl_uint64_t value) |
| Counts the number of leading zero bits in a 64-bit value. | |
| VL_API vl_uint_t | vlAlgoCTZ8 (vl_uint8_t value) |
| Counts the number of trailing zero bits in an 8-bit value. | |
| VL_API vl_uint_t | vlAlgoCTZ16 (vl_uint16_t value) |
| Counts the number of trailing zero bits in a 16-bit value. | |
| VL_API vl_uint_t | vlAlgoCTZ32 (vl_uint32_t value) |
| Counts the number of trailing zero bits in a 32-bit value. | |
| VL_API vl_uint_t | vlAlgoCTZ64 (vl_uint64_t value) |
| Counts the number of trailing zero bits in a 64-bit value. | |
| VL_API vl_uint_t | vlAlgoNextPO2 (vl_ularge_t value) |
| Computes the next power of 2 greater than or equal to the given value. | |
| VL_API vl_bool_t | vlAlgoIsPO2 (vl_ularge_t value) |
| Tests whether a value is a power of 2. | |
| VL_API vl_ularge_t | vlAlgoGCD (vl_ularge_t a, vl_ularge_t b) |
| Computes the Greatest Common Divisor (GCD) of two unsigned integers. | |
| VL_API vl_ularge_t | vlAlgoLCM (vl_ularge_t a, vl_ularge_t b) |
| Computes the Least Common Multiple (LCM) of two unsigned integers. | |
| VL_API vl_ilarge_t | vlAlgoGCDSigned (vl_ilarge_t a, vl_ilarge_t b) |
| Computes the Greatest Common Divisor (GCD) of two signed integers. | |
| VL_API vl_ilarge_t | vlAlgoLCMSigned (vl_ilarge_t a, vl_ilarge_t b) |
| Computes the Least Common Multiple (LCM) of two signed integers. | |
| VL_API vl_bool_t | vlAlgoAddOverflow (vl_ularge_t a, vl_ularge_t b) |
| Tests whether adding two unsigned integers would cause overflow. | |
| VL_API vl_bool_t | vlAlgoMulOverflow (vl_ularge_t a, vl_ularge_t b) |
| Tests whether multiplying two unsigned integers would cause overflow. | |
| VL_API vl_bool_t | vlAlgoSubUnderflow (vl_ularge_t a, vl_ularge_t b) |
| Tests whether subtracting two unsigned integers would cause underflow. | |
| #define VL_ABS | ( | x | ) | ((x) < 0 ? -(x) : (x)) |
Returns the absolute value of a number.
| x | input value |
Clamps a value between a minimum and maximum range.
| x | value to clamp |
| min | minimum allowed value |
| max | maximum allowed value |
| #define VL_MAX | ( | a, | |
| b | |||
| ) | ((a) > (b) ? (a) : (b)) |
Returns the maximum of two values.
| a | first value |
| b | second value |
| #define VL_MIN | ( | a, | |
| b | |||
| ) | ((a) < (b) ? (a) : (b)) |
Returns the minimum of two values.
██ ██ ██ █████ ███████ █████ ██████ ███ ██ █████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██ ██ ██ ██ ██ ███████ ███████ ███████ ██ ███ ██ ██ ██ ███████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ███████ ██ ██ ███████ ██ ██ ██████ ██ ████ ██ ██ ====—: A Data Structure and Algorithms library for C11. :—====
Copyright 2026 Jesse Walker, released under the MIT license. Git Repository: https://github.com/walkerje/veritable_lasagna
| a | first value |
| b | second value |
| VL_API vl_bool_t vlAlgoAddOverflow | ( | vl_ularge_t | a, |
| vl_ularge_t | b | ||
| ) |
Tests whether adding two unsigned integers would cause overflow.
Uses compiler intrinsics when available for optimal performance and accuracy. Falls back to portable overflow detection otherwise.
| a | first unsigned integer |
| b | second unsigned integer |
| VL_API vl_uint_t vlAlgoCLZ16 | ( | vl_uint16_t | value | ) |
Counts the number of leading zero bits in a 16-bit value.
Returns 16 if the input value is 0. Uses compiler intrinsics when available for optimal performance, with portable fallback implementations.
| value | 16-bit unsigned integer |
Here is the call graph for this function:| VL_API vl_uint_t vlAlgoCLZ32 | ( | vl_uint32_t | value | ) |
Counts the number of leading zero bits in a 32-bit value.
Returns 32 if the input value is 0. Uses compiler intrinsics when available for optimal performance, with portable fallback implementations.
| value | 32-bit unsigned integer |
Here is the caller graph for this function:| VL_API vl_uint_t vlAlgoCLZ64 | ( | vl_uint64_t | value | ) |
Counts the number of leading zero bits in a 64-bit value.
Returns 64 if the input value is 0. Uses compiler intrinsics when available for optimal performance, with portable fallback implementations.
| value | 64-bit unsigned integer |
Here is the call graph for this function:| VL_API vl_uint_t vlAlgoCLZ8 | ( | vl_uint8_t | value | ) |
Counts the number of leading zero bits in an 8-bit value.
Returns 8 if the input value is 0. Uses compiler intrinsics when available for optimal performance, with portable fallback implementations.
| value | 8-bit unsigned integer |
Here is the caller graph for this function:| VL_API vl_uint_t vlAlgoCTZ16 | ( | vl_uint16_t | value | ) |
Counts the number of trailing zero bits in a 16-bit value.
Returns 16 if the input value is 0. Uses compiler intrinsics when available for optimal performance, with portable fallback implementations.
| value | 16-bit unsigned integer |
Here is the call graph for this function:| VL_API vl_uint_t vlAlgoCTZ32 | ( | vl_uint32_t | value | ) |
Counts the number of trailing zero bits in a 32-bit value.
Returns 32 if the input value is 0. Uses compiler intrinsics when available for optimal performance, with portable fallback implementations.
| value | 32-bit unsigned integer |
Here is the caller graph for this function:| VL_API vl_uint_t vlAlgoCTZ64 | ( | vl_uint64_t | value | ) |
Counts the number of trailing zero bits in a 64-bit value.
Returns 64 if the input value is 0. Uses compiler intrinsics when available for optimal performance, with portable fallback implementations.
| value | 64-bit unsigned integer |
Here is the call graph for this function:| VL_API vl_uint_t vlAlgoCTZ8 | ( | vl_uint8_t | value | ) |
Counts the number of trailing zero bits in an 8-bit value.
Returns 8 if the input value is 0. Uses compiler intrinsics when available for optimal performance, with portable fallback implementations.
| value | 8-bit unsigned integer |
Here is the caller graph for this function:| VL_API vl_ularge_t vlAlgoGCD | ( | vl_ularge_t | a, |
| vl_ularge_t | b | ||
| ) |
Computes the Greatest Common Divisor (GCD) of two unsigned integers.
Uses the Euclidean algorithm for efficient computation. Handles edge cases where one or both inputs are zero appropriately.
| a | first unsigned integer |
| b | second unsigned integer |
Here is the caller graph for this function:| VL_API vl_ilarge_t vlAlgoGCDSigned | ( | vl_ilarge_t | a, |
| vl_ilarge_t | b | ||
| ) |
Computes the Greatest Common Divisor (GCD) of two signed integers.
Converts inputs to absolute values and delegates to the unsigned version. Handles the edge case of the most negative integer value safely.
| a | first signed integer |
| b | second signed integer |
Here is the call graph for this function:| VL_API vl_bool_t vlAlgoIsPO2 | ( | vl_ularge_t | value | ) |
Tests whether a value is a power of 2.
Returns VL_FALSE for input value 0, as 0 is not considered a power of 2. Uses efficient bit manipulation to perform the test.
VL_TRUE if the value is a power of 2, VL_FALSE otherwise.| value | input unsigned integer |
| VL_API vl_ularge_t vlAlgoLCM | ( | vl_ularge_t | a, |
| vl_ularge_t | b | ||
| ) |
Computes the Least Common Multiple (LCM) of two unsigned integers.
Uses the relationship LCM(a,b) = |a*b| / GCD(a,b) with overflow protection. Returns 0 if either input is 0 or if the result would overflow.
| a | first unsigned integer |
| b | second unsigned integer |
Here is the call graph for this function:
Here is the caller graph for this function:| VL_API vl_ilarge_t vlAlgoLCMSigned | ( | vl_ilarge_t | a, |
| vl_ilarge_t | b | ||
| ) |
Computes the Least Common Multiple (LCM) of two signed integers.
The result is always positive by mathematical definition. Converts inputs to absolute values and delegates to the unsigned version with overflow checking. Returns 0 if either input is 0 or if the result would overflow.
| a | first signed integer |
| b | second signed integer |
Here is the call graph for this function:| VL_API vl_bool_t vlAlgoMulOverflow | ( | vl_ularge_t | a, |
| vl_ularge_t | b | ||
| ) |
Tests whether multiplying two unsigned integers would cause overflow.
Uses compiler intrinsics when available for optimal performance and accuracy. Falls back to portable overflow detection otherwise.
| a | first unsigned integer |
| b | second unsigned integer |
| VL_API vl_uint_t vlAlgoNextPO2 | ( | vl_ularge_t | value | ) |
Computes the next power of 2 greater than or equal to the given value.
If the input value is already a power of 2, it returns the same value. Returns 1 for input value 0. Returns 0 if the result would overflow.
vl_uint_t.| value | input unsigned integer |
| VL_API vl_uint_t vlAlgoPopCount16 | ( | vl_uint16_t | value | ) |
Counts the number of set bits (population count) in a 16-bit value.
Uses compiler intrinsics when available for optimal performance. Falls back to portable bit manipulation algorithms otherwise.
| value | 16-bit unsigned integer |
| VL_API vl_uint_t vlAlgoPopCount32 | ( | vl_uint32_t | value | ) |
Counts the number of set bits (population count) in a 32-bit value.
Uses compiler intrinsics when available for optimal performance. Falls back to portable bit manipulation algorithms otherwise.
| value | 32-bit unsigned integer |
Here is the caller graph for this function:| VL_API vl_uint_t vlAlgoPopCount64 | ( | vl_uint64_t | value | ) |
Counts the number of set bits (population count) in a 64-bit value.
Uses compiler intrinsics when available for optimal performance. Falls back to portable bit manipulation algorithms otherwise.
| value | 64-bit unsigned integer |
Here is the call graph for this function:| VL_API vl_uint_t vlAlgoPopCount8 | ( | vl_uint8_t | value | ) |
Counts the number of set bits (population count) in an 8-bit value.
Uses compiler intrinsics when available for optimal performance. Falls back to portable bit manipulation algorithms otherwise.
| value | 8-bit unsigned integer |
| VL_API vl_bool_t vlAlgoSubUnderflow | ( | vl_ularge_t | a, |
| vl_ularge_t | b | ||
| ) |
Tests whether subtracting two unsigned integers would cause underflow.
For unsigned integers, underflow occurs when the first operand is smaller than the second operand. Uses efficient comparison for detection.
| a | first unsigned integer |
| b | second unsigned integer |