cmap

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

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

Go to latest
Published: Nov 6, 2015 License: MIT Imports: 1 Imported by: 5

README

CMap

Build Status GoDoc

Thread-safe Go map implementation suitable for concurrent access from multiple goroutines. Built on basic idea taken from: Go maps in action #concurrency

Example

import "github.com/neptulon/cmap"

m := cmap.New()
m.Set("foo", "bar")

val := m.Get("foo");
bar := val.(string)
log.Println(bar)

m.Delete("foo")

To see a more comprehensive example and relevant documentation, check the godocs.

Testing

All the tests can be executed with GORACE="halt_on_error=1" go test -v -race -cover ./... command.

License

MIT

Documentation

Overview

Example

Example demonstrating the use concurrent-map.

package main

import (
	"log"

	"github.com/neptulon/cmap"
)

func main() {
	m := cmap.New()
	m.Set("foo", "bar")

	if val, ok := m.GetOk("foo"); ok {
		bar := val.(string)
		log.Println(bar)
	}

	m.Delete("foo")
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CMap

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

CMap is a thread-safe map.

func New

func New() *CMap

New creates and returns a new thread-safe map.

func (*CMap) Delete

func (c *CMap) Delete(key interface{})

Delete removes a value for a given key.

func (*CMap) Get

func (c *CMap) Get(key interface{}) (val interface{})

Get retrieves a value for a given key.

func (*CMap) GetOk

func (c *CMap) GetOk(key interface{}) (val interface{}, ok bool)

GetOk retrieves a value for a given key. An 'ok' flag is also returned indicating whether a value exists for the given key.

func (*CMap) Len

func (c *CMap) Len() int

Len returns the item count.

func (*CMap) Range

func (c *CMap) Range(fn func(val interface{}))

Range iterates over the entire collection and executes given function on each item.

func (*CMap) Set

func (c *CMap) Set(key interface{}, val interface{})

Set stores a value for a given key.

Jump to

Keyboard shortcuts

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