aarondb/algo/graph

Types

Typed outcomes for bounded global graph requests.

pub type GraphError {
  InvalidGraphLimit
  NodeBudgetExceeded
  EdgeBudgetExceeded
  IterationBudgetExceeded
  InvalidPageRankParameters
}

Constructors

  • InvalidGraphLimit
  • NodeBudgetExceeded
  • EdgeBudgetExceeded
  • IterationBudgetExceeded
  • InvalidPageRankParameters

Explicit local work limits for global graph algorithms.

Bounded global APIs construct at most max_edges selected reference edges, admit at most max_nodes endpoints, and reject PageRank requests above max_iterations. They return a typed error rather than producing a partial graph result.

pub type GraphLimits {
  GraphLimits(
    max_nodes: Int,
    max_edges: Int,
    max_iterations: Int,
  )
}

Constructors

  • GraphLimits(max_nodes: Int, max_edges: Int, max_iterations: Int)
pub type TarjanState {
  TarjanState(
    index: Int,
    indices: dict.Dict(fact.EntityId, Int),
    lowlinks: dict.Dict(fact.EntityId, Int),
    on_stack: set.Set(fact.EntityId),
    stack: List(fact.EntityId),
    components: dict.Dict(fact.EntityId, Int),
    comp_id: Int,
  )
}

Constructors

Typed outcomes for bounded traversal requests.

pub type TraversalError {
  InvalidLimit
  VisitBudgetExceeded
  ResultLimitExceeded
}

Constructors

  • InvalidLimit
  • VisitBudgetExceeded
  • ResultLimitExceeded

Explicit local work limits for graph traversals.

A limit counts visited nodes, including the starting node. Callers that need unbounded traversal must opt into it through the legacy APIs; new callers should use the bounded variants below.

pub type TraversalLimits {
  TraversalLimits(max_visits: Int, max_results: Int)
}

Constructors

  • TraversalLimits(max_visits: Int, max_results: Int)

Values

pub fn betweenness_centrality(
  state: state.DbState,
  edge_attr: String,
) -> dict.Dict(fact.EntityId, Float)
pub fn betweenness_centrality_bounded(
  state: state.DbState,
  edge_attr: String,
  limits: GraphLimits,
) -> Result(dict.Dict(fact.EntityId, Float), GraphError)

Runs directed Brandes centrality after enforcing local graph limits.

pub fn connected_components(
  state: state.DbState,
  edge_attr: String,
) -> dict.Dict(fact.EntityId, Int)
pub fn connected_components_bounded(
  state: state.DbState,
  edge_attr: String,
  limits: GraphLimits,
) -> Result(dict.Dict(fact.EntityId, Int), GraphError)

Labels directed flood-fill components after enforcing local graph limits.

pub fn cycle_detect(
  state: state.DbState,
  edge_attr: String,
) -> List(List(fact.EntityId))
pub fn cycle_detect_bounded(
  state: state.DbState,
  edge_attr: String,
  limits: GraphLimits,
) -> Result(List(List(fact.EntityId)), GraphError)

Detects directed cycles after enforcing local graph limits.

pub fn graph_limits(
  max_nodes: Int,
  max_edges: Int,
  max_iterations: Int,
) -> Result(GraphLimits, GraphError)
pub fn neighbors_khop(
  state: state.DbState,
  from: fact.EntityId,
  edge_attr: String,
  max_depth: Int,
) -> List(fact.EntityId)
pub fn pagerank(
  state: state.DbState,
  attr: String,
  damping: Float,
  iterations: Int,
) -> dict.Dict(fact.EntityId, Float)
pub fn pagerank_bounded(
  state: state.DbState,
  attr: String,
  damping: Float,
  iterations: Int,
  limits: GraphLimits,
) -> Result(dict.Dict(fact.EntityId, Float), GraphError)
pub fn reachable(
  state: state.DbState,
  from: fact.EntityId,
  edge_attr: String,
) -> List(fact.EntityId)
pub fn reachable_bounded(
  state: state.DbState,
  from: fact.EntityId,
  edge_attr: String,
  limits: TraversalLimits,
) -> Result(List(fact.EntityId), TraversalError)
pub fn shortest_path(
  state: state.DbState,
  from: fact.EntityId,
  to: fact.EntityId,
  edge_attr: String,
  max_depth: option.Option(Int),
) -> option.Option(List(fact.EntityId))
pub fn strongly_connected_components(
  state: state.DbState,
  edge_attr: String,
) -> dict.Dict(fact.EntityId, Int)
pub fn strongly_connected_components_bounded(
  state: state.DbState,
  edge_attr: String,
  limits: GraphLimits,
) -> Result(dict.Dict(fact.EntityId, Int), GraphError)

Labels strongly connected components after enforcing local graph limits.

pub fn topological_sort(
  state: state.DbState,
  edge_attr: String,
) -> Result(List(fact.EntityId), List(fact.EntityId))
pub fn topological_sort_bounded(
  state: state.DbState,
  edge_attr: String,
  limits: GraphLimits,
) -> Result(
  Result(List(fact.EntityId), List(fact.EntityId)),
  GraphError,
)

Topologically sorts a bounded directed graph or returns typed budget errors.

pub fn traversal_limits(
  max_visits: Int,
  max_results: Int,
) -> Result(TraversalLimits, TraversalError)
Search Document