closuretable

package
v0.0.0-...-a23c0e6 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2015 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Child

type Child struct {
	Parent int64
	Child  int64
}

A Child is intended to be an ephemeral entity that gets validated and converted to a Relationship

type ClosureTable

type ClosureTable []Relationship

A ClosureTable should represent every direct-line relationship, including self-to-self

func New

func New(origin int64) *ClosureTable

func (*ClosureTable) AddChild

func (table *ClosureTable) AddChild(new Child) error

AddChild takes a Child, verifies that it is acceptable, verifies that the ClosureTable is suitable to accept a child, and then creates the appropriate Relationships within the ClosureTable to instantiate that child.

func (*ClosureTable) AddRelationship

func (table *ClosureTable) AddRelationship(r Relationship) error

Allows you to add relationships manually Note that this is unsafe, because it relies on you to get all relationships right, instead of building intermediary relationships for you

func (*ClosureTable) DeepestRelationships

func (table *ClosureTable) DeepestRelationships() ([]int, map[int][]Relationship)

Returns a map of the ID of each node along with its maximum depth

func (*ClosureTable) DepthOneRelationships

func (table *ClosureTable) DepthOneRelationships() []Relationship

Returns a map of the ID of each node along with its immediate parent

func (*ClosureTable) EntityExists

func (table *ClosureTable) EntityExists(id int64) bool

EntityExists asks if an entity of a given id exists in the closure table Entities that exist are guaranteed to appear at least once in ancestor and descendant thanks to the self relationship, so the choice of which one to inspect is arbitrary

func (*ClosureTable) GetAncestralRelationships

func (table *ClosureTable) GetAncestralRelationships(id int64) []Relationship

func (*ClosureTable) RootNodeId

func (table *ClosureTable) RootNodeId() (int64, error)

Return the id of the root node of the closure table. This method assumes that there can only be one root node.

func (*ClosureTable) Size

func (ct *ClosureTable) Size() int

func (*ClosureTable) TableToTree

func (table *ClosureTable) TableToTree(entries map[int64]interface{}) (*binarytree.Tree, error)

Takes map of entries whose keys are the same values as the IDs of the closure table entries Returns a well-formed *binarytree.Tree with those entries as values.

type Relationship

type Relationship struct {
	Ancestor   int64
	Descendant int64
	Depth      int
}

A Relationship is the fundamental unit of the closure table. A relationship is defined between every entry and itselft, its parent, and any of its parent's ancestors.

Jump to

Keyboard shortcuts

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