0.5.5 • Published 2 years ago

overlapping-hierarchy v0.5.5

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years 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

2 years ago

0.5.3

2 years ago

0.5.5

2 years ago

0.5.2

2 years ago

0.5.1

2 years ago

0.4.3

2 years ago

0.3.1

2 years ago

0.1.11

2 years ago

0.1.10

2 years ago

0.1.9

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago