Coder Social home page Coder Social logo

pierrekieffer / mstore Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 15 KB

In-memory storage management system for embedded data storage

License: BSD 2-Clause "Simplified" License

Go 100.00%
embedded-database cache-storage in-memory-database in-memory-storage in-memory-caching

mstore's Introduction

mstore

Go

In-memory storage management system for embedded data storage.

As an example of application, mstore can be used as the core of a cache system, or simply as an embedded database.

mstore uses an indexing system to optimize operations performance. mstore can manage multiple documents on the same index, but it is not possible to have several documents with the same key (the key is unique and is used to reference a document).

					      +-------+             data memory slot
					      |       |            +--------+-----------+
				       index  |       |            |        |           |
			     +-------> memory | Index +----------->+ Key_i  | Data      |
			     |         slot   |   01  |            |        |           |
			     |                |       |            +--------+-----------+
			     |                +-------+
			     |                |       |
			     |                |       |
			     |                |       |
+-----------+                |                |       |
|           |                |                |       |
| Data      +----------------+                +-------+
|           | hash function                   |       |            +--------+-----------+             +--------+----------+
+-----------+                                 |       |            |        |           |             |        |          |
					      | Index +----------->+ Key_j  |  Data     +------------>+ Key_k  | Data     |
					      |   ..  |            |        |           |             |        |          |
					      |       |            +--------+-----------+             +--------+----------+
					      +-------+
					      |       |
					      |       |
					      |       |
					      |       |
					      |       |
					      +-------+
					      |       |
					      |       |
					      |       |
					      +       +

Download

go get github.com/PierreKieffer/mstore

Usage

import(
	"github.com/PierreKieffer/mstore"
)

Initialize storage

s := mstore.InitStorage()

By default, the storage is built with 1000 indexes,

It is possible to configure the maximum number of indexes that make up the storage

s := mstore.InitStorage(10)

Document type

mstore uses a Document type :

type Document struct {
        Key  string
        Data interface{}
}

Documents are referenced by document key which must be unique.

If no custom key is passed, a key is generated in UnixNano format.

Insert

var data interface{} 
document := mstore.Document{Key: "custom-key", Data: data}
err = mstore.Insert(s, document)
if err != nil {
	fmt.Println(err)
}

Update

err = mstore.Update(s, document)
if err != nil {
	fmt.Println(err)
}

Delete

err := mstore.Delete(s, key)
if err != nil {
	fmt.Println(err)
}

Find

doc, err := mstore.Find(s, key)
if err != nil {
	fmt.Println(err)
}

mstore's People

Contributors

pierrekieffer avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

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.