godata

package module
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: May 5, 2020 License: MIT Imports: 4 Imported by: 1

README

godata

Basic data structures and operations written in Go which golang.org/pkg/container don't support such as stack, queue, etc.

Quick start

package main
import(
  "github.com/googege/godata"
)
func main(){
// stack
    stack := godata.NewStack(5)
    stack.Push(1)
    stack.Length()
    stack.Top()
    stack.Pop()
// trie
    trie := NewTrie()
    trie.Insert("hello world")
    trie.Insert("hello China")
    trie.Insert("hello My dear")
    trie.Search("hello world")
    trie.StartWith("he")
    trie.Image("he")
}

HERE

项目 介绍
对我的赞助 p
便宜服务器推荐 阿里云梯子服务器:支持支付宝
微信公众号 p
知识讨论微信群 p
我的社交平台 b站YouTube微博,抖音:googege

Documentation

Index

Constants

View Source
const (
	MAX_DB = 8388609
)

Variables

This section is empty.

Functions

func HashShower added in v0.7.0

func HashShower(data []byte, seed uint32) uint64

this HashShower fuction is fast but not safety.

func PopMin added in v0.4.0

func PopMin(m *MinHeap) int

func PushMin added in v0.4.0

func PushMin(m *MinHeap, value int)

func TopMin added in v0.4.2

func TopMin(m *MinHeap) int

Types

type BitMap added in v0.6.0

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

位图

func NewBitMap added in v0.6.0

func NewBitMap(max uint64) *BitMap

return a new bit map. if max > 2^64-1 ,return nil

func (*BitMap) Add added in v0.6.0

func (b *BitMap) Add(num uint64)

is right return true ,or false

func (*BitMap) Delete added in v0.6.0

func (b *BitMap) Delete(num uint64)

func (*BitMap) Init added in v0.6.0

func (b *BitMap) Init()

init the bitMap.

func (*BitMap) IsExit added in v0.6.0

func (b *BitMap) IsExit(num uint64) bool

type BloomFilter added in v0.7.0

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

func NewBloomFilter added in v0.7.0

func NewBloomFilter(k int) *BloomFilter

max is the max of bitmap number k is the number of HashShower fuction.

func (*BloomFilter) Add added in v0.7.0

func (b *BloomFilter) Add(value []byte)

add data

func (*BloomFilter) IsExit added in v0.7.0

func (b *BloomFilter) IsExit(value []byte) bool

is exit.

type DNode added in v0.5.0

type DNode struct {
	Value interface{}
	Child []*DNode
}

func (*DNode) DFS added in v0.5.0

func (d *DNode) DFS(ma map[*DNode]int, value interface{}) *DNode

type LRUCache added in v0.6.0

type LRUCache struct {
	Cache map[int]*list.Element
	Cap   int
	List  *list.List
}

func NewLRU added in v0.6.0

func NewLRU(capacity int) LRUCache

new a LRU

func (*LRUCache) Get added in v0.6.0

func (l *LRUCache) Get(key int) int

exist:value, no:-1

func (*LRUCache) Put added in v0.6.0

func (l *LRUCache) Put(key int, value int)

put a new data

func (*LRUCache) ReBuild added in v0.6.0

func (l *LRUCache) ReBuild()

Rebuild the LRU.

type LRUNode added in v0.6.0

type LRUNode struct {
	Key, Value int
}

type MinHeap added in v0.4.0

type MinHeap []int

func (MinHeap) Len added in v0.4.0

func (h MinHeap) Len() int

func (MinHeap) Less added in v0.4.0

func (h MinHeap) Less(i, j int) bool

func (*MinHeap) Pop added in v0.4.0

func (h *MinHeap) Pop() interface{}

func (*MinHeap) Push added in v0.4.0

func (h *MinHeap) Push(x interface{})

func (MinHeap) Swap added in v0.4.0

func (h MinHeap) Swap(i, j int)

type Node added in v0.5.0

type Node struct {
	Value interface{}
	Child []*Node
}

func (*Node) BFS added in v0.5.0

func (n *Node) BFS(value interface{}) *Node

寻找到目标值,并且返回目标struct. node是要加入搜索的root节点,value是目标值

type Queue added in v0.2.0

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

func NewQueue added in v0.2.0

func NewQueue(count int) *Queue

return cap of the slice.

func (*Queue) Length added in v0.2.0

func (q *Queue) Length() int

func (*Queue) Pop added in v0.2.0

func (q *Queue) Pop() interface{}

return the top of queue,and delete a node of the queue.

func (*Queue) PopBack added in v0.3.0

func (q *Queue) PopBack() interface{}

func (*Queue) Push added in v0.2.0

func (q *Queue) Push(value interface{}) int

return length of the queue

func (*Queue) Top added in v0.2.0

func (q *Queue) Top() interface{}

type Stack

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

func NewStack

func NewStack(count int) *Stack

return the cap of the slice.

func (*Stack) Length

func (s *Stack) Length() int

func (*Stack) Pop

func (s *Stack) Pop() interface{}

func (*Stack) Push

func (s *Stack) Push(v interface{}) int

func (*Stack) Top

func (s *Stack) Top() interface{}

type Trie added in v0.5.0

type Trie struct {
	// 都是存在于children中的
	Children map[rune]*Trie
	IsWord   bool
}

support all utf8 code.

func NewTrie added in v0.5.0

func NewTrie() *Trie

* Initialize your data structure here.

func (*Trie) Image added in v0.5.0

func (t *Trie) Image(prefix string) [][]rune

func (*Trie) Insert added in v0.5.0

func (t *Trie) Insert(word string)

* Inserts a word into the trie.

func (*Trie) Search added in v0.5.0

func (t *Trie) Search(word string) bool

* Returns if the word is in the trie.

func (*Trie) StartsWith added in v0.5.0

func (t *Trie) StartsWith(prefix string) (bool, *Trie)

* Returns if there is any word in the trie that starts with the given prefix.

type UnionFind added in v0.6.0

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

func NewUnionFind added in v0.6.0

func NewUnionFind(roots int) *UnionFind

new a union & find.

func (*UnionFind) FindRoot added in v0.6.0

func (u *UnionFind) FindRoot(i int) int

寻找老大的过程

func (*UnionFind) Union added in v0.6.0

func (u *UnionFind) Union(x, y int)

Jump to

Keyboard shortcuts

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