コード例 #1
0
ファイル: enumerablewithkey.go プロジェクト: junan/gods
func printMap(txt string, m *treemap.Map) {
	fmt.Print(txt, " { ")
	m.Each(func(key interface{}, value interface{}) {
		fmt.Print(key, ":", value, " ")
	})
	fmt.Println("}")
}
コード例 #2
0
func treemapInsert(theMap *treemap.Map, key int64, target string) {
	value, _ := theMap.Get(key)
	var entry []string
	if value == nil {
		entry = []string{target}
	} else {
		entry = value.([]string)
		entry = append(entry, target)
	}
	theMap.Put(key, entry)
}
コード例 #3
0
func treemapRemove(theMap *treemap.Map, key int64, target string) {
	value, _ := theMap.Get(key)
	if value == nil {
		cacheLogger.Error("Could not find element in treemap")
		return
	}
	entry := value.([]string)
	foundIndex := -1
	for index, targetJ := range entry {
		if target == targetJ {
			foundIndex = index
			break
		}
	}
	if foundIndex == -1 {
		cacheLogger.Error("Could not find element in treemap")
		return
	}
	entry = append(entry[:foundIndex], entry[foundIndex+1:]...)
	theMap.Put(key, entry)
}