Skip to content
/ KGraph Public

A Kotlin multi-platform library for graph data structures

License

Notifications You must be signed in to change notification settings

lamba92/KGraph

Repository files navigation

KGraph

KGraph provides an easy to use platform independent graph library. It bundles a convenient DSL to handle the creation of the graph on the go. At the moment, it compiles for:

  • JVM
  • JS
  • Android Native ARM32
  • Android Native ARM64
  • Linux X86_64

Other native builds will come as I figure out how to compile multi-platform.

Goals

  • add search algorithms, blind and heuristic driven
  • add multi-platform tests
  • allow serialization of nodes, edge and whole graph
  • save on file and load from file
  • platform specif graphic visualizations (help reeeaaaally wanted)
  • add Dokka wherever

Usage

KGraph is made by 3 main interfaces: Graph, Node and Edge.

Here an example for creating a graph using the provided DSL:

val g = graphBuilder {

    val n1 = node {
        id = "ciao"
        value = 20
    }

    val n2 = node {
        id = Random.randomString()
        value = HashMap<Int, String>()
    }

    bidirectionEdge {
        initialNode = n1
        arrivalNode = n2
        cost = 20.0
    }

    edge {
        initialNode = n1
        arrivalNode = n1
        cost = 13.123
    }
}

val (result, timeElapsed) = DepthFirstSearch(g, g.nodes.first(), "targetValue").compute()

Installing

Add the JitPack.io repository to the project build.grade:

repositories {
    maven { url 'https://jitpack.io' }
}

Then import the latest version in the build.gradle of the modules you need:

dependencies {
    implementation 'com.github.lamba92:kgraph:{latest_version}'
}

If using Gradle Kotlin DSL:

repositories {
    maven(url = "https://jitpack.io")
}
...
dependencies {
    implementation("com.github.lamba92.kgraph", "kgraph{-platform}", "{latest_version}")
}

The -platform placeholder should be replaced with:

  • -jvm
  • -js
  • -android_native_32
  • -android_native_64
  • -linuxx86_64

Leave it empty for common sources in common library.

About

A Kotlin multi-platform library for graph data structures

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages