fsm

package module
v0.0.0-...-2c32e6f Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2021 License: MIT Imports: 10 Imported by: 0

README

FSM

FileHashmap 文件Hash索引(支持重复的Key)基于Go实现, 能力列表:

  1. Get(key string) []values
  2. Set(key string, value uint32)
  3. Del(key string)

具体介绍:

  • 优化了Key存储逻辑(固定的Key只会存在一个文件里)
  • 新增了过期机制(添加了下一次可以写入的游标)
  • 待补充细节...

如何使用

可以直接阅读源码来学习具体的实现, 如果实在懒得看, 可以按照下面做:

package main

import (
	"github.com/invxp/fsm"
	"testing"
)

func TestSingle(t *testing.T) {
	// 初始化
	// 最大索引槽数量
	// 最大索引数量
	// 最多文件数量
	// 索引目录
	fileHashMap := fsm.NewFileHashMap(
		fsm.DefaultMaxSlotCount,
		fsm.DefaultMaxIndexCount,
		fsm.DefaultMaxFileCount,
		"idx",
	)

	// 写入KV
	fileHashMap.Set("Key", 1)
	
	// 打印KV
	fileHashMap.Get("Key")
}

测试用例可以这样做:

$ go test -v -race -run @XXXXX(具体方法名)
PASS / FAILED

或测试全部用例:

$ go test -v -race

TODO

  1. Value切换成可变长度String
  2. Value可以修改 + Key不可重复
  3. 删除Key
  4. 支持高可用(多机)

Documentation

Index

Constants

View Source
const DefaultDataFolderName = "data"

DefaultDataFolderName 默认数据路径名

View Source
const DefaultMaxFileCount = 1024

DefaultMaxFileCount 默认最大索引文件数量

View Source
const DefaultMaxIndexCount = 20000000

DefaultMaxIndexCount 默认最大索引的数量,推荐槽数量的4倍(4 * 500W = 2000W)

View Source
const DefaultMaxSlotCount = 5000000

DefaultMaxSlotCount 默认最大槽的数量(500W)

View Source
const DefaultMaxValueSize = math.MaxUint16

DefaultMaxValueSize 默认最大Value长度

View Source
const HeaderSize = 40

HeaderSize 头信息大小 [00-03](预留字段)4字节 [04-11](索引写入的起始时间)8字节 [12-19](索引写入的结束时间)8字节 [20-23](下次索引写入的位置)4字节 [24-27](下次数据写入的位置)4字节 [28-39](预留字段)12字节

View Source
const IndexSize = 16

IndexSize 索引的大小 [00-03](KeyHash)4字节 [04-07](Value)4字节 [08-11](与索引写入的起始时间的时间差)4字节 [12-15](链表Index)4字节

View Source
const SlotSize = 4

SlotSize Hash槽的大小,固定4字节

Variables

This section is empty.

Functions

func NewFileHashMap

func NewFileHashMap(maxSlotCount, maxIndexCount uint32, maxFileCount uint, database string) *fileHashmap

NewFileHashMap 初始化对象(选定一个目录)

Types

This section is empty.

Jump to

Keyboard shortcuts

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