igraph

igraph graph algorithm library bindings for Kit

Files

FileDescription
.editorconfigEditor formatting configuration
.gitignoreGit ignore rules for build artifacts and dependencies
.tool-versionsasdf tool versions (Zig, Kit)
LICENSEMIT license file
README.mdThis file
c/kit_igraph.cC FFI wrapper
c/kit_igraph.hC header for FFI wrapper
examples/basic.kitBasic usage example
kit.tomlPackage manifest with metadata and dependencies
src/igraph.kitKit igraph - Graph algorithm library bindings
tests/igraph.test.kitTests for igraph

Dependencies

No Kit package dependencies.

Installation

kit add gitlab.com/kit-lang/packages/kit-igraph.git

System Requirements

PlatformCommand
macOSbrew install igraph
Ubuntusudo apt install libigraph-dev
Fedorasudo dnf install igraph-devel

Usage

import Kit.IGraph as Igraph

main = fn =>
  println ("igraph version: " ++ Igraph.version)

  # Create a graph with 5 vertices
  match Igraph.empty 5 false
    | Ok g ->
      Igraph.add-edge g 0 1
      Igraph.add-edge g 1 2
      Igraph.add-edge g 2 3
      Igraph.add-edge g 3 4
      Igraph.add-edge g 4 0

      println ("Vertices: " ++ (show (Igraph.vcount g)))
      println ("Edges: " ++ (show (Igraph.ecount g)))
      println ("Connected: " ++ (show (Igraph.is-connected? g)))
      Igraph.destroy g
    | Err e -> println ("Error: " ++ e)

  # Shortest paths
  match Igraph.empty 6 false
    | Ok g ->
      Igraph.add-edges g "0 1 1 2 2 3 3 4 4 5 0 3"
      len = Igraph.shortest-path-length g 0 5
      println ("Shortest 0->5: " ++ (show len) ++ " hops")
      path = Igraph.shortest-path g 0 5
      println ("Path: " ++ path)
      Igraph.destroy g
    | Err e -> println ("Error: " ++ e)

  # Graph metrics on a complete graph
  match Igraph.full 6 false
    | Ok g ->
      println ("Density: " ++ (show (Igraph.density g)))
      println ("Diameter: " ++ (show (Igraph.diameter g)))
      Igraph.destroy g
    | Err e -> println ("Error: " ++ e)

  # Centrality on a star graph
  match Igraph.star 5
    | Ok g ->
      println ("Degree: " ++ (Igraph.degree-all g))
      println ("Betweenness: " ++ (Igraph.betweenness g))
      println ("PageRank: " ++ (Igraph.pagerank g 0.85))
      Igraph.destroy g
    | Err e -> println ("Error: " ++ e)

main

Development

Running Examples

Run examples with the interpreter:

kit run examples/basic.kit

Compile examples to a native binary:

kit build examples/basic.kit && ./basic

Running Tests

Run the test suite:

kit test

Run the test suite with coverage:

kit test --coverage

Running kit dev

Run the standard development workflow (format, check, test):

kit dev

This will:

  1. Format and check source files in src/
  2. Run tests in tests/ with coverage

Generating Documentation

Generate API documentation from doc comments:

kit doc

Note: Kit sources with doc comments (##) will generate HTML documents in docs/*.html

Cleaning Build Artifacts

Remove generated files, caches, and build artifacts:

kit task clean

Note: Defined in kit.toml.

Local Installation

To install this package locally for development:

kit install

This installs the package to ~/.kit/packages/@kit/igraph/, making it available for import as Kit.IGraph in other projects.

License

This package is released under the MIT License - see LICENSE for details.

igraph is released under the GPL 2.0 License. Note: The GPL license may restrict use in proprietary applications.

Exported Functions & Types

empty

Create an empty graph with n vertices.

Parameters:

Returns:

Int -> Bool -> Result Ptr String

full

Create a complete (fully connected) graph with n vertices.

Int -> Bool -> Result Ptr String

ring

Create a ring graph with n vertices.

Int -> Bool -> Result Ptr String

star

Create a star graph with n vertices.

Int -> Result Ptr String

tree

Create a k-ary tree with n vertices.

Parameters:

    Int -> Int -> Result Ptr String

famous

Create a famous named graph (e.g., "Petersen", "Tutte", "Chvatal").

String -> Result Ptr String

erdos-renyi

Create an Erdos-Renyi random graph.

Parameters:

    Int -> Float -> Result Ptr String

destroy

Destroy a graph and release its memory.

Ptr -> Unit

vcount

Get the number of vertices in a graph.

Ptr -> Int

ecount

Get the number of edges in a graph.

Ptr -> Int

is-directed?

Check if a graph is directed.

Ptr -> Bool

is-connected?

Check if a graph is connected.

Ptr -> Bool

add-edge

Add an edge between two vertices.

Returns:

Ptr -> Int -> Int -> Result Unit String

add-edges

Add multiple edges at once from a space-separated string of vertex pairs.

Parameters:

    Ptr -> String -> Result Unit String

neighbors

Get the neighbors of a vertex as a space-separated string of vertex IDs.

Ptr -> Int -> String

degree

Get the degree of a vertex.

Ptr -> Int -> Int

shortest-path-length

Get the shortest path length between two vertices.

Returns -1 if no path exists.

Ptr -> Int -> Int -> Int

shortest-path

Get the shortest path between two vertices as a space-separated string.

Ptr -> Int -> Int -> String

all-shortest-path-lengths

Get all pairwise shortest path lengths as a flat space-separated string.

Ptr -> String

betweenness

Compute betweenness centrality for all vertices.

Ptr -> String

closeness

Compute closeness centrality for all vertices.

Ptr -> String

degree-all

Get degrees of all vertices as a space-separated string.

Ptr -> String

pagerank

Compute PageRank for all vertices.

Parameters:

    Ptr -> Float -> String

diameter

Get the diameter (longest shortest path) of the graph.

Ptr -> Float

density

Get the density of the graph (0.0 to 1.0).

Ptr -> Float

average-path-length

Get the average path length of the graph.

Ptr -> Float

girth

Get the girth (shortest cycle length) of the graph.

Ptr -> Int

community-label-propagation

Detect communities using label propagation.

Returns membership vector as space-separated integers.

Ptr -> String

connected-components-count

Get the number of connected components.

Ptr -> Int

connected-components

Get component membership as space-separated integers.

Ptr -> String

clique-number

Get the clique number (size of the largest clique).

Ptr -> Int

version

Get the igraph library version string.

String