Otzel.Content.Iomemo (otzel v0.3.2)

View Source

An efficient IO-list based string representation for OT operations.

Iomemo (IO-list with memoized length) stores strings as nested IO-lists along with precomputed length information. This provides O(1) size lookups and efficient splitting/concatenation operations that are common in OT.

Why IO-lists?

In collaborative editing, strings are frequently split and concatenated. Standard Elixir strings require copying the entire string for these operations. IO-lists allow structural sharing, making these operations much more efficient for large documents.

Structure

  • :s - The string data as an IO-list
  • :l - Memoized length information matching the IO-list structure

Usage

Iomemo is the default string module. Strings are automatically converted:

# This creates an Iomemo internally
Otzel.insert("Hello World")

You can also create directly:

Otzel.Content.Iomemo.new("Hello World")

Configuration

To use standard strings instead:

config :otzel, :string_module, String

Summary

Functions

Callback implementation for Otzel.Content.as_binary/1.

Callback implementation for Otzel.Content.compose/2.

Callback implementation for Otzel.Content.diff/2.

Callback implementation for Otzel.Content.embed?/1.

Callback implementation for Otzel.Content.invert/2.

Creates a new Iomemo from a string or IO-list.

Callback implementation for Otzel.Content.size/1.

Callback implementation for Otzel.Content.take/2.

Callback implementation for Otzel.Content.transform/3.

Checks if the Iomemo's cached length is consistent with its content.

Types

len_list()

@type len_list() ::
  maybe_improper_list(
    non_neg_integer() | {non_neg_integer(), len_list()},
    non_neg_integer()
  )

str_list()

@type str_list() :: maybe_improper_list(String.t() | str_list(), String.t())

t()

@type t() :: %Otzel.Content.Iomemo{
  l: len_list() | non_neg_integer(),
  s: str_list() | String.t()
}

Functions

as_binary(iodata)

Callback implementation for Otzel.Content.as_binary/1.

compose(left, right)

Callback implementation for Otzel.Content.compose/2.

concatenate(list)

diff(a, b)

Callback implementation for Otzel.Content.diff/2.

embed?(_)

Callback implementation for Otzel.Content.embed?/1.

invert(_, _)

Callback implementation for Otzel.Content.invert/2.

merge_into(left, right)

Callback implementation for Otzel.Content.merge_into/2.

new(str)

Creates a new Iomemo from a string or IO-list.

Examples

iex> Otzel.Content.Iomemo.new("Hello")
%Otzel.Content.Iomemo{s: "Hello", l: 5}

size(map)

Callback implementation for Otzel.Content.size/1.

take(iomemo, count)

Callback implementation for Otzel.Content.take/2.

transform(_, _, _)

Callback implementation for Otzel.Content.transform/3.

well_formed?(iodata)

Checks if the Iomemo's cached length is consistent with its content.

Returns true if the memoized length matches the actual content length. Useful for debugging and validation.