-
Book Overview & Buying
-
Table Of Contents
Practical Systems Programming in Go
By :
Both arrays and slices limit you to using positive integers as indexes, which start from 0 and cannot have gaps in them – this means that even if you want to put data in the slice element at index 99 only, the slice is still going to occupy 100 elements in memory. Maps are more powerful data structures because they allow you to use indexes of various data types as keys to look up your data if these keys are comparable – if a type cannot be compared using == and !=, you cannot use it as a map key. The map syntax and behavior reflect the language design philosophy of making common operations straightforward while maintaining the performance characteristics that systems programming demands. Maps are illustrated with the following example code, which uses the main() function implementation to show the different ways to declare and initialize maps:
func main() {
fmt.Println("=== Go Maps Comprehensive Example ===\n")
fmt.Println(...