nexus

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

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

Go to latest
Published: Jun 7, 2017 License: MIT Imports: 7 Imported by: 0

README

Nexus

一个轻量级的存储框架。

将kv类型的数据库群转化成为树形结构的存储。

优势:

拓展易,可支持海量存储需求;

缺点:

每次操作需要最多height(树的深度)次的操作。

原理:

kv模式下,以key的md5后的hash为16位的byte数组,通过每4位变成一个biary.BigEndian转化为一个hash值,所以总共有12层。

每一个节点与其子节点变成一个节点数组,通过取余的模式,分配节点数据。为了方便起见,root节点不存放数据,为空节点。

使用时,通过实现interface.go的interface即可。

test

详细可以查阅test文件夹。

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrConfFormat the format of configuration is wrong
	ErrConfFormat = errors.New("wrong conf format")
	// ErrConf bad configuration
	ErrConf = errors.New("wrong conf")

	// ErrNodeNotFound node not found
	ErrNodeNotFound = errors.New("node not found")
	// ErrNodeReplicate node replicate
	ErrNodeReplicate = errors.New("node replicate")
	// ErrNodeHasChildren node has children
	ErrNodeHasChildren = errors.New("node has children")

	// ErrKeyNotFound key not found
	ErrKeyNotFound = errors.New("key not found")
)
View Source
var (
	// RootIndex the index of root
	RootIndex = 0
)

Functions

func MD5

func MD5(key string) [16]byte

MD5 .

Types

type DB

type DB interface {
	Set(key string, value string) error
	Get(key string) (string, error)
	Del(key string) error
	Close() error

	String() string
}

DB is the interface of db, user must implement itself

type Node

type Node struct {
	Index  int
	Parent *Node
	DB     DB
	// contains filtered or unexported fields
}

Node root's parent is itself

func (*Node) Close

func (node *Node) Close() (err error)

Close close the node

func (*Node) Del

func (node *Node) Del(key string) error

Del .

func (*Node) Get

func (node *Node) Get(key string) (string, error)

Get must return err = ErrKeyNotFound when key not found

func (*Node) Set

func (node *Node) Set(key string, value string) error

Set .

func (*Node) String

func (node *Node) String() string

String output the conf of the node

type NodeManager

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

NodeManager manage nodes

func NewNodeManager

func NewNodeManager(f func(string) (DB, error)) (nm *NodeManager, err error)

NewNodeManager .

func (*NodeManager) AddNode

func (nm *NodeManager) AddNode(index int, conf []string) (err error)

AddNode add the children of index node

func (*NodeManager) Del

func (nm *NodeManager) Del(key string) error

Del find and delete

func (*NodeManager) Get

func (nm *NodeManager) Get(key string) (string, error)

Get find and return

func (*NodeManager) NewNode

func (nm *NodeManager) NewNode(conf string) (err error)

NewNode build node tree

func (*NodeManager) Set

func (nm *NodeManager) Set(key string, value string) error

Set find the bottom of tree

func (*NodeManager) String

func (nm *NodeManager) String() string

String .

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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