Dynabase¶
Documentation for
std-library/ksp/dynabase.ksp
Import¶
import "_IVLS/std-library/ksp/dynabase.ksp"API¶
Macros¶
| Name | Description |
|---|---|
dynabase.Functions(#name#) |
Generates utility functions for manipulating numbers in the dynamic base system. |
dynabase.ICB(#name#, #places#, #bases#) |
Declares storage and initializes a dynamic base number system with the given nam... |
Functions¶
| Name | Description |
|---|---|
#name#.get_place(num, pl) -> return |
Extracts the value at a specific place from an encoded number. |
#name#.make_raw_at_place(v, pl) -> return |
Converts a digit value to its raw encoded form at a specific place. |
#name#.place_to_raw(num, pl) -> return |
Returns the raw contribution of a specific place to the total encoded number. |
#name#.recache() |
Recomputes the multiplication factor cache after base values have been modified. |
#name#.set_place(num, pl, v) |
Sets the value at a specific place within an encoded number. |
Dynamic Base Number System¶
dynabase.ICB(#name#, #places#, #bases#)¶
Declares storage and initializes a dynamic base number system with the given name prefix.
| Parameter | Description |
|---|---|
#name# |
text prefix for all generated identifiers |
#places# |
number of digit positions in the number system |
#bases# |
array containing the base (modulus) for each place; must have at least #places# elements |
Side effects:
| Name | Type | Purpose |
|---|---|---|
#name#_MAX_PLACES |
const int | Number of places in the number system |
#name#_bases |
int[] | Base (modulus) for each place |
#name#_factor_cache |
int[] | Precomputed multiplication factors for encoding/decoding |
#name#_factor |
int | Working variable for factor computation |
#name#_i |
int | Loop variable for initialization |
Notes: Must be followed by dynabase.Functions(#name#) to generate the utility function suite.
dynabase.Functions(#name#)¶
Generates utility functions for manipulating numbers in the dynamic base system.
Preconditions: Must be called after dynabase.ICB() with the same #name# prefix.
| Parameter | Description |
|---|---|
#name# |
text prefix matching the dynabase.ICB() call |
Side effects:
| Name | Type | Purpose |
|---|---|---|
#name#.recache() |
function | Recomputes multiplication factor cache |
#name#.set_place(num, pl, v) |
function | Sets value at a specific place in an encoded number |
#name#.get_place(num, pl) |
function | Extracts value at a specific place from an encoded number |
#name#.place_to_raw(num, pl) |
function | Returns raw contribution of a place |
#name#.make_raw_at_place(v, pl) |
function | Converts a digit value to its raw encoded form at a place |
#name#.recache()¶
Recomputes the multiplication factor cache after base values have been modified.
Notes: Call after modifying any element of #name#_bases to maintain cache coherence.
#name#.set_place(num, pl, v)¶
Sets the value at a specific place within an encoded number.
| Parameter | Type | Description |
|---|---|---|
num |
int | the encoded number to modify (modified in-place at call site) |
pl |
int | place index (0-based; 0 is least significant) |
v |
int | new value for this place (must be within the base range for that place) |
#name#.get_place(num, pl) -> return¶
Extracts the value at a specific place from an encoded number.
| Parameter | Type | Description |
|---|---|---|
num |
int | the encoded number to read from |
pl |
int | place index (0-based) |
Returns: return — value stored at the specified place
#name#.place_to_raw(num, pl) -> return¶
Returns the raw contribution of a specific place to the total encoded number.
| Parameter | Type | Description |
|---|---|---|
num |
int | the encoded number |
pl |
int | place index (0-based) |
Returns: return — portion of num contributed by the digit at place pl
#name#.make_raw_at_place(v, pl) -> return¶
Converts a digit value to its raw encoded form at a specific place.
| Parameter | Type | Description |
|---|---|---|
v |
int | the digit value to encode |
pl |
int | place index (0-based) |
Returns: return — raw integer contribution this value makes at the specified place
Example¶
// TODO: Add usage example