htable

package module
v0.0.0-...-8992865 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2020 License: MIT Imports: 4 Imported by: 1

README

htable

Documentation

Index

Constants

View Source
const HashTableLength int = 100 // 哈希表默认长度

HashTableLength 哈希表默认数组长度

Variables

View Source
var Content []byte // 存储
View Source
var FreeLength int // 剩余空间大小
View Source
var FreeList []*Block // 空闲存储块
View Source
var UsedList []*Block // 已使用的存储块

Functions

func HashInt

func HashInt(s interface{}) int

HashInt 根据 hash 算法获取数值

func HashValueToBytes

func HashValueToBytes(hashValue HashValue) ([]byte, error)

func KeyToInt

func KeyToInt(key interface{}) int

KeyToInt 将 Key 转换为数组下标

Types

type Block

type Block struct {
	Offset int // 存储空间 Content 中的 offset
	Length int // 存储空间 Content 中的 length
	Next   *Block
}

Block 存储块

func Store

func Store(content []byte) *Block

func (*Block) GetContent

func (block *Block) GetContent() []byte

type HashTable

type HashTable struct {
	Length    int
	BlockList []*Block
}

HashTable 哈希表 理论上讲哈希表的 value 应该是 HashValue,即哈希表应该是 HashValue 的数组; 但是因为要控制内存空间的大小,所以必须将HashValue 存储在 block 中,所以哈希表的 value 是 block 的指针。

func MapToHashTable

func MapToHashTable(v map[string]interface{}) (*HashTable, error)

MapToHashTable 将 map 对象装成 HashTable

func NewHashTable

func NewHashTable() *HashTable

func (*HashTable) Get

func (ht *HashTable) Get(key string) (interface{}, error)

func (*HashTable) Index

func (ht *HashTable) Index(keyInt int) *Block

Index 通过下标获取数据

func (*HashTable) Keys

func (ht *HashTable) Keys() ([]interface{}, error)

Keys 列出 HashTable 所有的 key

func (*HashTable) Set

func (ht *HashTable) Set(key string, value interface{}) error

func (*HashTable) SetByType

func (ht *HashTable) SetByType(key string, value interface{}, tp string) error

func (*HashTable) String

func (ht *HashTable) String() string

func (*HashTable) ToMap

func (ht *HashTable) ToMap() (map[string]interface{}, error)

ToMap 将 HashTable 转成 map

type HashValue

type HashValue struct {
	Key   interface{}
	Value interface{} // value 可以是 int/string等标准类型,也可以是 HashTable 类型
	Type  string      // 类型,指明 value 是值还是 HashTable,可选值有 ValueType / HashType
}

HashValue 哈希表 value 结构

func HashValueFromBytes

func HashValueFromBytes(content []byte) (*HashValue, error)

func (*HashValue) IsHashType

func (hv *HashValue) IsHashType() bool

Jump to

Keyboard shortcuts

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