Beispiel #1
0
func (sms *SafeMapStore) Set(key, fld string, val interface{}) bool {
	sm, ok := sms.GetSafeMap(key)
	if !ok {
		sms.Lock()
		sms.SafeMaps[key] = safemap.NewSafeMap(safemap.SHARD_COUNT)
		sm = sms.SafeMaps[key]
		sms.Unlock()
	}
	return sm.Set(fld, val)
}
Beispiel #2
0
func (sms *SafeMapStore) AddStore(key string) bool {
	if _, ok := sms.GetSafeMap(key); !ok {
		sms.Lock()
		sms.SafeMaps[key] = safemap.NewSafeMap(safemap.SHARD_COUNT)
		sms.Unlock()
	}
	sms.RLock()
	_, ok := sms.SafeMaps[key]
	sms.RUnlock()
	return ok
}
Beispiel #3
0
func main() {

	sm := safemap.NewSafeMap(32)

	fmt.Printf("Adding %d elements to map...\n", COUNT)

	t1 := ms()

	for i := 0; i < COUNT; i++ {
		key := fmt.Sprintf("key-%d", i)
		val := fmt.Sprintf("val-%d", i)
		sm.Set(key, []byte(val))
	}

	fmt.Printf("Took %dms\n", ms()-t1)

	bufio.NewReader(os.Stdin).ReadBytes('\n')
}