ZenoIndexingEx (zeno_indexing_ex v0.1.1)

View Source

To use this module, simply call generate_key/2 to generated an ordered key c that sorts lexicographically in between a and b, two ordered keys you'll provided as arguments.

Examples

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

And if you'd like to use it without having to pattern match the result

# iex> ZenoIndexingEx.generate_key!(nil, nil)
# "a0"
#
# iex> ZenoIndexingEx.generate_key!("a0", nil)
# "a1"

Order key format

Ordered keys (or order keys for short) are not just any strings (see t:order_key()), they are a concatenation of a two components:

  1. An integer component, i.e. a stringified integer
  2. An optional fractional component, a stringified fractional value

This order key format was first explained in Greenspan's notebook, specifically, his approach to fractional indexing algorithm with logarithmic key growth. In layman's terms, this order key format was designed to slow down the growth of keys as keys are inserted in and around existing keys.

TODO Integer component

Explain and define the format of the integer component and the optional fractional component.

TODO Fractional component

Summary

Functions

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

Generates an order key just like generate_key/2, but raises an error if the key generation fails.

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, error_code :: atom(), reason :: String.t()}

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

generate_key!(a, b)

Generates an order key just like generate_key/2, but raises an error if the key generation fails.