Skip to content
/ shm Public

A hash map implemented in a shared memory mapping.

License

Notifications You must be signed in to change notification settings

fengyoulin/shm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

shm

A hash map implemented in a shared memory mapping.

Example:

package main

import (
	"github.com/fengyoulin/shm"
	"log"
	"time"
)

func main() {
	m, err := shm.Create("map.db", 4096, 40, 32, 20, time.Second)
	if err != nil {
		log.Fatalln(err)
	}

	defer func() {
		err = m.Close()
		if err != nil {
			log.Fatalln(err)
		}
	}()

	// get or add a key
	b, err := m.Get("1a2b3c4d5e6f", true)
	if err != nil {
		log.Fatalln(err)
	}

	// do something with b
	log.Println(cap(b))

	// iterate over the map
	m.Foreach(func(key string, value []byte) bool {
		log.Printf("key: %s\n", key)
		return true
	})
	// m.Delete("key")
}

About

A hash map implemented in a shared memory mapping.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages