Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/canscale/lexicographic-encoding
Lexicographic integer encoding in Motoko
https://github.com/canscale/lexicographic-encoding
Last synced: about 1 month ago
JSON representation
Lexicographic integer encoding in Motoko
- Host: GitHub
- URL: https://github.com/canscale/lexicographic-encoding
- Owner: canscale
- License: apache-2.0
- Created: 2022-09-27T19:05:04.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2022-10-02T01:23:47.000Z (about 2 years ago)
- Last Synced: 2024-08-03T00:14:19.053Z (5 months ago)
- Language: TypeScript
- Size: 77.1 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-motoko - lexicographic-encoding - Lexicographic (string sortable) integer encoding in Motoko. (Libraries / Encoding)
README
# lexicographic-encoding
A library for lexicographically encoding Integers
## Usage
```
import E "mo:encode/EncodeInt";let x: Int = 256;
let encoded = E.encodeInt(x);
```## Limitations
Currently this library is only able to reliably encode integers from **0** up to ~**1.7 * 10^13**, while maintaining equivalence with the JavaScript reference implementation in `reference/lexicographic-encoding.ts`
## Motivation
When converting numbers to strings, the same sort order is preserved. Lexicographic encodings of numbers preserve their sort order.
Additionally, this allows one to preserve sort order when associating number ids with strings, such as a user with id=256 becoming "user-fb05"