dsg

package module
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: Apache-2.0 Imports: 4 Imported by: 2

README

array* : 用一维数组保存高维数组, 以集中存储, 增加 cache 命中可能.
set : 集合.
link_set : 带链接的集合 (可遍历).
link_mat : 二维带链接的集合 (元素为二元组 (row, col), 可沿行列遍历).
graph : 有相图 (利用 link_mat 实现, 可遍历所有根节点, 叶节点, 入边和出边).
perf : PERF 工作图表, 用于发现关键节点和关键路径.
hash : 桶结构, 用于字典查询.
heap : 堆和优先队列, 可实现排序.
llist : 固定长度的栈与队列.
llist_dyn : 双链表结构, 可实现不固定长度的栈与队列.
avl : 平衡二叉树, 可实现搜索和范围查询.
savl : 固定最大节点数的平衡二叉树.
interface: 函数接口 (比较函数, 键值与 Value 类型定义).
dsg : 通用函数: 整数, 浮点数比较函数, IMin, 对特定类型的初始化函数.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Float64CompFunc

func Float64CompFunc(v1 Value, v2 Value) int

func FloatHeapSort

func FloatHeapSort(data []Value)

func HeapSort

func HeapSort(data []Value, cmf CompFunc)

堆排序: 从大到小.

func IMin added in v1.4.0

func IMin(v1 int, v2 int) int

func IndexArray1D added in v1.2.0

func IndexArray1D(data []float64, size []int) []float64

func IndexArray2D added in v1.2.0

func IndexArray2D(data []float64, size []int) [][]float64

func IndexArray3D added in v1.2.0

func IndexArray3D(data []float64, size []int) [][][]float64

func IndexArray4D added in v1.2.0

func IndexArray4D(data []float64, size []int) [][][][]float64

func IndexArray5D added in v1.2.0

func IndexArray5D(data []float64, size []int) [][][][][]float64

func IndexBArray1D added in v1.3.0

func IndexBArray1D(data []byte, size []int) []byte

func IndexBArray2D added in v1.3.0

func IndexBArray2D(data []byte, size []int) [][]byte

func IndexBArray3D added in v1.3.0

func IndexBArray3D(data []byte, size []int) [][][]byte

func IndexBArray4D added in v1.3.0

func IndexBArray4D(data []byte, size []int) [][][][]byte

func IndexBArray5D added in v1.3.0

func IndexBArray5D(data []byte, size []int) [][][][][]byte

func IndexIArray1D added in v1.3.0

func IndexIArray1D(data []int, size []int) []int

func IndexIArray2D added in v1.3.0

func IndexIArray2D(data []int, size []int) [][]int

func IndexIArray3D added in v1.3.0

func IndexIArray3D(data []int, size []int) [][][]int

func IndexIArray4D added in v1.3.0

func IndexIArray4D(data []int, size []int) [][][][]int

func IndexIArray5D added in v1.3.0

func IndexIArray5D(data []int, size []int) [][][][][]int

func IntCompFunc

func IntCompFunc(v1 Value, v2 Value) int

func IntHeapSort

func IntHeapSort(data []Value)

func LocToInd added in v1.2.0

func LocToInd(size []int, loc []int) int

func TotalSize added in v1.2.0

func TotalSize(size []int) int

Types

type AvlNode

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

func InitAvlNode

func InitAvlNode(v Value, comp_func CompFunc) *AvlNode

func (*AvlNode) Add

func (root *AvlNode) Add(v Value) (new_root *AvlNode, new_deeper int)

func (*AvlNode) BalanceLeft

func (root *AvlNode) BalanceLeft() *AvlNode

func (*AvlNode) BalanceRight

func (root *AvlNode) BalanceRight() *AvlNode

func (*AvlNode) FindLeftNeighbour added in v1.2.0

func (root *AvlNode) FindLeftNeighbour() *AvlNode

func (*AvlNode) FindRightNeighbour added in v1.2.0

func (root *AvlNode) FindRightNeighbour() *AvlNode

func (*AvlNode) GetHeight

func (root *AvlNode) GetHeight() int

func (*AvlNode) Print

func (root *AvlNode) Print(level int)

func (*AvlNode) Remove

func (root *AvlNode) Remove(v Value) (new_root *AvlNode, junk *AvlNode)

func (*AvlNode) RemoveLeftMostDescendant

func (root *AvlNode) RemoveLeftMostDescendant() (new_root *AvlNode, junk *AvlNode)

func (*AvlNode) RestoreLeftBalance

func (root *AvlNode) RestoreLeftBalance(oldbf int) *AvlNode

func (*AvlNode) RestoreRightBalance

func (root *AvlNode) RestoreRightBalance(oldbf int) *AvlNode

func (*AvlNode) Search added in v1.2.0

func (root *AvlNode) Search(v Value) (dir []int)

type AvlTree

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

func InitAvlTree

func InitAvlTree(comp_func CompFunc) *AvlTree

func InitFloatAvlTree

func InitFloatAvlTree() *AvlTree

func InitIntAvlTree

func InitIntAvlTree() *AvlTree

func (*AvlTree) Add

func (tr *AvlTree) Add(v Value)

func (*AvlTree) FollowPath added in v1.2.0

func (tr *AvlTree) FollowPath(path []int) *AvlNode

func (*AvlTree) Print

func (tr *AvlTree) Print()

func (*AvlTree) Remove

func (tr *AvlTree) Remove(v Value)

func (*AvlTree) Search added in v1.2.0

func (tr *AvlTree) Search(v Value) (dir []int)

func (*AvlTree) SearchRange added in v1.2.0

func (tr *AvlTree) SearchRange(v Value) (vc Value, vl Value, vr Value)

type Chain

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

* Hash 非叶节点结构, 若其子节点为叶节点, 则 len(sublist) = 0,

  • head 指向首个子节点, tail 指向最后一个子节点.
  • 若其子节点为非叶节点, 则 head = tail = nil, sublist 指向子节点数组,
  • n 为子节点个数.

type CompFunc

type CompFunc func(v1 Value, v2 Value) int

type DirGraph added in v1.3.0

type DirGraph struct {
	Node *LinkSet
	Edge *LinkMat
	Leaf *LinkSet
	Root *LinkSet
	// contains filtered or unexported fields
}

func InitDirGraph added in v1.3.0

func InitDirGraph(size int) *DirGraph

func LoadDirGraph added in v1.3.0

func LoadDirGraph(fin io.Reader) *DirGraph

func (*DirGraph) AddEdge added in v1.3.0

func (dg *DirGraph) AddEdge(i1, i2 int)

func (*DirGraph) AddNode added in v1.3.0

func (dg *DirGraph) AddNode(inode int)

func (*DirGraph) Expand added in v1.3.0

func (dg *DirGraph) Expand(size int)

func (*DirGraph) GetAllEdge added in v1.4.0

func (dg *DirGraph) GetAllEdge() [][]int

func (*DirGraph) GetAllNode added in v1.4.0

func (dg *DirGraph) GetAllNode() []int

func (*DirGraph) GetInEdge added in v1.4.0

func (dg *DirGraph) GetInEdge(inode int) []int

func (*DirGraph) GetOutEdge added in v1.4.0

func (dg *DirGraph) GetOutEdge(inode int) []int

func (*DirGraph) GetSize added in v1.3.0

func (dg *DirGraph) GetSize() int

func (*DirGraph) GetUnuseIndex added in v1.3.0

func (dg *DirGraph) GetUnuseIndex() int

func (*DirGraph) PrintRootLeaf added in v1.4.0

func (dg *DirGraph) PrintRootLeaf(fout io.Writer)

func (*DirGraph) RemoveEdge added in v1.3.0

func (dg *DirGraph) RemoveEdge(i1, i2 int)

func (*DirGraph) RemoveNode added in v1.3.0

func (dg *DirGraph) RemoveNode(inode int)

func (*DirGraph) Save added in v1.3.0

func (dg *DirGraph) Save(fout io.Writer)

type Hash

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

* Hash 结构

func InitHash

func InitHash(n int, ktoi KeyToIndexFunc, comp CompFunc) *Hash

func InitTreeHash

func InitTreeHash(n []int, ktoi KeyToIndexFunc, comp CompFunc) *Hash

func (*Hash) AddData

func (hash *Hash) AddData(key Value, value Value)

* 向 hash 中增加一个叶节点.

  • \param hash 待增加hash
  • \param key 增加节点的 key
  • \param value 增加节点的 value

func (*Hash) Clear

func (hash *Hash) Clear()

func (*Hash) GotoChain

func (hash *Hash) GotoChain(ind []int) *Chain

* 跳转到 hash 的某个非叶节点

  • \param ind 位置索引

func (*Hash) InitSubHash

func (hash *Hash) InitSubHash(ind []int, n int)

func (*Hash) RemoveData

func (hash *Hash) RemoveData(key Value)

* 删除 hash 中以 key 为索引的节点

  • \param hash 待删除节点所在的 hash
  • \param key 待删除节点的索引 (key)

func (*Hash) Search

func (hash *Hash) Search(key Value) (value Value)

* 核心函数, 利用 Hash 完成查找,

  • \param hash 已经建立好的 Hash
  • \param key 待查找的 key
  • \param value 返回查找得到的 value (nil: 没找到)

func (*Hash) SearchChain

func (hash *Hash) SearchChain(key Value) *Chain

* 通过 key 查找 hash 的某个非叶节点,

  • \param hash 待查找的 hash
  • \param key 用于查找的 key

func (*Hash) SearchNode

func (hash *Hash) SearchNode(key Value) (last *Node, pcc *Chain, result *Node)

* 通过 key 查找 hash 的某个叶节点,

  • \param hash 待查找的 hash
  • \param key 用于查找的 key
  • \param last 返回所得叶节点的前一个节点 (若为该树枝上的首个节点, 则返回 nil)
  • \param pcc 返回所得叶节点的父节点.
  • \param result 返回查找所得的节点.

type Heap

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

func InitFloatHeap

func InitFloatHeap() *Heap

func InitHeap

func InitHeap(cmf CompFunc) *Heap

func InitIntHeap

func InitIntHeap() *Heap

func (*Heap) Add

func (hp *Heap) Add(value Value)

* 向 heap 中添加元素

func (*Heap) Get

func (hp *Heap) Get(ind int) *Value

func (*Heap) GetLCInd

func (hp *Heap) GetLCInd(ind int) int

return -1 if no child

func (*Heap) GetParInd

func (hp *Heap) GetParInd(ind int) int

return -1 if no par (root)

func (*Heap) GetRCInd

func (hp *Heap) GetRCInd(ind int) int

return -1 if no child

func (*Heap) GetSize

func (hp *Heap) GetSize() int

func (*Heap) Pop

func (hp *Heap) Pop() (value Value)

* 删除 heap 的根元素

func (*Heap) Rebuild

func (hp *Heap) Rebuild(root int)

* 重建以索引 root 为根结点的子树重建堆

type Key

type Key interface{}

type KeyToIndexFunc

type KeyToIndexFunc func(key Key) (ind []int)

type LList

type LList struct {
	// contains filtered or unexported fields
}
滑动数组表

* LList 负责分配空间;

func InitLList

func InitLList(nbuf int) *LList

func (*LList) Flush

func (ll *LList) Flush()

func (*LList) Get

func (ll *LList) Get(ind int) (value *Value)

func (*LList) GetFirst

func (ll *LList) GetFirst() (value *Value)

func (*LList) GetLast

func (ll *LList) GetLast() (value *Value)

func (*LList) GetN

func (ll *LList) GetN() int

func (*LList) Pop

func (ll *LList) Pop() (value Value)

func (*LList) PopFirst

func (ll *LList) PopFirst() (value Value)

func (*LList) Push

func (ll *LList) Push(value Value) int

type LListD added in v1.2.0

type LListD []Value

func InitLListD added in v1.2.0

func InitLListD() *LListD

func (*LListD) Flush added in v1.2.0

func (ll *LListD) Flush()

func (*LListD) Get added in v1.2.0

func (ll *LListD) Get(ind int) (value *Value)

func (*LListD) GetFirst added in v1.2.0

func (ll *LListD) GetFirst() (value *Value)

func (*LListD) GetLast added in v1.2.0

func (ll *LListD) GetLast() (value *Value)

func (*LListD) GetN added in v1.2.0

func (ll *LListD) GetN() int

func (*LListD) Pop added in v1.2.0

func (ll *LListD) Pop() (value Value)

func (*LListD) PopFirst added in v1.2.0

func (ll *LListD) PopFirst() (value Value)

func (*LListD) Push added in v1.2.0

func (ll *LListD) Push(value Value)

type LinkMat added in v1.2.0

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

func InitLinkMat added in v1.2.0

func InitLinkMat(size int) *LinkMat

func InverseLinkMat added in v1.3.0

func InverseLinkMat(lm *LinkMat) (lm1 *LinkMat)

func LoadLinkMat added in v1.3.0

func LoadLinkMat(fin io.Reader) *LinkMat

func (*LinkMat) Clear added in v1.2.0

func (lm *LinkMat) Clear()

func (*LinkMat) ClearCol added in v1.4.0

func (lm *LinkMat) ClearCol(col int)

func (*LinkMat) ClearRow added in v1.4.0

func (lm *LinkMat) ClearRow(row int)

func (*LinkMat) ColTraverseForward added in v1.2.0

func (lm *LinkMat) ColTraverseForward()

func (*LinkMat) ColTraverseStart added in v1.2.0

func (lm *LinkMat) ColTraverseStart(col int)

func (*LinkMat) Expand added in v1.2.0

func (lm *LinkMat) Expand(size int)

func (*LinkMat) GetAllLabel added in v1.4.0

func (lm *LinkMat) GetAllLabel() [][]int

func (*LinkMat) GetCol added in v1.4.0

func (lm *LinkMat) GetCol(col int) []int

func (*LinkMat) GetColNum added in v1.2.0

func (lm *LinkMat) GetColNum(col int) int

func (*LinkMat) GetColTraverseLabel added in v1.2.0

func (lm *LinkMat) GetColTraverseLabel() (row, col int)

row = -1 if traverse to tail

func (*LinkMat) GetLabel added in v1.2.0

func (lm *LinkMat) GetLabel(row, col int) bool

func (*LinkMat) GetNum added in v1.2.0

func (lm *LinkMat) GetNum() int

func (*LinkMat) GetRow added in v1.4.0

func (lm *LinkMat) GetRow(row int) []int

func (*LinkMat) GetRowNum added in v1.2.0

func (lm *LinkMat) GetRowNum(row int) int

func (*LinkMat) GetRowTraverseLabel added in v1.2.0

func (lm *LinkMat) GetRowTraverseLabel() (row, col int)

col = -1 if traverse to tail

func (*LinkMat) GetSize added in v1.3.0

func (lm *LinkMat) GetSize() int

func (*LinkMat) GetTraverseLabel added in v1.2.0

func (lm *LinkMat) GetTraverseLabel() (row, col int)

return -1, -1 if traverse to tail

func (*LinkMat) RowTraverseForward added in v1.2.0

func (lm *LinkMat) RowTraverseForward()

func (*LinkMat) RowTraverseStart added in v1.2.0

func (lm *LinkMat) RowTraverseStart(row int)

func (*LinkMat) Save added in v1.3.0

func (lm *LinkMat) Save(fout io.Writer)

func (*LinkMat) Set added in v1.2.0

func (lm *LinkMat) Set(row int, col int)

func (*LinkMat) TraverseForward added in v1.2.0

func (lm *LinkMat) TraverseForward()

func (*LinkMat) TraverseStart added in v1.2.0

func (lm *LinkMat) TraverseStart()

func (*LinkMat) UnSet added in v1.2.0

func (lm *LinkMat) UnSet(row int, col int)

type LinkSet added in v1.2.0

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

func InitFullLinkSet added in v1.4.0

func InitFullLinkSet(size int) *LinkSet

func InitLinkSet added in v1.2.0

func InitLinkSet(size int) *LinkSet

func InverseLinkSet added in v1.3.0

func InverseLinkSet(ls *LinkSet) (ls_inv *LinkSet)

func LoadLinkSet added in v1.3.0

func LoadLinkSet(fin io.Reader) *LinkSet

func (*LinkSet) Clear added in v1.2.0

func (ls *LinkSet) Clear()

func (*LinkSet) DeleteCurrentTraverse added in v1.4.0

func (ls *LinkSet) DeleteCurrentTraverse()

func (*LinkSet) Expand added in v1.2.0

func (ls *LinkSet) Expand(size int)

func (*LinkSet) GetAllLabel added in v1.4.0

func (ls *LinkSet) GetAllLabel() []int

func (*LinkSet) GetFirstLabel added in v1.4.0

func (ls *LinkSet) GetFirstLabel() int

func (*LinkSet) GetLabel added in v1.2.0

func (ls *LinkSet) GetLabel(ind int) bool

func (*LinkSet) GetNum added in v1.2.0

func (ls *LinkSet) GetNum() int

func (*LinkSet) GetSize added in v1.3.0

func (ls *LinkSet) GetSize() int

func (*LinkSet) GetTraverseLabel added in v1.2.0

func (ls *LinkSet) GetTraverseLabel() int

return -1 if traverse to tail

func (*LinkSet) Save added in v1.3.0

func (ls *LinkSet) Save(fout io.Writer)

func (*LinkSet) Set added in v1.2.0

func (ls *LinkSet) Set(ind int)

func (*LinkSet) TraverseBackward added in v1.2.0

func (ls *LinkSet) TraverseBackward()

func (*LinkSet) TraverseEnd added in v1.2.0

func (ls *LinkSet) TraverseEnd()

func (*LinkSet) TraverseForward added in v1.2.0

func (ls *LinkSet) TraverseForward()

func (*LinkSet) TraverseStart added in v1.2.0

func (ls *LinkSet) TraverseStart()

func (*LinkSet) UnSet added in v1.2.0

func (ls *LinkSet) UnSet(ind int)

如果要删除正在遍历的元素, 则首先自动调用一次 LSTraverseForward

type Node

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

* Hash 叶节点结构

type PQueue

type PQueue Heap

func InitPQueue

func InitPQueue(cmf CompFunc) *PQueue

初始化优先队列

func (*PQueue) Add

func (pq *PQueue) Add(value Value)

向优先队列中添加元素

func (*PQueue) Flush

func (pq *PQueue) Flush()

清空优先队列

func (*PQueue) GetSize

func (pq *PQueue) GetSize() int

获得优先队列长度

func (*PQueue) Pop

func (pq *PQueue) Pop() (value Value)

从优先队列中取出最小元素 * \return -1: 队列空; 0: 成功

type PerfGraph added in v1.4.0

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

func InitPerfGraph added in v1.4.0

func InitPerfGraph(size int) *PerfGraph

func LoadPerfGraph added in v1.4.0

func LoadPerfGraph(fin io.Reader) *PerfGraph

func (*PerfGraph) AddEdge added in v1.4.0

func (pg *PerfGraph) AddEdge(from, to int, time int)

func (*PerfGraph) CalNodeTimeRange added in v1.4.0

func (pg *PerfGraph) CalNodeTimeRange()

func (*PerfGraph) Save added in v1.4.0

func (pg *PerfGraph) Save(fout io.Writer)

type SAvlNode added in v1.4.0

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

type SAvlTree added in v1.4.0

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

func InitFloatSAvlTree added in v1.4.0

func InitFloatSAvlTree(max_node int) *SAvlTree

func InitIntSAvlTree added in v1.4.0

func InitIntSAvlTree(max_node int) *SAvlTree

func InitSAvlTree added in v1.4.0

func InitSAvlTree(comp_func CompFunc, max_node int) *SAvlTree

func (*SAvlTree) Add added in v1.4.0

func (tr *SAvlTree) Add(v Value)

func (*SAvlTree) AddNode added in v1.4.0

func (tree *SAvlTree) AddNode(root int, v Value) (new_root, new_deeper int)

func (*SAvlTree) BalanceLeft added in v1.4.0

func (tr *SAvlTree) BalanceLeft(root int) int

func (*SAvlTree) BalanceRight added in v1.4.0

func (tr *SAvlTree) BalanceRight(root int) int

func (*SAvlTree) FindLeftNeighbour added in v1.4.0

func (tr *SAvlTree) FindLeftNeighbour(root int) int

func (*SAvlTree) FindRightNeighbour added in v1.4.0

func (tr *SAvlTree) FindRightNeighbour(root int) int

func (*SAvlTree) FollowPath added in v1.4.0

func (tr *SAvlTree) FollowPath(path []int) int

func (*SAvlTree) GetHeight added in v1.4.0

func (tr *SAvlTree) GetHeight() int

func (*SAvlTree) GetHeightNode added in v1.4.0

func (tr *SAvlTree) GetHeightNode(root int) int

func (*SAvlTree) InitSAvlNode added in v1.4.0

func (tree *SAvlTree) InitSAvlNode(v Value) int

func (*SAvlTree) Print added in v1.4.0

func (tr *SAvlTree) Print()

func (*SAvlTree) PrintNode added in v1.4.0

func (tr *SAvlTree) PrintNode(root, level int)

func (*SAvlTree) Remove added in v1.4.0

func (tr *SAvlTree) Remove(v Value)

func (*SAvlTree) RemoveLeftMostDescendant added in v1.4.0

func (tr *SAvlTree) RemoveLeftMostDescendant(root int) (new_root, junk int)

func (*SAvlTree) RemoveNode added in v1.4.0

func (tr *SAvlTree) RemoveNode(root int, v Value) (new_root, junk int)

func (*SAvlTree) RestoreLeftBalance added in v1.4.0

func (tr *SAvlTree) RestoreLeftBalance(root int, oldbf int) int

func (*SAvlTree) RestoreRightBalance added in v1.4.0

func (tr *SAvlTree) RestoreRightBalance(root int, oldbf int) int

func (*SAvlTree) Search added in v1.4.0

func (tr *SAvlTree) Search(v Value, dir []int) int

func (*SAvlTree) SearchNode added in v1.4.0

func (tr *SAvlTree) SearchNode(root int, v Value, dir []int) int

func (*SAvlTree) SearchRange added in v1.4.0

func (tr *SAvlTree) SearchRange(v Value, work_path []int) (vc Value, vl Value, vr Value)

type Set

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

func InitSet

func InitSet(size int) *Set

func LoadSet added in v1.4.0

func LoadSet(fload io.Reader) (set *Set)

func (*Set) Co

func (sres *Set) Co(s1 *Set)

func (*Set) CopyFrom

func (oset *Set) CopyFrom(sset *Set) (is_err bool)

func (*Set) Diff

func (sres *Set) Diff(s1 *Set, s2 *Set)

func (*Set) Empty

func (s1 *Set) Empty()

func (*Set) Full

func (s1 *Set) Full()

func (*Set) GetAllLabel

func (set *Set) GetAllLabel() (labels []int)

func (*Set) GetLabel

func (set *Set) GetLabel(ind int) bool

func (*Set) GetNLabel

func (set *Set) GetNLabel() int

func (*Set) GetSize

func (set *Set) GetSize() int

func (*Set) Inter

func (sres *Set) Inter(s1 *Set, s2 *Set)

func (*Set) IsEmpty

func (set *Set) IsEmpty() bool

func (*Set) Save

func (set *Set) Save(fsav io.Writer)

func (*Set) SetLabel

func (set *Set) SetLabel(ind int, label bool)

func (*Set) Union

func (sres *Set) Union(s1 *Set, s2 *Set)

type Value

type Value interface{}

Jump to

Keyboard shortcuts

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