0.5.5 • Published 9 months ago

overlapping-hierarchy v0.5.5

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

Overlapping hierarchy

Library for modeling overlapping hierarchy, in which nodes can have multiple parents.

Equivalent of transitively reduced directed acyclic graph, in which edges represent parenthood.

Example

A  B F  G
 \ | | /
   C H
 / | | \
D  E I  J
const hierarchy = new OverlappingHierarchy()
hierarchy.add('A')
hierarchy.add('B')
hierarchy.attach('A', 'C')
hierarchy.attach('B', 'C')
hierarchy.attach('C', 'D')
hierarchy.attach('C', 'E')
hierarchy.add('F')
hierarchy.add('G')
hierarchy.attach('F', 'H')
hierarchy.attach('G', 'H')
hierarchy.attach('H', 'I')
hierarchy.attach('H', 'J')

API

Initialization

const empty = new OverlappingHierarchy()

const cloned = new OverlappingHierarchy(source)

Mutation

hierarchy.add(node)

hierarchy.attach(parent, child)

hierarchy.detach(parent, child)

hierarchy.delete(node)

Traversal

hierarchy.nodes()

hierarchy.hierarchs()

hierarchy.children(parent)

hierarchy.parents(child)

hierarchy.descendants(ancestor)

hierarchy.ancestors(descendant)

Errors

LoopError

hierarchy.attach('A', 'A') // LoopError: Cannot add node to itself

CycleError

hierarchy.attach('D', 'A') // CycleError: Cannot add ancestor as a child

TransitiveReductionError

hierarchy.attach('A', 'D') // TransitiveReductionError: Cannot attach non-child descendant as a child
hierarchy.attach('A', 'B') // TransitiveReductionError: Cannot attach child whose descendant is a child of the parent
0.5.4

9 months ago

0.5.3

9 months ago

0.5.5

9 months ago

0.5.2

9 months ago

0.5.1

10 months ago

0.4.3

10 months ago

0.3.1

10 months ago

0.1.11

10 months ago

0.1.10

10 months ago

0.1.9

10 months ago

0.1.8

10 months ago

0.1.7

10 months ago

0.1.6

10 months ago

0.1.5

10 months ago

0.1.3

10 months ago

0.1.2

10 months ago

0.1.1

10 months ago

0.1.0

10 months ago