Skip to content

Signed Lexicographic Integer & Date encoders#40

Open
lejeunerenard wants to merge 7 commits intomainfrom
signed-lexint
Open

Signed Lexicographic Integer & Date encoders#40
lejeunerenard wants to merge 7 commits intomainfrom
signed-lexint

Conversation

@lejeunerenard
Copy link
Contributor

Lexicographic encoder for dates would be nice for range queries of timestamps. To support pre-epoch dates, a signed version of the lexint encoder was needed.

I initially opted to using the first byte for a boolean for whether the value is positive or not. But then adjusted a copy of the lexint (en/dec)coder so that it uses 1 bit from the first byte as the positive flag. This means the first byte can hold only a max magnitude of 122. The non-flag bits of negative numbers are flipped from their positive counterparts so the lexicographic ordering is preserved.

Adds a byte before the `lexint` encoding that denotes if it is positive
or negative.
Flipping the bits will preserve ordering for negative numbers.
Same as the `date` encoder, the date is encoded as milliseconds to
epoch, but with a signed lexicographic integer encoder instead of a
zig-zag integer encoder.

Added test with assertion that will fail to order two dates if using the
zig-zag encoder.
`signedLexint` was skipped since `lexint` isn't documented.
@lejeunerenard
Copy link
Contributor Author

Discovered a bug where signedLexint flips all bits when decoding including bytes after the signedLexint part of the buffer.

Included a test which uses the same buffer to encode a `lexdate` &
`string` to showcase and test that `signedLexint` (used via `lexdate`)
doesn't flip the bits after the date when decoding.
@lejeunerenard
Copy link
Contributor Author

Fixed the issue & added a test that uses the same buffer to (en/de)code a lexdate and string in that order. Before the fix, the test showed that the string couldn't be decoded as lexdate had flipped the buffer bits past it's bytes.

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.

1 participant