Skip to content

kolobovdg/gomap-concurrent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gomap-concurrent

Build Status Go Report Card Sourcegraph GolangCI codecov

Concurrent general-purpose shared map for using with flexible key/value data. Suggest minimal expenditure of effort for configuration and best perfomance.

Thread-safety!

Import

Import the package:

import (
	gmap "github.com/kolobovdg/gomap-concurrent"
)
go get "github.com/kolobovdg/gomap-concurrent"

Running tests:

go test "github.com/kolobovdg/gomap-concurrent"

Examples

    // Resolver examples avaliable in map_resolvers.go
    func baseIntResolver(key interface{}, sCount uint16) uint {
        return uint(key.(int)) % uint(sCount)
    }

    
    targetShards := uint16(32)
    m := NewMapWithResolver(resolver, targetShards)
    
    value := "x"
    
    m.Set(key, value)               // Set
    value, exists := m.Get(key)     // Get
    value, exists := m.Delete(key)  // Del
    
    lenOfMap := m.Len()

In case of need to store different types of keys:

    // Test struct for make an example of struct resolving in shared map
    type TestStruct struct {
    	sVar    string
    	uintVar uint32
    }
    
    // Example resolver for mixed types of keys
    func exampleTestMixedStructResolver(key interface{}, sCount uint16) uint {
    	switch key.(type) {
    	case int:
    		return baseIntResolver(key, sCount)
    	case uint32:
    		return baseUint32Resolver(key, sCount)
    	case string:
    		return baseStringResolver(key, sCount)
    	case TestStruct:
    		return exampleTestStructResolver(key, sCount)
    	}
    	// Default case if any others didn't fit
    	return 0
    }

Releases

No releases published

Packages

No packages published

Languages