Skip to content

Inclusivity#23

Merged
tomijaga merged 3 commits into0.0.1from
inclusivity
Apr 13, 2025
Merged

Inclusivity#23
tomijaga merged 3 commits into0.0.1from
inclusivity

Conversation

@tomijaga
Copy link
Copy Markdown
Member

@tomijaga tomijaga commented Apr 13, 2025

Resolves #17

Resolved this issue by transforming the value before encoding it
For #gt([a, b]) we apply the function get_next_value(), that was added in the src/CandidMod/lib.mo file in this CR, to the last composite field so the bound becomes #eq([a, next(b)]). Because of the nature of composite keys, [a, next(b)] will always be greater than [a, b].

If b was #Nat(7) next(b) would be #Nat(8).
If it were #Blob([12, 32, 45]), the next(b) result would be #Blob([12, 32, 45, 1]). Because blobs are null terminated (ends with a 0) we add 1 instead of a zero at the end to prevent matching on blob values that are equal to the initial value.

For #lt([a, b]) we apply the function get_prev_value(), that was also added in the src/CandidMod/lib.mo file, to the last composite field so the bound becomes #eq([a, prev(b)]).
Here, if b were #Nat(7) the result of the prev function would be #Nat(6).
However, there is some nuance to take note of is b were a blob of example #Blob([12, 32, 45]).
At first glance it seems like #Blob([12, 32, 44]) is the next smallest value, but we need to consider the lexicographical ordering of the bytes.
If we compared #Blob([12, 32, 44, 5]) we will notice that it is less than b but greater than prev(b).
If we take the lexicographical ordering into account, the next smallest value is #Blob([12, 32, 44, 44, 44, 44, 44, 44, 44, ...]) with the last byte - 1 repeated to infinity. For this implementation we think it is enough to repeat the character 30 times (we picked this number arbitrarily).

There is one more edge case to consider. If the last byte in the blob was zero, we need pop the zero and return the remaining bytes.

@tomijaga tomijaga merged commit 07eb893 into 0.0.1 Apr 13, 2025
0 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inclusivity is ignored in indexed fields

1 participant