Documentation ¶
Overview ¶
Package datastruct 这个包是用于构造map结构,在golang里面已经实现了map这个基本类型。 基本的map实现还是比较高效的。在1.8的版本中map的负载因子是6.5.当超过这个负载因子时,map就是进行 扩容,但是目前遇到的问题是,golang没有对删除的键进行缩容。也即是就算是当前的map没有键也不会被gc掉 因此这一块内容需要自己扩展 现在的思路是 底层依然使用go的map,当负载因子减小到一定程度时 新建map将值拷贝过来 然后释放之前的map
Index ¶
- Variables
- type DemoDictFuncs
- func (*DemoDictFuncs) HashCalc(key string) uint64
- func (*DemoDictFuncs) KeyCompare(k1, k2 string) int
- func (*DemoDictFuncs) KeyCopy(key string) string
- func (*DemoDictFuncs) KeyDestructor(key string)
- func (*DemoDictFuncs) ValueCopy(v interface{}) interface{}
- func (*DemoDictFuncs) ValueDestructor(value interface{})
- type Dict
- type DictFuncType
- type List
- func (l *List) ListAddNodeHead(node *ListNode) bool
- func (l *List) ListAddNodeTail(node *ListNode) bool
- func (l *List) ListCopy() (*List, error)
- func (l *List) ListDelNodeByIndex(index int64)
- func (l *List) ListDelNodeByValue(valueNode *ListNode, dir int) bool
- func (l *List) ListFirst() *ListNode
- func (l *List) ListFree()
- func (l *List) ListIndex(index int64) *ListNode
- func (l *List) ListInsertNode(newNode *ListNode, target *ListNode, dir int) (bool, error)
- func (l *List) ListInsertNodeByValue(newNode *ListNode, target *ListNode, dir int) (int, error)
- func (l *List) ListInsterNodeByIndex(newNode *ListNode, index int64, dir int) (bool, error)
- func (l *List) ListLast() *ListNode
- func (l *List) ListLengeth() int64
- func (l *List) ListNextNode(node *ListNode) *ListNode
- func (l *List) ListNodeValue(node *ListNode) interface{}
- func (l *List) ListPrevNode(node *ListNode) *ListNode
- func (l *List) ListSetProcess(proc ListProcess)
- func (l *List) ListTrim(left int, right int)
- type ListNode
- type ListProcess
- type Map
- func (myself *Map) Cap() int64
- func (myself *Map) Delete(key string)
- func (myself *Map) Free()
- func (myself *Map) Get(key string) (interface{}, bool)
- func (myself *Map) Keys(pattern string) ([][]byte, error)
- func (myself *Map) Len() int64
- func (myself *Map) RandomKeys(pattern string) ([]byte, error)
- func (myself *Map) Set(key string, value interface{})
- type RBT
- type RBTNode
- type RBTNodeFuncs
- type Sds
- func (sds *Sds) Buffer() []byte
- func (sds *Sds) SdsCat(str []byte)
- func (sds *Sds) SdsCatSds(newSds *Sds)
- func (sds *Sds) SdsClear()
- func (sds *Sds) SdsCmp(other *Sds) bool
- func (sds *Sds) SdsCopy() *Sds
- func (sds *Sds) SdsCopyStr(str []byte)
- func (sds *Sds) SdsFree()
- func (sds *Sds) SdsLen() int
- func (sds *Sds) SdsRange(left, right int) *Sds
- func (sds *Sds) SdsVail() int
- func (sds *Sds) String() string
- type StrListNode
- type StringRBTNode
Constants ¶
This section is empty.
Variables ¶
var StrListFuncs = &StrListNode{}
StrListFuncs 字符串类型的列表函数簇
var StringNodeFuncs = &StringRBTNode{}
StringNodeFuncs 字符串类型节点的操作函数
Functions ¶
This section is empty.
Types ¶
type DemoDictFuncs ¶
type DemoDictFuncs struct { }
DemoDictFuncs 函数簇示例
func (*DemoDictFuncs) KeyCompare ¶
func (*DemoDictFuncs) KeyCompare(k1, k2 string) int
KeyCompare 值比较
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 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 (*List) ListAddNodeHead ¶
ListAddNodeHead 将一个指定的节点加入表头
func (*List) ListAddNodeTail ¶
ListAddNodeTail 将一个节点接入表尾
func (*List) ListDelNodeByIndex ¶
ListDelNodeByIndex 根据索引删除指定节点
func (*List) ListDelNodeByValue ¶
ListDelNodeByValue 根据值相等来删除指定节点
func (*List) ListFree ¶
func (l *List) ListFree()
ListFree 释放链表空间 todo:: 此处有疑问 如果我只取消节点的引用 gc释放能够自动释放内存 现在先手动释放 下回有时间检测一下
func (*List) ListInsertNode ¶
ListInsertNode 将一个新节点插入指定节点的前或者尾 dir: 负数或0表示向前插入 正数表示向后插入
func (*List) ListInsertNodeByValue ¶
ListInsertNodeByValue 将一个新节点插入指定节点的前或者尾 (比较节点的值是否相等 而不是地址) dir: 负数或0表示向前插入 正数表示向后插入
func (*List) ListInsterNodeByIndex ¶
ListInsterNodeByIndex 通过索引插入一个节点
func (*List) ListNextNode ¶
ListNextNode 返回给定节点的下一个节点
func (*List) ListNodeValue ¶
ListNodeValue 返回指定节点保存的值
func (*List) ListPrevNode ¶
ListPrevNode 返回给定节点的前一个节点
func (*List) ListSetProcess ¶
func (l *List) ListSetProcess(proc ListProcess)
ListSetProcess 设置链表的操作函数
type ListProcess ¶
type ListProcess interface { ListDup(*ListNode) (*ListNode, error) // 复制一个链表节点所保存的值 ListFree(*ListNode) error // 释放链表节点所保存的值 ListMatch(l1, l2 *ListNode) bool // 用于对比链表节点所保存的值是否和输入值相等 }
ListProcess 定义list的函数族
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 ¶
DeleteNodeValue 删除node中的一个值
func (*RBTNode) GetNodeInfo ¶
GetNodeInfo 返回节点信息 分数 值
func (*RBTNode) SetNodeValue ¶
SetNodeValue 设置node的值
type RBTNodeFuncs ¶
type RBTNodeFuncs interface { // 更改节点的值 SetValue(node *RBTNode, value interface{}) error // 删除node中为value的值 DeleteValue(node *RBTNode, value interface{}) error }
RBTNodeFuncs 聚合函数
type StrListNode ¶
type StrListNode struct{}
StrListNode 字符串类型的函数簇
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 设置节点值