datastruct

package
v0.0.0-...-4125365 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2017 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package datastruct 这个包是用于构造map结构,在golang里面已经实现了map这个基本类型。 基本的map实现还是比较高效的。在1.8的版本中map的负载因子是6.5.当超过这个负载因子时,map就是进行 扩容,但是目前遇到的问题是,golang没有对删除的键进行缩容。也即是就算是当前的map没有键也不会被gc掉 因此这一块内容需要自己扩展 现在的思路是 底层依然使用go的map,当负载因子减小到一定程度时 新建map将值拷贝过来 然后释放之前的map

Index

Constants

This section is empty.

Variables

View Source
var StrListFuncs = &StrListNode{}

StrListFuncs 字符串类型的列表函数簇

View Source
var StringNodeFuncs = &StringRBTNode{}

StringNodeFuncs 字符串类型节点的操作函数

Functions

This section is empty.

Types

type DemoDictFuncs

type DemoDictFuncs struct {
}

DemoDictFuncs 函数簇示例

func (*DemoDictFuncs) HashCalc

func (*DemoDictFuncs) HashCalc(key string) uint64

HashCalc 计算hash值

func (*DemoDictFuncs) KeyCompare

func (*DemoDictFuncs) KeyCompare(k1, k2 string) int

KeyCompare 值比较

func (*DemoDictFuncs) KeyCopy

func (*DemoDictFuncs) KeyCopy(key string) string

KeyCopy 返回键的复制

func (*DemoDictFuncs) KeyDestructor

func (*DemoDictFuncs) KeyDestructor(key string)

KeyDestructor 键销毁

func (*DemoDictFuncs) ValueCopy

func (*DemoDictFuncs) ValueCopy(v interface{}) interface{}

ValueCopy 值拷贝

func (*DemoDictFuncs) ValueDestructor

func (*DemoDictFuncs) ValueDestructor(value interface{})

ValueDestructor 值销毁

type Dict

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

Dict 字典的定义

func NewDict

func NewDict(funcs DictFuncType) *Dict

NewDict 创建一个新的字典

func (*Dict) Delete

func (d *Dict) Delete(key string)

Delete 删除一个键值

func (*Dict) Free

func (d *Dict) Free()

Free 释放字典

func (*Dict) Get

func (d *Dict) Get(key string) (interface{}, bool)

Get 返回一个值类型

func (*Dict) Print

func (d *Dict) Print()

Print 打印key和value

func (*Dict) Set

func (d *Dict) Set(key string, value interface{})

Set 增加一对键值

type DictFuncType

type DictFuncType interface {
	// 计算hash值的函数
	HashCalc(key string) uint64
	// 复制键的函数
	KeyCopy(key string) string
	// 复制值的函数
	ValueCopy(v interface{}) interface{}
	// 对比键的函数
	KeyCompare(k1, k2 string) int
	// 销毁键的函数
	KeyDestructor(key string)
	// 销毁值的函数
	ValueDestructor(value interface{})
}

DictFuncType 字典处理相关的函数接口

type List

type List struct {
	Processor ListProcess
	// contains filtered or unexported fields
}

List 声明列表对象

func ListCreate

func ListCreate() *List

ListCreate 创建一个不包含任何节点的新链表

func (*List) ListAddNodeHead

func (l *List) ListAddNodeHead(node *ListNode) bool

ListAddNodeHead 将一个指定的节点加入表头

func (*List) ListAddNodeTail

func (l *List) ListAddNodeTail(node *ListNode) bool

ListAddNodeTail 将一个节点接入表尾

func (*List) ListCopy

func (l *List) ListCopy() (*List, error)

ListCopy 返回一个链表额副本

func (*List) ListDelNodeByIndex

func (l *List) ListDelNodeByIndex(index int64)

ListDelNodeByIndex 根据索引删除指定节点

func (*List) ListDelNodeByValue

func (l *List) ListDelNodeByValue(valueNode *ListNode, dir int) bool

ListDelNodeByValue 根据值相等来删除指定节点

func (*List) ListFirst

func (l *List) ListFirst() *ListNode

ListFirst 返回列表的表头

func (*List) ListFree

func (l *List) ListFree()

ListFree 释放链表空间 todo:: 此处有疑问 如果我只取消节点的引用 gc释放能够自动释放内存 现在先手动释放 下回有时间检测一下

func (*List) ListIndex

func (l *List) ListIndex(index int64) *ListNode

ListIndex 查找指定索引的节点

func (*List) ListInsertNode

func (l *List) ListInsertNode(newNode *ListNode, target *ListNode, dir int) (bool, error)

ListInsertNode 将一个新节点插入指定节点的前或者尾 dir: 负数或0表示向前插入 正数表示向后插入

func (*List) ListInsertNodeByValue

func (l *List) ListInsertNodeByValue(newNode *ListNode, target *ListNode, dir int) (int, error)

ListInsertNodeByValue 将一个新节点插入指定节点的前或者尾 (比较节点的值是否相等 而不是地址) dir: 负数或0表示向前插入 正数表示向后插入

func (*List) ListInsterNodeByIndex

func (l *List) ListInsterNodeByIndex(newNode *ListNode, index int64, dir int) (bool, error)

ListInsterNodeByIndex 通过索引插入一个节点

func (*List) ListLast

func (l *List) ListLast() *ListNode

ListLast 返回列表的尾部

func (*List) ListLengeth

func (l *List) ListLengeth() int64

ListLengeth 返回列表的长度

func (*List) ListNextNode

func (l *List) ListNextNode(node *ListNode) *ListNode

ListNextNode 返回给定节点的下一个节点

func (*List) ListNodeValue

func (l *List) ListNodeValue(node *ListNode) interface{}

ListNodeValue 返回指定节点保存的值

func (*List) ListPrevNode

func (l *List) ListPrevNode(node *ListNode) *ListNode

ListPrevNode 返回给定节点的前一个节点

func (*List) ListSetProcess

func (l *List) ListSetProcess(proc ListProcess)

ListSetProcess 设置链表的操作函数

func (*List) ListTrim

func (l *List) ListTrim(left int, right int)

ListTrim 剔除范围外的列表

type ListNode

type ListNode struct {
	Prev  *ListNode
	Next  *ListNode
	Value interface{}
}

ListNode 列表节点

type ListProcess

type ListProcess interface {
	ListDup(*ListNode) (*ListNode, error) // 复制一个链表节点所保存的值
	ListFree(*ListNode) error             // 释放链表节点所保存的值
	ListMatch(l1, l2 *ListNode) bool      // 用于对比链表节点所保存的值是否和输入值相等
}

ListProcess 定义list的函数族

type Map

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

Map 构造map实现

func NewMap

func NewMap() *Map

NewMap 新建map对象

func (*Map) Cap

func (myself *Map) Cap() int64

Cap 获取当前的map的cap

func (*Map) Delete

func (myself *Map) Delete(key string)

Delete 删除一个key

func (*Map) Free

func (myself *Map) Free()

Free 是否所有内容

func (*Map) Get

func (myself *Map) Get(key string) (interface{}, bool)

Get 获取一个键的内容

func (*Map) Keys

func (myself *Map) Keys(pattern string) ([][]byte, error)

Keys 返回所有的key

func (*Map) Len

func (myself *Map) Len() int64

Len 获取当前键值个数

func (*Map) RandomKeys

func (myself *Map) RandomKeys(pattern string) ([]byte, error)

RandomKeys 返回一个随机键

func (*Map) Set

func (myself *Map) Set(key string, value interface{})

Set 设置一个键值

type RBT

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

RBT 红黑树对象

func NewRbt

func NewRbt() *RBT

NewRbt 新建一个红黑树操作对象

func (*RBT) Delete

func (t *RBT) Delete(node *RBTNode)

Delete 将节点从树中删除

func (*RBT) Get

func (t *RBT) Get(score int) (*RBTNode, bool)

Get 获取一个节点的内容

func (*RBT) GetMaxNode

func (t *RBT) GetMaxNode() (*RBTNode, bool)

GetMaxNode 获取最小节点

func (*RBT) GetMinNode

func (t *RBT) GetMinNode() (*RBTNode, bool)

GetMinNode 获取最小节点

func (*RBT) Insert

func (t *RBT) Insert(node *RBTNode)

Insert 将节点加入红黑树中

type RBTNode

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

RBTNode 每个红黑树的节点

func NewRBTNode

func NewRBTNode(funcs RBTNodeFuncs, socre int, value interface{}) *RBTNode

NewRBTNode 新的红黑树节点

func (*RBTNode) DeleteNodeValue

func (node *RBTNode) DeleteNodeValue(value interface{}) error

DeleteNodeValue 删除node中的一个值

func (*RBTNode) GetNodeInfo

func (node *RBTNode) GetNodeInfo() (score int, value interface{})

GetNodeInfo 返回节点信息 分数 值

func (*RBTNode) SetNodeValue

func (node *RBTNode) SetNodeValue(value interface{}) error

SetNodeValue 设置node的值

type RBTNodeFuncs

type RBTNodeFuncs interface {
	// 更改节点的值
	SetValue(node *RBTNode, value interface{}) error
	// 删除node中为value的值
	DeleteValue(node *RBTNode, value interface{}) error
}

RBTNodeFuncs 聚合函数

type Sds

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

Sds -- sds 结构体

func NewSds

func NewSds(str []byte) *Sds

NewSds -- 创建一个包含字符串的新的sds对象

func SdsEmpty

func SdsEmpty() *Sds

SdsEmpty -- 返回一个空的sds对象

func (*Sds) Buffer

func (sds *Sds) Buffer() []byte

Buffer 以字节返回

func (*Sds) SdsCat

func (sds *Sds) SdsCat(str []byte)

SdsCat 将指定的字符串拼接到末尾

func (*Sds) SdsCatSds

func (sds *Sds) SdsCatSds(newSds *Sds)

SdsCatSds 将给定的sds拼接到一个sds的末尾

func (*Sds) SdsClear

func (sds *Sds) SdsClear()

SdsClear 清空内容

func (*Sds) SdsCmp

func (sds *Sds) SdsCmp(other *Sds) bool

SdsCmp 比较两个sds的字符串是否一样

func (*Sds) SdsCopy

func (sds *Sds) SdsCopy() *Sds

SdsCopy 创建一个新的副本

func (*Sds) SdsCopyStr

func (sds *Sds) SdsCopyStr(str []byte)

SdsCopyStr 拷贝一个字符串 覆盖原来的内容

func (*Sds) SdsFree

func (sds *Sds) SdsFree()

SdsFree -- 释放一个sds的内存

func (*Sds) SdsLen

func (sds *Sds) SdsLen() int

SdsLen -- 返回字符串的长度

func (*Sds) SdsRange

func (sds *Sds) SdsRange(left, right int) *Sds

SdsRange 保留指定返回的内容

func (*Sds) SdsVail

func (sds *Sds) SdsVail() int

SdsVail --返回已经使用的长度

func (*Sds) String

func (sds *Sds) String() string

String 以字符串格式返回内容

type StrListNode

type StrListNode struct{}

StrListNode 字符串类型的函数簇

func (*StrListNode) ListDup

func (*StrListNode) ListDup(node *ListNode) (*ListNode, error)

ListDup 拷贝

func (*StrListNode) ListFree

func (*StrListNode) ListFree(node *ListNode) error

ListFree 释放

func (*StrListNode) ListMatch

func (*StrListNode) ListMatch(n1, n2 *ListNode) bool

ListMatch 比较

type StringRBTNode

type StringRBTNode struct {
}

StringRBTNode 字符串类型节点对象操作函数簇

func (*StringRBTNode) DeleteValue

func (*StringRBTNode) DeleteValue(node *RBTNode, value interface{}) error

DeleteValue 删除一个值

func (*StringRBTNode) SetValue

func (*StringRBTNode) SetValue(node *RBTNode, value interface{}) error

SetValue 设置节点值

Jump to

Keyboard shortcuts

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