0.10.4 • Published 5 months ago

ordered-overlapping-hierarchy v0.10.4

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

OOH | Ordered Overlapping Hierarchy

Library for modeling overlapping hierarchy, in which members can have multiple parents and children are ordered.

It is transitively reduced multiply connected weighted directed acyclic graph with a single source. Edges represent parenthood and their weights represent order.

Example

    0
 / | | \
A  B F  G
 \ | | /
   C H
 / | | \
D  E I  J
const hierarchy = new OverlappingHierarchy('0')
hierarchy.relate([
    { parent: '0', child: 'A' },
    { parent: '0', child: 'B' },
    { parent: 'A', child: 'C' },
    { parent: 'B', child: 'C' },
    { parent: 'C', child: 'D' },
    { parent: 'C', child: 'E' },
    { parent: '0', child: 'F' },
    { parent: '0', child: 'G' },
    { parent: 'F', child: 'H' },
    { parent: 'G', child: 'H' },
    { parent: 'H', child: 'I' },
    { parent: 'H', child: 'J' }
])

API

Initialization

const hierarchy = new OverlappingHierarchy(hierarch)

const cloned = new OverlappingHierarchy(hierarchy)

Mutation

Relate

ℹ️ Relating all members at once is orders of magnitude faster than adding them one by one, as expensive transitive reduction is performed once per call.

hierarchy.relate([...]) relates batch of members and automatically removes transitive relationships.

hierarchy.relate([{ parent, child }]) // as last child

hierarchy.relate([{ parent, child, childIndex }]) // at specific index

hierarchy.relate([{ parent: 'A', child: 'A' }]) // LoopError: Cannot relate member to itself

hierarchy.relate([{ parent: 'D', child: 'A' }]) // CycleError: Cannot relate ancestor as a child

Unrelate

hierarchy.unrelate({ parent, child }) // removes child from parent

hierarchy.unrelate({ parent, child }) // deletes member without parents

hierarchy.unrelate({ parent: hierarchy.hierarch, child: hierarchy.hierarch }) // no-op

Traversal

.hierarch()

.members()

.relationships()

.children(member)

.descendants(member)

.parents(member)

.ancestors(member)

0.10.4

5 months ago

0.10.3

5 months ago

0.10.0

5 months ago

0.10.1

5 months ago

0.9.0

5 months ago

0.8.1

5 months ago

0.8.2

5 months ago

0.2.9

6 months ago

0.2.8

6 months ago

0.2.7

6 months ago

0.2.6

6 months ago

0.2.5

6 months ago

0.2.4

6 months ago

0.2.3

6 months ago

0.2.2

6 months ago

0.2.1

6 months ago

0.2.0

6 months ago

0.1.4

7 months ago

0.1.3

7 months ago

0.1.2

7 months ago

0.1.0

7 months ago