graph

package
v0.0.0-...-5802de0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2019 License: GPL-3.0 Imports: 2 Imported by: 3

Documentation

Overview

Package graph is inmemory representation for company hierarchy. All read requests are served from this package. It's consumers responsibility to update this package after any write call to persistent layer.

Index

Constants

This section is empty.

Variables

View Source
var ErrDuplicateID = errors.New("id alreary exists")

ErrDuplicateID triggers when given id already exists

View Source
var ErrInvalidParentID = errors.New("parent not found")

ErrInvalidParentID ...

Functions

This section is empty.

Types

type Graph

type Graph struct {
	Root  *Node
	Nodes map[string]*Node
}

Graph is in memory representation of hierarchy.

func Initialize

func Initialize(nodes []*Node) (*Graph, error)

Initialize creates a new graph object

func (*Graph) EmplaceNode

func (g *Graph) EmplaceNode(node *Node) error

EmplaceNode emplaces the given node into the graph. Updates the parent child relationship.

func (*Graph) GetChildren

func (g *Graph) GetChildren(id string) ([]*Node, error)

GetChildren returns all the childrens of a given node

func (*Graph) UpdateParent

func (g *Graph) UpdateParent(id, newPar string) error

UpdateParent sets the parent to parameter 'newPar'

type Node

type Node struct {
	ID       string `json:"id"`
	ParID    string `json:"pid"`
	Height   int    `json:"height"`
	Children map[string]*Node
}

Node is the building block of Graph. Node ID is chosen as the unique identifier for each node. Which is not the best practice, but will serve the given problem sufficiently.

func NewEmptyNode

func NewEmptyNode() Node

NewEmptyNode ...

Jump to

Keyboard shortcuts

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