canscale / lexicographic-encoding

Lexicographic integer encoding in Motoko

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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"

About

Lexicographic integer encoding in Motoko

License:Apache License 2.0


Languages

Language:TypeScript 66.3%Language:Motoko 27.2%Language:Dhall 3.3%Language:Makefile 3.2%