ds

package
v0.0.10-rc1 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2020 License: Apache-2.0 Imports: 6 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 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.

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) 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.

type ReplyList

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

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

func NewReplyList

func NewReplyList(s store.ExtendedStore) (*ReplyList, error)

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

func (*ReplyList) IndexForID

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

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

func (*ReplyList) WithReplies

func (c *ReplyList) WithReplies(closure func(replies []ReplyData))

WithReplies executes an arbitrary closure with access to the replies stored inside of the ReplyList. The closure must not modify the slice that it is given.

Jump to

Keyboard shortcuts

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