kartographer

module
v0.0.0-...-b2afd5d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 8, 2024 License: Apache-2.0

README

kartographer

A Graph Library for Resolving Dependent Nodes

This package provides functionality for traversing and analyzing a dependency graph. The DependencyGraph struct and its methods allow for listing dependencies in various orders, including direct, recursive, top-down, and reverse dependencies.

Table of Contents

Installation

To use this package, you need to import it into your Go project. Make sure you have the following dependencies in your go.mod file:

import (
  graph "github.com/kdeps/kartographer/graph"
)

Usage

First, create a new DependencyGraph instance by calling the NewDependencyGraph function with the appropriate parameters.

import (
    graph "github.com/kdeps/kartographer/graph"
)

dependencies := map[string][]string{
    "A": {"B", "C"},
    "B": {"D"},
    "C": {"D"},
    "D": {},
}

dg := graph.NewDependencyGraph(fs, logger, dependencies)

Then you can call any of the methods on the DependencyGraph instance to list dependencies in various orders.

dg.ListDirectDependencies("A")
dg.ListDependencyTree("A")
dg.ListDependencyTreeTopDown("A")
dg.ListReverseDependencies("D")

Functions

TraverseDependencyGraph

Traverses the dependency graph starting from a given node and prints the paths.

func (dg *DependencyGraph) TraverseDependencyGraph(node string, dependencies map[string][]string, visited map[string]bool)
ListDependencyTreeTopDown

Lists the dependency tree in a top-down order starting from a given node.

func (dg *DependencyGraph) ListDependencyTreeTopDown(node string)
ListDependenciesRecursive

Lists all dependencies recursively from a given node and prints each dependency path.

func (dg *DependencyGraph) ListDependenciesRecursive(node string, path []string, visited map[string]bool)
ListReverseDependencies

Lists all reverse dependencies for a given node.

func (dg *DependencyGraph) ListReverseDependencies(node string)
ListDependencyTree

Lists the entire dependency tree for a given node.

func (dg *DependencyGraph) ListDependencyTree(node string)
BuildDependencyStack

Builds and returns a stack of dependencies starting from a given node.

func (dg *DependencyGraph) BuildDependencyStack(node string, visited map[string]bool) []string
InvertDependencies

Inverts the dependency graph, swapping dependencies with their dependents.

func (dg *DependencyGraph) InvertDependencies() map[string][]string
ListDirectDependencies

Lists direct dependencies for a given node.

func (dg *DependencyGraph) ListDirectDependencies(node string)

Utility Functions

The package also includes utility functions for constructing or printing dependency paths.

ConstructDependencyPath

Construct a given dependency path which returns a string

func (dg *DependencyGraph) ConstructDependencyPath(path []string, dir string) string
PrintDependencyPath

Prints a given dependency path.

func (dg *DependencyGraph) PrintDependencyPath(path []string, dir string)

This function can be used to format and print paths in a human-readable form.


With this package, you can easily manage and traverse dependency graphs in Go, allowing for complex dependency analysis and visualization.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL