cmap

package module
v0.0.0-...-0c5e570 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2016 License: Apache-2.0 Imports: 4 Imported by: 15

README

go-cmap

Golang concurrency map

Usage

$ go get github.com/antlinker/go-cmap

Benchmark

BenchmarkGoMap-8                 2000000              1308 ns/op
BenchmarkNolockGoMap-8           2000000              1172 ns/op
BenchmarkConcurrencyMap-8        2000000               758 ns/op

License

Copyright 2015.All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Documentation

Index

Constants

View Source
const (
	// DefaultPoolSize 提供分配共享池大小的默认值
	DefaultPoolSize = 1 << 5
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ConcurrencyElement

type ConcurrencyElement struct {
	Key   interface{}
	Value interface{}
}

ConcurrencyElement 存储的元素项

type ConcurrencyMap

type ConcurrencyMap interface {
	// Get 获取给定键值对应的元素值。若没有对应的元素值则返回nil
	Get(key interface{}) (interface{}, error)
	// Set 给指定的键设置元素值。若该键值已存在,则替换
	Set(key interface{}, elem interface{}) error
	// SetIfAbsent 给指定的键设置元素值。
	// 若该键值已存在,则不替换,并返回已经存在的值同时返回false
	// 若改键值不存在,则增加该键值同时返回true
	SetIfAbsent(key interface{}, elem interface{}) (interface{}, bool)
	// Remove 删除给定键值对应的键值对,并返回旧的元素值。若没有旧元素的值则返回nil
	Remove(key interface{}) (interface{}, error)
	// Contains 判断是否包含给定的键值
	Contains(key interface{}) (bool, error)
	// Clear 清除所有的键值对
	Clear()
	// Len 获取键值对的数量
	Len() int
	// ToMap 获取已包含的键值对所组成的字典值
	ToMap() map[interface{}]interface{}
	// Elements 获取并发Map中的元素
	Elements() <-chan ConcurrencyElement
	// Keys 获取所有的键数据
	Keys() []interface{}
	// Values 获取所有的值数据
	Values() []interface{}
}

ConcurrencyMap 并发的Map接口

func NewConcurrencyMap

func NewConcurrencyMap(poolSizes ...uint) ConcurrencyMap

NewConcurrencyMap 创建并发的Map接口 poolSize 分配共享池的大小,默认为32

Jump to

Keyboard shortcuts

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