- Declared: map[KeyType]ValueType
- Ex. m := make(map[string]int)m["a"]=1m{"b"]=2
- Ex. m := map[string]int {"a":1,"b":2, // Please notice every entry need to be end with comma}
- Key type must be comparable using ==, array can be used as a key to declare a map, but slice is not acceptable.
- Ex. array can be used as key
- Ex. compile error when use slice as a key
- Empty map, length of nil map is 0 as well, but you can't put entry to nil map
- m := make(map[string]int)m := map[string]int{}
- Ex. Delete entrym := map[string]int {"a":1,"b":2}delete(m, "a")
- add 1 to key
- add 1 to entry but key not exist, value will start from 0 because there is still an assignment
- Can't get entry's address, because entry address may change after rehash.Will compile error when trying to get entry's address.Ex. keyP := &m["k"]
- Iterate map by range, the order is random by design intent. To prevent client code depends on the implementation
- If we want to follow order to iterate, need sort key and iterate key to get value
- Zero value of map is nil
- Store a value in map's zero value will panic!! Must allocate the map before using it
- Get value from a nil map will get zero value of the type.
- Check key exist or not
- m = make(map[string]map[string]int)
Go - Maps
訂閱:
文章 (Atom)
Lessons Learned While Benchmarking vLLM with GPU
Recently, I benchmarked vLLM on a GPU to better understand how much throughput can realistically be expected in an LLM serving setup. One ...
-
spring.jpa.open-in-view spring boot 的 property, spring.jpa.open-in-view 預設是開啟的 開啟的話, OpenSessionInViewInterceptor 就會介入 收到 web request 的時候...
-
Introduction One day, Cassandra stop listening for thrift client until restart it manually. After checking Cassandra log, found it enco...
-
ChatGPT generated Java Class Loader 是 Java Runtime Environment 的一部分, 它動態地將 Java 類別加載到 Java Virtual Machine 中。通常,只有在需要時才會加載類別 。Java 運行時系統不需...