Coder Social home page Coder Social logo

memkv's Introduction

MemKV

实现一个基于内存的KV存储微系统。
利用链表法解决key值哈希冲突问题。
系统有两部分组成:
1 哈希bucket。
2 二叉搜索树。二叉搜索数中每个节点为一个链表。
用于保存hash值相同的KV对。

斐波那契(Fibonacci)散列法

1 对于16位整数而言,这个乘数是40503
2 对于32位整数而言,这个乘数是2654435769
3 对于64位整数而言,这个乘数是11400714819323198485
对32位整数,示例公式:
index = (value * 2654435769) >> 28

Requires

go get github.com/spaolacci/murmur3

Usage

import (
	"fmt"
	"github.com/KunBetter/MemKV"
	"time"
)

func main() {
	kv := MemKV.DB()
	//put
	kv.Put([]byte("a"), "b")
	kv.Put([]byte("c"), "d")
	s := time.Now()
	for i := 0; i < 100000000; i++ {
		kv.Get([]byte("c"))
	}
	e := time.Now()
	t := e.UnixNano() - s.UnixNano()
	var es float64 = float64(t)
	fmt.Println(kv.Get([]byte("c")), t, es/1e9)
	//get
	fmt.Println(kv.Get([]byte("a")))
	//update
	kv.Put([]byte("a"), "e")
	fmt.Println(kv.Get([]byte("a")))
	//delete
	kv.Del([]byte("a"))
	fmt.Println(kv.Get([]byte("a")))
}  
Result:
d 19762130300 19.7621303
b
e
<nil>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.