ZenoIndexingEx (zeno_indexing_ex v0.1.0)

View Source

ZenoIndexingEx's provides the generate_key/2 function to help you generate a fractional index (a string-based key), that sorts lexicographically in between two existing keys a and b.

Fractional indexes with logarithmic key growth

While there are a number of ways to generate an order key c that sorts in in between keys a and b, this particular module is an implementation of Greenspan's fractional indexing algorithm with logarithmic key growth, which itself an improvement on Evan Wallace's fractional indexing approach.

Examples

# iex> ZenoIndexingEx.generate_key(nil, nil)
# {:ok, "a0"}
#
#
# iex> ZenoIndexingEx.generate_key("a0", nil)
# {:ok, "a1"}

Key format

As described earlier, generate_key/2 accepts keys a, b, and generates key c; in other words, all keys accepted and generated by generate_key/2 must not only conform to order_key/0, but also, when set to a string, must be composed as follows:

"[integer_component][fractional_component]"

Summary

Functions

Generates an order key (i.e. a key that sorts lexicographically) in between the keys a and b.

Types

order_key()

@type order_key() :: String.t() | nil

Functions

generate_key(a, b)

@spec generate_key(order_key(), order_key()) ::
  {:ok, order_key()} | {:error, order_key()}

Generates an order key (i.e. a key that sorts lexicographically) in between the keys a and b.

has_trailing_zeroes?(key)