Get the App
SLTechnology News&Howtos  ›  Development  › 

Can map define length in go language?

Shulou Source: shulou.com Published: 2022-05-31 22:06:40 09月21日 Update

This article mainly introduces the relevant knowledge of "can map define length in go language". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "can map define length in go language" can help you solve the problem.

Map in the go language can define length. Map can scale dynamically according to the new key-value, so there is no fixed length or maximum limit, but you can also choose to mark the initial capacity of map cap, the syntax "make (map [keytype] valuetype, cap)".

The operating environment of this tutorial: windows10 system, GO 1.11.2, Dell G3 computer.

Map in Go language is a special data structure, an unordered set of element pairs (pair). Pair corresponds to an key (index) and a value (value), so this structure is also called associative array or dictionary. It is an ideal structure that can quickly find values. Given key, you can quickly find the corresponding value.

The data structure of map is also known as Python, hash, HashTable, and so on in other programming languages.

Map capacity

Unlike arrays, map can dynamically scale according to the newly added key-value, so it does not have a fixed length or maximum limit, but you can also choose to mark the initial capacity capacity of map in the following format:

Make (map [keytype] valuetype, cap)

For example:

Map2: = make (map [string] float, 100)

When the map grows to the capacity limit, the size of the new key-value,map will be automatically increased by 1, so for performance reasons, for large map or map that will expand rapidly, it is best to mark it first, even if you only know the capacity.

Here is a concrete example of map, which maps the scale to the corresponding audio:

NoteFrequency: = map [string] float32 {"C0": 16.35," D0 ": 18.35," E0": 20.60," F0 ": 21.83," G0": 24.50," A0 ": 27.50," B0": 30.87,440} about "can map define length in go language". Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Tags: Language length capacity structure knowledge difference maximum dynamic dictionary data data structure array industry selection limitation utility special upper limit example element Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker OPPO Reno macOS Shulou Information Xiaomi