chmap

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2022 License: MIT Imports: 3 Imported by: 0

README

chmap

CI Workflow Badge Go Report Card Godoc Badge

ConcurrentHashMap implementation in go.

m := chmap.New()

m.Put("nine", 9)

if val, ok := m.Get("nine"); ok {
    _ = val.(int)
    // some code
}

_ = m.GetOrDefault("twenty-three", 23)

if ok := m.Contains("nine"); ok {
    // some code
}

if val, ok := m.Get("nine"); ok {
    _ = val.(int)
    // some code
}

Documentation

Overview

Package chmap ConcurrentHashMap

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConcurrentHashMap

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

ConcurrentHashMap thread-safe string:any map

func New

func New() ConcurrentHashMap

New returns ConcurrentHashMap with default capacity.

func NewWithCap

func NewWithCap(capacity int) (chm ConcurrentHashMap, err error)

NewWithCap returns ConcurrentHashMap with given capacity.

func (*ConcurrentHashMap) Contains

func (m *ConcurrentHashMap) Contains(key string) bool

Contains returns if there is an entry mapped by the given key.

func (*ConcurrentHashMap) Get

func (m *ConcurrentHashMap) Get(key string) (interface{}, bool)

Get returns value of the entry mapped by given key. If there is mopping by given key, it returns false.

func (*ConcurrentHashMap) GetOrDefault

func (m *ConcurrentHashMap) GetOrDefault(key string, defVal interface{}) interface{}

GetOrDefault returns the value of the entry mapped by the given key. If there is mopping by the given key, it returns default value argument.

func (*ConcurrentHashMap) Put

func (m *ConcurrentHashMap) Put(key string, value interface{})

Put maps the given key to the value, and saves the entry. In case of there is already an entry mapped by the given key, it updates the value of the entry.

func (*ConcurrentHashMap) Remove

func (m *ConcurrentHashMap) Remove(key string) (interface{}, bool)

Remove removes the entry mapped by the given key and returns value of removed entry and true. In case of there is entry by the given key, It returns nil and false.

func (*ConcurrentHashMap) Size

func (m *ConcurrentHashMap) Size() int

Size returns the count of entries in the map

Jump to

Keyboard shortcuts

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