cmap

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

README

cmap - A thread-safe concurrent map

Install
go get github.com/s1m0n21/cmap
How to use
package main

import (
	"fmt"

	"github.com/s1m0n21/cmap"
)

type key struct {
	Content int // The key must have at least one public field
}

type value struct {
	Content int
}

func main() {
	m := cmap.New(cmap.DefaultShard)

	k := key{Content: 1}
	v := value{Content: 2}

	if err := m.Set(k, v); err != nil {
		fmt.Printf("SET ERROR: %s", err)
		return
	}

	r, has, err := m.Get(k)
	if err != nil {
		fmt.Printf("GET ERROR: %s", err)
		return
	}

	fmt.Printf("has: %v", has)
	fmt.Printf("r: %+v", r)
}

Documentation

Index

Constants

View Source
const DefaultShard uint64 = 32

Variables

This section is empty.

Functions

This section is empty.

Types

type ConcurrentMap

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

func New

func New(shard uint64) *ConcurrentMap

func (*ConcurrentMap) Del

func (m *ConcurrentMap) Del(key interface{}) (bool, error)

func (*ConcurrentMap) Get

func (m *ConcurrentMap) Get(key interface{}) (interface{}, bool, error)

func (*ConcurrentMap) Has added in v1.1.0

func (m *ConcurrentMap) Has(key interface{}) (bool, error)

func (*ConcurrentMap) Iterator

func (m *ConcurrentMap) Iterator() *Iter

func (*ConcurrentMap) Set

func (m *ConcurrentMap) Set(key, value interface{}) error

type Iter

type Iter struct {
	C chan Kv
}

type Kv

type Kv struct {
	Key   interface{}
	Value interface{}
}

Jump to

Keyboard shortcuts

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