Summary

Functions

Compares 2 Erlang tuples with the ordering defined by the tuple layer.

Encodes the tuple into a binary.

Encodes the prefix and tuple into a binary.

With versionstamps, encodes the tuple into a binary.

With versionstamps, encodes the prefix and tuple into a binary.

Returns a {StartKey, EndKey} pair of binaries that includes all possible sub-tuples.

With prefix, returns a {StartKey, EndKey} pair of binaries that includes all possible sub-tuples.

Decodes the binary into a tuple.

Decodes the binary into a prefix and tuple.

Types

-type elem() ::
          null |
          boolean() |
          binary() |
          {utf8, binary()} |
          integer() |
          float() |
          {float, float()} |
          {float, float_tag(), <<_:32>>} |
          {double, float_tag(), <<_:64>>} |
          {uuid, <<_:128>>} |
          {id64, integer()} |
          versionstamp() |
          tuple().
-type float_tag() :: denormalized | infinite | nan.
-type versionstamp() ::
          {versionstamp, Id :: non_neg_integer(), Batch :: non_neg_integer()} |
          {versionstamp, Id :: non_neg_integer(), Batch :: non_neg_integer(), Tx :: non_neg_integer()}.

Functions

-spec compare(tuple(), tuple()) -> -1 | 0 | 1.

Compares 2 Erlang tuples with the ordering defined by the tuple layer.

Return

  • 0 if both tuples compare as equal.
  • -1 if the left tuple is less than the right tuple.
  • 1 if the left tuple is greater than the right tuple.

Examples

The ordering isn't equivalent to the Erlang term ordering:

1> lists:sort(fun(A, B) -> erlfdb_tuple:compare(A, B) =< 0 end, [{1}, {null}]).
[{null},{1}]
2> lists:sort([{1}, {null}]).
[{1},{null}]
-spec pack(tuple()) -> binary().

Encodes the tuple into a binary.

Supported Erlang types

  • binary/0: Encodes as binary blob.
  • integer/0: Encodes as variable-length integer.
  • float/0: Encodes as 64-bit floating point (double).
  • tuple/0: Encodes as nested tuple.

Special types

  • null: Encodes as NULL char (16#0) instead of as an atom.
  • boolean/0: Encodes as a boolean instead of as an atom.
  • {utf8, Bin :: binary()}: Encodes Bin as UTF-8 string.
  • {float, float()}: Advanced floating point encoding. See erlfdb_float.
  • {float, _, float()}: Advanced floating point encoding. See erlfdb_float.
  • {double, _, float()}: Advanced floating point encoding. See erlfdb_float.
  • {uuid, binary()}: Encodes a binary of size == 16 as a UUID type.
  • {id64, integer()}: Encodes a fixed-length 64-bit integer.
  • {versionstamp, Id :: integer(), Batch :: integer()}: Versionstamp encoding. For unset versionstamps use pack_vs/1.
  • {versionstamp, Id :: integer(), Batch :: integer(), Tx}: Versionstamp encoding. For unset versionstamps use pack_vs/1.

Unsupported Erlang types

Examples

1> erlfdb_tuple:pack({}).
<<>>
1> erlfdb_tuple:pack({<<"hello">>, 42}).
<<1,104,101,108,108,111,0,21,42>>
-spec pack(tuple(), binary()) -> binary().

Encodes the prefix and tuple into a binary.

Examples

1> erlfdb_tuple:pack({}, <<"foo">>).
<<"foo">>
1> erlfdb_tuple:pack({<<"foo">>}, <<>>).
<<1,102,111,111,0>>
1> erlfdb_tuple:pack({<<"hello">>, 42}, <<"foo">>).
<<102,111,111,1,104,101,108,108,111,0,21,42>>
-spec pack_vs(tuple()) -> binary().

With versionstamps, encodes the tuple into a binary.

Special types

  • {versionstamp, Id, Batch}: Versionstamp encoding
  • {versionstamp, Id, Batch, Tx}: Versionstamp encoding
-spec pack_vs(tuple(), binary()) -> binary().

With versionstamps, encodes the prefix and tuple into a binary.

-spec range(tuple()) -> {binary(), binary()}.

Returns a {StartKey, EndKey} pair of binaries that includes all possible sub-tuples.

-spec range(tuple(), binary()) -> {binary(), binary()}.

With prefix, returns a {StartKey, EndKey} pair of binaries that includes all possible sub-tuples.

-spec unpack(binary()) -> tuple().

Decodes the binary into a tuple.

Examples

1> erlfdb_tuple:unpack(erlfdb_tuple:pack({})).
{}
1> erlfdb_tuple:unpack(erlfdb_tuple:pack({<<"hello">>, 42})).
{<<"hello">>,42}
-spec unpack(binary(), binary()) -> tuple().

Decodes the binary into a prefix and tuple.

Examples

1> erlfdb_tuple:unpack(erlfdb_tuple:pack({}, <<"foo">>), <<"foo">>).
{}
1> erlfdb_tuple:unpack(erlfdb_tuple:pack({<<"hello">>, 42}, <<"foo">>), <<"foo">>).
{<<"hello">>,42}