Skip to content

james-spears/btree_dag

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Binary Tree Dag (btree_dag)

Branch Status

build test main
CodeBuild(build) CodeBuild(test) CodeBuild(main)

CodeBuild(main) Version badge Docs badge

This library is a minimal implementation of a directed acyclic graph (abstract data structure) by way of a single binary tree map (BTreeMap). This implementation is often referred to as an adjacency list.

The primary goals of this implementation are to be minimal and idiomatic to the Rust language. The alloc crate is the only dependency when compiled with default features and is not optional. As one might assume, alloc is required for reason the implementation relies on BTreeMap (and the BTreeSet wrapper).

Example

use crate::BTreeDAG;

fn main() {
    let mut dag: BTreeDAG<String> = BTreeDAG::new();
    // Add nodes.
    dag.add_vertex(String::from("Tarzan"));
    dag.add_vertex(String::from("Jane"));
    // Add a relationship.
    dag.add_edge(String::from("Tarzan"), String::from("Jane"));
    
    // Assert relationship now exists.
    assert!(dag.adjacdent(String::from("Tarzan"), String::from("Jane")));
    
    // Adding a bidirectional edge is not allowed.
    assert!(dag.add_edge(String::from("Jane"), String::from("Tarzan"))?.is_err());
}

Usage

Add the following to your Cargo.toml file:

[dependencies]
btree_dag = "0.1.0"

API

Please see the API for a full list of available methods.

License

This work is dually licensed under MIT OR Apache-2.0.

About

A generic DAG (directed acyclic graph) data structure library implemented in Rust.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages