Documentation ¶
Overview ¶
Package ds implements useful data structures for sprig.
Index ¶
- type AlphaReplyList
- func (r *AlphaReplyList) Contains(id *fields.QualifiedHash) (isContained bool)
- func (r *AlphaReplyList) FilterWith(f func(ReplyData) bool)
- func (r *AlphaReplyList) IndexForID(id *fields.QualifiedHash) (index int)
- func (r *AlphaReplyList) Insert(nodes ...ReplyData)
- func (s *AlphaReplyList) Len() int
- func (s *AlphaReplyList) Less(i, j int) bool
- func (s *AlphaReplyList) Sort()
- func (s *AlphaReplyList) Swap(i, j int)
- func (r *AlphaReplyList) WithReplies(f func(replies []ReplyData))
- type CommunityList
- type HiddenTracker
- func (h *HiddenTracker) Hide(id *fields.QualifiedHash, s store.ExtendedStore) error
- func (h *HiddenTracker) IsAnchor(id *fields.QualifiedHash) bool
- func (h *HiddenTracker) IsHidden(id *fields.QualifiedHash) bool
- func (h *HiddenTracker) NumDescendants(id *fields.QualifiedHash) int
- func (h *HiddenTracker) Process(node forest.Node)
- func (h *HiddenTracker) Reveal(id *fields.QualifiedHash)
- func (h *HiddenTracker) ToggleAnchor(id *fields.QualifiedHash, s store.ExtendedStore) error
- type IDSet
- type NodeFilter
- type NodeList
- type NodeSorter
- type ReplyData
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AlphaReplyList ¶ added in v0.0.12
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) 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
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
func (h *HiddenTracker) Hide(id *fields.QualifiedHash, s store.ExtendedStore) error
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 NodeList ¶
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.
type NodeSorter ¶
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.