Documentation ¶
Overview ¶
Package cmap please refer to README.md
Index ¶
- Variables
- type Map
- func (c *Map) Count() int64
- func (c *Map) Get(key string) (interface{}, error)
- func (c *Map) GetElseSet(key string, newValue interface{}) (interface{}, error)
- func (c *Map) Has(key string) bool
- func (c *Map) Iterator() chan Tuple
- func (c *Map) Remove(key string)
- func (c *Map) Set(key string, newValue interface{}) error
- type ShardManager
- type ShardManagerFNV
- type Tuple
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrNoSuchItem indicated no such item exists in the key ErrNoSuchItem = errors.New("no such item") )
Functions ¶
This section is empty.
Types ¶
type Map ¶
type Map struct {
// contains filtered or unexported fields
}
Map is a concurrent map
Example (DefaultSharding) ¶
package main import ( "fmt" "github.com/corsc/go-commons/concurrency/cmap" ) func main() { myMap := cmap.New() val, err := myMap.Get("key") fmt.Printf("Value/Err: %v/%v\n", val, err) err = myMap.Set("key", "foo") fmt.Printf("Err: %v\n", err) val, err = myMap.Get("key") fmt.Printf("Value/Err: %v/%v\n", val, err) }
Output: Value/Err: <nil>/no such item Err: <nil> Value/Err: foo/<nil>
func (*Map) Get ¶
Get will attempt to return the requested key or an error. `ErrNoSuchItem` indicates the item does not exist
func (*Map) GetElseSet ¶
GetElseSet will return the existing value in the map or will set the value using `newValue`. Regardless, this method will return the map item value or an error.
func (*Map) Has ¶
Has will return true if the key exists in the map or false
Note: this method will silently fail on errors
type ShardManager ¶
type ShardManager interface { // Return the total number of shards in this concurrent map GetTotalShards() int64 // Return the shard number for the supplied key GetShardNo(key string) (int64, error) }
ShardManager controls how many shards exist and how keys are hashed
type ShardManagerFNV ¶
type ShardManagerFNV struct {
TotalShards int64
}
ShardManagerFNV implements manager using `hash/fnv.Hash32` to hash the keys
func (*ShardManagerFNV) GetShardNo ¶
func (sm *ShardManagerFNV) GetShardNo(key string) (int64, error)
GetShardNo implements manager
func (*ShardManagerFNV) GetTotalShards ¶
func (sm *ShardManagerFNV) GetTotalShards() int64
GetTotalShards implements manager
Click to show internal directories.
Click to hide internal directories.