types

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2019 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 IdTree

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

The IdTree is a collection of Ider objects in a tree structure. Objects must have a unique id within the structure. It is likely that each of your objects will need a pointer to the IdTree to manipulate it, but that is an implementation dependant thing

func NewIdTree

func NewIdTree() *IdTree

func (*IdTree) Add

func (t *IdTree) Add(parent Ider, child Ider)

Add an item to the tree.

func (*IdTree) Children

func (t *IdTree) Children(parent Ider) []Ider

func (*IdTree) Clear

func (t *IdTree) Clear()

func (*IdTree) Get

func (t *IdTree) Get(id string) Ider

func (*IdTree) GetAll

func (t *IdTree) GetAll() []Ider

GetAll returns a list of all the Ider items in the tree. Order is random.

func (*IdTree) Parent

func (t *IdTree) Parent(child Ider) Ider

func (*IdTree) Remove

func (t *IdTree) Remove(item Ider)

Removes the item from the tree and all its sub-itmes

func (*IdTree) RemoveChildren

func (t *IdTree) RemoveChildren(parent Ider)

Remove all child controls

func (*IdTree) Root

func (t *IdTree) Root(child Ider) Ider

Root returns the root of the branch that the given object is on

type Ider

type Ider interface {
	ID() string
}

Any object that returns a string id can be stored in the tree.

type LruCache

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

LruCache is a kind of LRU cache. Objects that are too old are removed, and if the cache is full, the oldest item(s) will be removed. When an item is set more than once, it is pushed to the end so its last to be removed. Limits are approximate, as garbage collecting will randomly happen. Also, in order to prevent memory thrashing, strict order is not preserved, but items will fall out more or less in LRU order. Someday we may offer a backing store version to extend the size of the cache to disk or some other kind of storage

func NewLruCache

func NewLruCache(maxItemCount int, ttl int64) *LruCache

Create and return a new cache. maxItemCount is the maximum number of items the cache can hold ttl is the age in seconds past when items will be removed

func (*LruCache) Get

func (o *LruCache) Get(key string) interface{}

Get returns the item based on its id. If not found, it will return nil.

func (*LruCache) Has

func (o *LruCache) Has(key string) (exists bool)

Has tests for the existence of the key

func (*LruCache) Set

func (o *LruCache) Set(key string, v interface{})

Puts the item into the cache, and updates its access time, pushing it to the end of the removal queue

type TreeNode

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

A kind of mixin for anything that controls child controls, which are all controls, but also the top level form or page Creates a parent/child tree of controls that is used by the drawing code to draw the controls

func (*TreeNode) AddChildNode

func (n *TreeNode) AddChildNode(c TreeNodeI)

addChildNode adds the given node as a child of the current node

func (*TreeNode) ChildNodes

func (n *TreeNode) ChildNodes() []TreeNodeI

func (*TreeNode) Init

func (n *TreeNode) Init(self TreeNodeI)

To correctly get to the top node, the top node must know about itself

func (*TreeNode) ParentNode

func (n *TreeNode) ParentNode() TreeNodeI

func (*TreeNode) RemoveAllChildNodes

func (n *TreeNode) RemoveAllChildNodes()

func (*TreeNode) RemoveChildNode

func (n *TreeNode) RemoveChildNode(c TreeNodeI)

The central removal function. Manages the entire remove process. Other removal functions should call here.

func (*TreeNode) SetParent

func (n *TreeNode) SetParent(p TreeNodeI)

func (*TreeNode) TopNode

func (n *TreeNode) TopNode() TreeNodeI

Return the top node in the hierarchy.

type TreeNodeI

type TreeNodeI interface {
	AddChildNode(TreeNodeI)
	RemoveAllChildNodes()
	RemoveChildNode(TreeNodeI)
	ParentNode() TreeNodeI
	SetParent(TreeNodeI)
	TopNode() TreeNodeI
	ChildNodes() []TreeNodeI
}

An interface and structure together that can turn any struct into a tree structure with parent/child relationships To use it, simply embed the TreeNode structure into another structure and call Init. This TreeNodeI structure will be convertable to the parent object

Jump to

Keyboard shortcuts

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