gotype

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TreeByLevel added in v0.0.5

func TreeByLevel(root *BNode, fn func(root *BNode))

TreeByLevel 按层处理二叉树

Types

type AVLNode

type AVLNode struct {
	Data   int
	Height int
	Count  int
	Left   *AVLNode
	Right  *AVLNode
}

AVLNode AVL树 平衡数

func NewAVLNode

func NewAVLNode(data int) *AVLNode

type BNode

type BNode struct {
	Data       interface{}
	LeftChild  *BNode
	RightChild *BNode
}

BNode 二叉树定义

func ArrToSearchTree added in v0.0.5

func ArrToSearchTree(arr []int, start, end int) *BNode

ArrToSearchTree 有序数组处理成搜索二叉树

func NewBNode

func NewBNode() *BNode

type Element

type Element struct {
	Member string
	Score  float64
}

Element is a key-score pair

type GEdges

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

GEdges 图的边

func NewGEdges

func NewGEdges(weight int, from, to *GNode) *GEdges

type GNode

type GNode struct {
	Value int //node的值
	In    int //出度
	Out   int //入度
	Nexts *NodesMap
	Edges []*GEdges
}

GNode 图的node

func NewGNode

func NewGNode(value int) *GNode

NewGNode 新node

type Graph

type Graph struct {
	Nodes *NodesMap
	Edges *Set
	sync.RWMutex
}

func NewGraph

func NewGraph() *Graph

func (*Graph) BFSGraph added in v0.0.4

func (g *Graph) BFSGraph(node *GNode)

func (*Graph) DFSGraph

func (g *Graph) DFSGraph(node *GNode)

func (*Graph) FillGraph

func (g *Graph) FillGraph(meta [][]int)

FillGraph 将矩阵类型图边输入图中

example [][]int{ {1,2,3}, //1为from node 2为to node 3为weight

		  {2,5,7}
}

type LNode

type LNode struct {
	Data interface{}
	Next *LNode
}

LNode 链表定义

func NewLNode

func NewLNode() *LNode

type Level

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

Level aspect of a node

type LinkedQueue

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

func NewLinkedQueue

func NewLinkedQueue() *LinkedQueue

func (*LinkedQueue) DeQueue

func (p *LinkedQueue) DeQueue() interface{}

DeQueue 出队列,删除队列首元素

func (*LinkedQueue) EnQueue

func (p *LinkedQueue) EnQueue(e interface{})

EnQueue 入队列:把元素e加到队列尾

func (*LinkedQueue) GetBack

func (p *LinkedQueue) GetBack() interface{}

GetBack 取得队列尾元素

func (*LinkedQueue) GetFront

func (p *LinkedQueue) GetFront() interface{}

GetFront 取得队列首元素

func (*LinkedQueue) IsEmpty

func (p *LinkedQueue) IsEmpty() bool

IsEmpty 判断队列是否为空,如果为空返回true,否则返回false

func (*LinkedQueue) Size

func (p *LinkedQueue) Size() int

Size 获取栈中元素的个数

type LinkedStack

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

LinkedStack 链表所写的stack

func NewLinkedStack

func NewLinkedStack() *LinkedStack

func (*LinkedStack) IsEmpty

func (p *LinkedStack) IsEmpty() bool

func (*LinkedStack) Pop

func (p *LinkedStack) Pop() interface{}

func (*LinkedStack) Push

func (p *LinkedStack) Push(e interface{})

func (*LinkedStack) Size

func (p *LinkedStack) Size() int

func (*LinkedStack) Top

func (p *LinkedStack) Top() interface{}

type Maxheap added in v0.0.4

type Maxheap struct {
	Arr  []int
	Size int
}

func NewMaxheap added in v0.0.4

func NewMaxheap() *Maxheap

func (*Maxheap) HeapInsert added in v0.0.4

func (h *Maxheap) HeapInsert(value int)

HeapInsert 大跟堆生成

func (*Maxheap) Heapifiy added in v0.0.4

func (h *Maxheap) Heapifiy()

Heapifiy 调整成大根堆

type Minheap added in v0.0.4

type Minheap struct {
	Arr  []int
	Size int
}

func NewMinheap added in v0.0.4

func NewMinheap() *Minheap

func (*Minheap) HeapInsert added in v0.0.4

func (h *Minheap) HeapInsert(value int)

HeapInsert 小根堆

func (*Minheap) Heapifiy added in v0.0.4

func (h *Minheap) Heapifiy()

Heapifiy 小根堆调整

type NodesMap

type NodesMap struct {
	M map[int]*GNode
	sync.RWMutex
}

NodesMap 为查找方便使用map替代数组

func NewNodesMap

func NewNodesMap() *NodesMap

func (*NodesMap) Add

func (m *NodesMap) Add(gNode *GNode)

func (*NodesMap) Contains

func (m *NodesMap) Contains(key int) bool

Contains node是否存在

func (*NodesMap) Get

func (m *NodesMap) Get(key int) *GNode

func (*NodesMap) Put

func (m *NodesMap) Put(key int, gNode *GNode)

type Person added in v0.0.4

type Person struct {
	Age int
}

type Queue

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

func NewSliceQueue

func NewSliceQueue() *Queue

func (*Queue) DeQueue

func (p *Queue) DeQueue() interface{}

DeQueue 弹出头元素

func (*Queue) EnQueue

func (p *Queue) EnQueue(item interface{})

EnQueue 把新元素加入队列尾

func (*Queue) GetBack

func (p *Queue) GetBack() interface{}

GetBack 返回队列尾元素

func (*Queue) GetFront

func (p *Queue) GetFront() interface{}

GetFront 返回队列首元素

func (*Queue) IsEmpty

func (p *Queue) IsEmpty() bool

IsEmpty 判断队列是否为空

func (*Queue) List

func (p *Queue) List() []interface{}

List 队列中所有元素

func (*Queue) Remove

func (p *Queue) Remove(item interface{})

Remove 简单实现一个Remove

func (*Queue) Size

func (p *Queue) Size() int

Size 返回队列的大小

type RWMap added in v0.0.6

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

读写锁 map

func NewRWMap added in v0.0.6

func NewRWMap() *RWMap

NewRWMap 新建RWMap

func (*RWMap) Delete added in v0.0.6

func (m *RWMap) Delete(key interface{})

Delete 删除某个key

func (*RWMap) Get added in v0.0.6

func (m *RWMap) Get(key interface{}) (interface{}, bool)

Get 获取某个key的值

func (*RWMap) JsonMarshal added in v0.0.6

func (m *RWMap) JsonMarshal() ([]byte, error)

JsonMarshal json序列化

func (*RWMap) Set added in v0.0.6

func (m *RWMap) Set(key interface{}, val interface{})

Set 设置某个key的值

type ScoreBorder

type ScoreBorder struct {
	Inf     int8
	Value   float64
	Exclude bool
}

ScoreBorder represents range of a float value, including: <, <=, >, >=, +inf, -inf

func ParseScoreBorder

func ParseScoreBorder(s string) (*ScoreBorder, error)

ParseScoreBorder creates ScoreBorder from redis arguments

type Set

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

func NewSet

func NewSet() *Set

func (*Set) Add

func (s *Set) Add(item interface{})

func (*Set) Clear

func (s *Set) Clear()

func (*Set) Contains

func (s *Set) Contains(item interface{}) bool

func (*Set) IsEmpty

func (s *Set) IsEmpty() bool

func (*Set) Len

func (s *Set) Len() int

func (*Set) List

func (s *Set) List() []interface{}

func (*Set) Remove

func (s *Set) Remove(item interface{})

type SliceStack

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

SliceStack slice所写的stack

func NewSliceStack

func NewSliceStack() *SliceStack

func (*SliceStack) IsEmpty

func (p *SliceStack) IsEmpty() bool

IsEmpty 判断是否为空

func (*SliceStack) List

func (p *SliceStack) List() []interface{}

func (*SliceStack) Pop

func (p *SliceStack) Pop() interface{}

Pop 弹出栈元素

func (*SliceStack) Push

func (p *SliceStack) Push(t interface{})

Push Push栈元素

func (*SliceStack) Size

func (p *SliceStack) Size() int

Size 返回大小

func (*SliceStack) Top

func (p *SliceStack) Top() interface{}

Top 返回栈顶元素

type SortedSet

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

SortedSet is a set which keys sorted by bound score

func Make

func Make() *SortedSet

Make makes a new SortedSet

func (*SortedSet) Add

func (sortedSet *SortedSet) Add(member string, score float64) bool

Add puts member into set, and returns whether has inserted new node

func (*SortedSet) Count

func (sortedSet *SortedSet) Count(min *ScoreBorder, max *ScoreBorder) int64

Count returns the number of members which score within the given border

func (*SortedSet) ForEach

func (sortedSet *SortedSet) ForEach(start int64, stop int64, desc bool, consumer func(element *Element) bool)

ForEach visits each member which rank within [start, stop), sort by ascending order, rank starts from 0

func (*SortedSet) ForEachByScore

func (sortedSet *SortedSet) ForEachByScore(min *ScoreBorder, max *ScoreBorder, offset int64, limit int64, desc bool, consumer func(element *Element) bool)

ForEachByScore visits members which score within the given border

func (*SortedSet) Get

func (sortedSet *SortedSet) Get(member string) (element *Element, ok bool)

Get returns the given member

func (*SortedSet) GetRank

func (sortedSet *SortedSet) GetRank(member string, desc bool) (rank int64)

GetRank returns the rank of the given member, sort by ascending order, rank starts from 0

func (*SortedSet) Len

func (sortedSet *SortedSet) Len() int64

Len returns number of members in set

func (*SortedSet) Range

func (sortedSet *SortedSet) Range(start int64, stop int64, desc bool) []*Element

Range returns members which rank within [start, stop), sort by ascending order, rank starts from 0

func (*SortedSet) RangeByScore

func (sortedSet *SortedSet) RangeByScore(min *ScoreBorder, max *ScoreBorder, offset int64, limit int64, desc bool) []*Element

RangeByScore returns members which score within the given border param limit: <0 means no limit

func (*SortedSet) Remove

func (sortedSet *SortedSet) Remove(member string) bool

Remove removes the given member from set

func (*SortedSet) RemoveByRank

func (sortedSet *SortedSet) RemoveByRank(start int64, stop int64) int64

RemoveByRank removes member ranking within [start, stop) sort by ascending order and rank starts from 0

func (*SortedSet) RemoveByScore

func (sortedSet *SortedSet) RemoveByScore(min *ScoreBorder, max *ScoreBorder) int64

RemoveByScore removes members which score within the given border

type TrieNode

type TrieNode struct {
	IsLeaf bool

	Url   string
	Child []*TrieNode
	// contains filtered or unexported fields
}

TrieNode 前缀树

func NewTrieNode

func NewTrieNode(count int) *TrieNode

func (*TrieNode) Add added in v0.0.4

func (t *TrieNode) Add(url skiplist)

func (*TrieNode) Delete added in v0.0.4

func (t *TrieNode) Delete()

type UnionFind added in v0.0.6

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

func NewUnionFind added in v0.0.6

func NewUnionFind(size int) *UnionFind

New returns an initialized list of size

func (*UnionFind) Find added in v0.0.6

func (uf *UnionFind) Find(p int) int

Find Root or Find

func (*UnionFind) IsConnected added in v0.0.6

func (uf *UnionFind) IsConnected(p int, q int) bool

IsConnected Check if items p,q are connected

func (*UnionFind) Root added in v0.0.6

func (uf *UnionFind) Root(p int) int

Root or Find traverses each parent element while compressing the levels to find the root element of p If we attempt to access an element outside the array it returns -1

func (*UnionFind) Union added in v0.0.6

func (uf *UnionFind) Union(p int, q int)

Union connects p and q by finding their roots and comparing their respective size arrays to keep the tree flat

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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