I recently learned a very cute technique for storing arbitrary precision decimals between 0 and 1 as strings. This is useful for representing the index of items in a reorderable list because you can always make a new index in between two existing indexes (so long as you ensure each index is unique).<p>Creating a new index in between two indices and comparing two indices are both O(N), but the cute part is that the standard string comparison in JavaScript just works.<p>You just encode the digits after the decimal point. As in for "0.15" you encode "15". Except you do it in a big base, and to support concurrent edits you add some randomness to the midpoint operation (because this falls apart if two items have identical indexes)<p>I learned it from Evan Wallace's Blog (Figma, Esbuild). <a href="https://madebyevan.com/algos/crdt-fractional-indexing/" rel="nofollow noreferrer">https://madebyevan.com/algos/crdt-fractional-indexing/</a>
That is a first step towards an open source version of <a href="https://news.ycombinator.com/item?id=37328669">https://news.ycombinator.com/item?id=37328669</a>