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 ¶
var ErrDuplicateID = errors.New("id alreary exists")
ErrDuplicateID triggers when given id already exists
var ErrInvalidParentID = errors.New("parent not found")
ErrInvalidParentID ...
Functions ¶
This section is empty.
Types ¶
type Graph ¶
Graph is in memory representation of hierarchy.
func Initialize ¶
Initialize creates a new graph object
func (*Graph) EmplaceNode ¶
EmplaceNode emplaces the given node into the graph. Updates the parent child relationship.
func (*Graph) GetChildren ¶
GetChildren returns all the childrens of a given node
func (*Graph) UpdateParent ¶
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.