Introduction

A map container with a concurrent safety switch option, the most commonly used data structure. This module includes map containers with multiple data structures: HashMap, TreeMap, and ListMap.

TypeData StructureAverage ComplexitySupports SortingOrdered TraversalDescription
HashMapHash TableO(1)NoNoHigh performance read/write operation, high memory usage, random traversal
ListMapHash Table + Doubly Linked ListO(2)NoYesSupports traversal in the order of insertion, high memory usage
TreeMapRed Black TreeO(log N)YesYesCompact memory usage, supports key name sorting and ordered traversal

Map - 图1tip

Additionally, the gmap module supports defining common types of map with hash table as the underlying data structure: IntIntMap, IntStrMap, IntAnyMap, StrIntMap, StrStrMap, StrAnyMap.

Usage Scenarios:

Any map/hash table/associative array usage scenario, particularly in concurrent safety scenarios.

Usage Method:

  1. import "github.com/gogf/gf/v2/container/gmap"

Interface Documentation:

https://pkg.go.dev/github.com/gogf/gf/v2/container/gmap

Documentation

📄️ Map - UsageBasic usage of the gmap module under the GoFrame framework, including switching operations of concurrent security features, setting, querying, and deleting key-value pairs, as well as ordered traversal, serialization and deserialization of data structures, with detailed code examples and execution results.

📄️ Map - PerformanceDetailed testing and analysis of the performance of dictionary types. By comparing the performance of gmap in the GoFrame framework with the standard library’s sync.Map, the efficiency in different scenarios of concurrent safety and non-concurrent safety is revealed. Includes performance benchmarking of different types of maps such as HashMap, ListMap, and TreeMap, providing developers with real-time reference for optimizing applications.

📄️ Map - MethodsVarious methods of the AnyAnyMap in the GoFrame framework, including operations such as creation, cloning, iteration, setting, deletion, and merging. Code examples are provided to help understand the use of these methods to ensure concurrency safety. For more detailed information, refer to the GoFrame Framework documentation.