ds

package
v0.0.20-rc1 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package ds implements useful data structures for sprig.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AlphaReplyList added in v0.0.12

type AlphaReplyList struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

AlphaReplyList creates a thread-safe list of ReplyData that maintains its internal sort order and supports looking up the index of specific nodes. It enforces uniqueness on the nodes it contains

func (*AlphaReplyList) Contains added in v0.0.12

func (r *AlphaReplyList) Contains(id *fields.QualifiedHash) (isContained bool)

Contains returns whether the list currently contains the node with the given ID.

func (*AlphaReplyList) FilterWith added in v0.0.12

func (r *AlphaReplyList) FilterWith(f func(ReplyData) bool)

func (*AlphaReplyList) IndexForID added in v0.0.12

func (r *AlphaReplyList) IndexForID(id *fields.QualifiedHash) (index int)

IndexForID returns the index at which the given ID's data is stored. It is safe (and recommended) to call this function from within the function passed to WithReplies(), as otherwise the node may by moved by another goroutine between looking up its index and using it.

func (*AlphaReplyList) Insert added in v0.0.12

func (r *AlphaReplyList) Insert(nodes ...ReplyData)

Insert adds the ReplyData to the list and updates the list sort order

func (*AlphaReplyList) Len added in v0.0.12

func (s *AlphaReplyList) Len() int

func (*AlphaReplyList) Less added in v0.0.12

func (s *AlphaReplyList) Less(i, j int) bool

func (*AlphaReplyList) Sort added in v0.0.12

func (s *AlphaReplyList) Sort()

func (*AlphaReplyList) Swap added in v0.0.12

func (s *AlphaReplyList) Swap(i, j int)

func (*AlphaReplyList) WithReplies added in v0.0.12

func (r *AlphaReplyList) WithReplies(f func(replies []ReplyData))

WithReplies accepts a closure that it will run with access to the stored list of replies. It is invalid to access the replies list stored by a replyList except from within this closure. References to the slice are not valid after the closure returns, and using them will cause confusing bugs.

type CommunityList

type CommunityList struct {
	// contains filtered or unexported fields
}

CommunityList holds a sortable list of communities that can update itself automatically by subscribing to a store.ExtendedStore

func NewCommunityList

func NewCommunityList(s store.ExtendedStore) (*CommunityList, error)

NewCommunityList creates a CommunityList and subscribes it to the provided ExtendedStore. It will prepopulate the list with the contents of the store as well.

func (*CommunityList) IndexForID

func (c *CommunityList) IndexForID(id *fields.QualifiedHash) int

IndexForID returns the position of the node with the given `id` inside of the CommunityList, or -1 if it is not present.

func (*CommunityList) WithCommunities

func (c *CommunityList) WithCommunities(closure func(communities []*forest.Community))

WithCommunities executes an arbitrary closure with access to the communities stored inside of the CommunitList. The closure must not modify the slice that it is given.

type HiddenTracker added in v0.0.16

type HiddenTracker struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

HiddenTracker tracks which nodes have been manually hidden by a user. This is modeled as a set of "anchor" nodes, the desendants of which are not visible. Anchors themselves are visible, and can be used to reveal their descendants. HiddenTracker is safe for concurrent use.

func (*HiddenTracker) Hide added in v0.0.16

Hide makes the given ID into an anchor and hides its descendants.

func (*HiddenTracker) IsAnchor added in v0.0.16

func (h *HiddenTracker) IsAnchor(id *fields.QualifiedHash) bool

IsAnchor returns whether the provided node is serving as an anchor that hides its descendants.

func (*HiddenTracker) IsHidden added in v0.0.16

func (h *HiddenTracker) IsHidden(id *fields.QualifiedHash) bool

IsHidden returns whether the provided node should be hidden.

func (*HiddenTracker) NumDescendants added in v0.0.16

func (h *HiddenTracker) NumDescendants(id *fields.QualifiedHash) int

NumDescendants returns the number of hidden descendants for the given anchor node.

func (*HiddenTracker) Process added in v0.0.16

func (h *HiddenTracker) Process(node forest.Node)

Process ensures that the internal state of the HiddenTracker accounts for the provided node. This is primarily useful for nodes that were inserted into the store *after* their ancestor was made into an anchor. Each time a new node is received, it should be Process()ed.

func (*HiddenTracker) Reveal added in v0.0.16

func (h *HiddenTracker) Reveal(id *fields.QualifiedHash)

Reveal makes the given node no longer an anchor, thereby un-hiding all of its children.

func (*HiddenTracker) ToggleAnchor added in v0.0.16

func (h *HiddenTracker) ToggleAnchor(id *fields.QualifiedHash, s store.ExtendedStore) error

ToggleAnchor switches the anchor state of the given ID.

type IDSet added in v0.0.16

type IDSet struct {
	// contains filtered or unexported fields
}

IDSet implements basic set operations on node IDs. It is not safe for concurrent use.

func (*IDSet) Add added in v0.0.16

func (h *IDSet) Add(ids ...*fields.QualifiedHash)

Add inserts the list of IDs into the set.

func (*IDSet) Contains added in v0.0.16

func (h *IDSet) Contains(id *fields.QualifiedHash) bool

Contains returns whether the given ID is in the set.

func (*IDSet) Remove added in v0.0.16

func (h *IDSet) Remove(ids ...*fields.QualifiedHash)

Remove deletes the provided IDs from the set.

type NodeFilter

type NodeFilter func(forest.Node) forest.Node

type NodeList

type NodeList struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

NodeList implements a generic data structure for storing ordered lists of forest nodes.

func NewNodeList

func NewNodeList(filter NodeFilter, sort NodeSorter, initialize func() []forest.Node, s store.ExtendedStore) *NodeList

NewNodeList creates a nodelist subscribed to the provided store and initialized with the return value of initialize(). The nodes will be sorted using the provided sort function (via sort.Slice) and nodes will only be inserted into the list if the filter() function returns non-nil for them. The filter function may transform the data before inserting it. The filter function is also responsible for any deduplication.

func (*NodeList) IndexForID

func (n *NodeList) IndexForID(id *fields.QualifiedHash) int

IndexForID returns the position of the node with the given `id` inside of the CommunityList, or -1 if it is not present.

func (*NodeList) Insert added in v0.0.12

func (n *NodeList) Insert(nodes ...forest.Node)

func (*NodeList) WithNodes

func (n *NodeList) WithNodes(closure func(nodes []forest.Node))

WithNodes executes the provided closure with readonly access to the nodes managed by the NodeList. This is the only way to view the nodes, and is thread-safe.

type NodeSorter

type NodeSorter func(a, b forest.Node) bool

type ReplyData added in v0.0.9

type ReplyData struct {
	ID             *fields.QualifiedHash
	CommunityID    *fields.QualifiedHash
	CommunityName  string
	AuthorID       *fields.QualifiedHash
	AuthorName     string
	ParentID       *fields.QualifiedHash
	ConversationID *fields.QualifiedHash
	Depth          int
	CreatedAt      time.Time
	Content        string
	Metadata       *twig.Data
}

ReplyData holds the contents of a single reply and the major nodes that it references.

func (*ReplyData) Populate added in v0.0.12

func (r *ReplyData) Populate(reply forest.Node, store store.ExtendedStore) bool

populate populates the the fields of a ReplyData object from a given node and a store. It can be used on an unfilled ReplyData instance in place of a constructor. It returns false if the node cannot be processed into ReplyData

func (ReplyData) Serial added in v0.0.22

func (r ReplyData) Serial() list.Serial

Serial returns a unique identifier for this ReplyData which can be used for dynamic list state management.

Jump to

Keyboard shortcuts

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