Zog.SoA (Zog v0.1.0)

View Source

Build graphs for the native Zog (Zig) backend using arbitrary labels.

This module accumulates data into flat arrays that are ready to pass to Zigler NIFs.

Summary

Types

Graph type

Internal integer node id (maps to Zog's u32 index)

Any type can be used as a label

t()

Zog SoA struct

Functions

Adds an edge between two labeled nodes with a weight.

Adds a node with the given label.

Adds a simple edge with weight 1 between two labeled nodes.

Adds an unweighted edge (weight defaults to 1.0).

Returns all edges as {from_id, to_id, weight} tuples.

Returns all labels in insertion order.

Creates a new directed Zog SoA builder.

Returns the number of directed edges stored.

Gets or creates a node for the given label.

Converts a Yog.Graph into a Zog.SoA struct.

Converts a Graph (from libgraph) into a Zog.SoA struct.

Creates a builder from a list of labeled edges.

Creates a builder from a list of unweighted labeled edges.

Returns the label for a given internal id.

Returns the internal id for a given label.

Creates a new Zog SoA builder of the specified type.

Returns the number of nodes.

Extracts edges as parallel arrays suitable for NIF passing.

Converts the SoA struct back to a standard Yog.Graph.

Converts the SoA struct back to a Graph (from libgraph).

Creates a new undirected Zog SoA builder.

Types

graph_type()

@type graph_type() :: :directed | :undirected

Graph type

id()

@type id() :: non_neg_integer()

Internal integer node id (maps to Zog's u32 index)

label()

@type label() :: term()

Any type can be used as a label

t()

@type t() :: %Zog.SoA{
  edges: [{id(), id(), float()}],
  id_to_label: %{required(id()) => label()},
  integer_labels: boolean(),
  kind: graph_type(),
  label_to_id: %{required(label()) => id()},
  next_id: non_neg_integer(),
  nodes: [label()]
}

Zog SoA struct

Functions

add_edge(builder, from, to, weight)

@spec add_edge(t(), label(), label(), term()) :: t()

Adds an edge between two labeled nodes with a weight.

add_node(builder, label)

@spec add_node(t(), label()) :: t()

Adds a node with the given label.

add_simple_edge(builder, from, to)

@spec add_simple_edge(t(), label(), label()) :: t()

Adds a simple edge with weight 1 between two labeled nodes.

add_unweighted_edge(builder, from, to)

@spec add_unweighted_edge(t(), label(), label()) :: t()

Adds an unweighted edge (weight defaults to 1.0).

all_edges(so_a)

@spec all_edges(t()) :: [{id(), id(), float()}]

Returns all edges as {from_id, to_id, weight} tuples.

all_labels(so_a)

@spec all_labels(t()) :: [label()]

Returns all labels in insertion order.

directed()

@spec directed() :: t()

Creates a new directed Zog SoA builder.

edge_count(so_a)

@spec edge_count(t()) :: non_neg_integer()

Returns the number of directed edges stored.

ensure_node(builder, label)

@spec ensure_node(t(), label()) :: {t(), id()}

Gets or creates a node for the given label.

from_graph(graph)

@spec from_graph(Yog.graph()) :: t()

Converts a Yog.Graph into a Zog.SoA struct.

from_labeled(labeled)

@spec from_labeled(Yog.Builder.Labeled.t()) :: t()

Converts a Yog.Builder.Labeled into a Zog.SoA struct.

from_libgraph(libgraph)

@spec from_libgraph(Graph.t()) :: t()

Converts a Graph (from libgraph) into a Zog.SoA struct.

from_list(graph_type, edges)

@spec from_list(graph_type(), [{label(), label(), term()}]) :: t()

Creates a builder from a list of labeled edges.

from_unweighted_list(graph_type, edges)

@spec from_unweighted_list(graph_type(), [{label(), label()}]) :: t()

Creates a builder from a list of unweighted labeled edges.

id_to_label(so_a, id)

@spec id_to_label(t(), id()) :: label() | nil

Returns the label for a given internal id.

label_to_id(so_a, label)

@spec label_to_id(t(), label()) :: id() | nil

Returns the internal id for a given label.

new(graph_type)

@spec new(graph_type()) :: t()

Creates a new Zog SoA builder of the specified type.

node_count(so_a)

@spec node_count(t()) :: non_neg_integer()

Returns the number of nodes.

to_edge_arrays(so_a)

@spec to_edge_arrays(t()) :: {[id()], [id()], [float()]}

Extracts edges as parallel arrays suitable for NIF passing.

to_graph(so_a)

@spec to_graph(t()) :: Yog.graph()

Converts the SoA struct back to a standard Yog.Graph.

to_libgraph(builder)

@spec to_libgraph(t()) :: Graph.t()

Converts the SoA struct back to a Graph (from libgraph).

undirected()

@spec undirected() :: t()

Creates a new undirected Zog SoA builder.