algorithm

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: May 11, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BitSize = 8 // 一个字节8位
)
View Source
const SKIPLIST_MAXLEVEL = 32 // 8
View Source
const SKIPLIST_P = 4

Variables

This section is empty.

Functions

func ByteToBinaryString

func ByteToBinaryString(data byte) (str string)

ByteToBinaryString函数来源: Go语言版byte变量的二进制字符串表示 http://www.sharejs.com/codes/go/4357

func GetSnowflakeId

func GetSnowflakeId() int64

fixme: 并发安全

func SetMachineId

func SetMachineId(mid int64)

func TestRetry

func TestRetry(t *testing.T)

Types

type Bitmap

type Bitmap struct {
	BitArray  []byte
	ArraySize uint32
}

func NewBitmap

func NewBitmap(max uint32) *Bitmap

func (*Bitmap) Clear

func (bitmap *Bitmap) Clear(i uint32)

func (*Bitmap) Set

func (bitmap *Bitmap) Set(i uint32)

func (*Bitmap) Test

func (bitmap *Bitmap) Test(i uint32) byte

type CacheNode

type CacheNode struct {
	Key, Value interface{}
}

func (*CacheNode) NewCacheNode

func (cnode *CacheNode) NewCacheNode(k, v interface{}) *CacheNode

type LRUCache

type LRUCache struct {
	Capacity int
	// contains filtered or unexported fields
}

func NewLRUCache

func NewLRUCache(cap int) *LRUCache

func (*LRUCache) Get

func (lru *LRUCache) Get(k interface{}) (v interface{}, ret bool, err error)

func (*LRUCache) Remove

func (lru *LRUCache) Remove(k interface{}) bool

func (*LRUCache) Set

func (lru *LRUCache) Set(k, v interface{}) error

func (*LRUCache) Size

func (lru *LRUCache) Size() int

type Node

type Node struct {
	Forward []Node
	Value   interface{}
}

func NewNode

func NewNode(v interface{}, level int) *Node

type SkipList

type SkipList struct {
	Header *Node
	Level  int
}

func NewSkipList

func NewSkipList() *SkipList

func (*SkipList) Insert

func (skipList *SkipList) Insert(key int)

func (*SkipList) PrintSkipList

func (skipList *SkipList) PrintSkipList()

func (*SkipList) Random_level

func (skipList *SkipList) Random_level() int

func (*SkipList) Remove

func (skipList *SkipList) Remove(key int)

func (*SkipList) Search

func (skipList *SkipList) Search(key int) *Node

type Sms

type Sms struct {
	Title, From, To, Content string
}

短信

func (*Sms) Send

func (p *Sms) Send() error

模拟发短信

func (*Sms) SendWithRetry

func (p *Sms) SendWithRetry(count uint8, interval time.Duration)

发送短信(失败重试)

count: 尝试发送次数
interval: 第一次失败重试间隔时间(后续间隔翻倍)

type Stack

type Stack struct {
	Element []interface{} // Element
}

func NewStack

func NewStack() *Stack

func (*Stack) Empty

func (stack *Stack) Empty() bool

是否为空

func (*Stack) Get

func (stack *Stack) Get(idx int) (value interface{})

返回指定索引的元素

func (*Stack) Pop

func (stack *Stack) Pop() (err error)

返回下一个元素,并从Stack移除元素

func (*Stack) Print

func (stack *Stack) Print()

打印

func (*Stack) Push

func (stack *Stack) Push(value ...interface{})

func (*Stack) Set

func (stack *Stack) Set(idx int, value interface{}) (err error)

修改指定索引的元素

func (*Stack) Size

func (stack *Stack) Size() int

Stack的size

func (*Stack) Swap

func (stack *Stack) Swap(other *Stack)

交换值

func (*Stack) Top

func (stack *Stack) Top() (value interface{})

返回下一个元素

type Stop

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

自定义Stop错误

func NewStop

func NewStop(msg string) Stop

Jump to

Keyboard shortcuts

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