ds

package
v0.0.13-rc3 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2020 License: Apache-2.0 Imports: 7 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 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 {
	*forest.Reply
	Community *forest.Community
	Author    *forest.Identity
}

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

Jump to

Keyboard shortcuts

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