Brother Lian Blockchain technology training share the Go Language source code interpretation map

Source: Internet
Author: User

Internet more than 20 years, has reached the crossroads. Before the advent of the blockchain, the internet was known as the classical Internet, and the use of blockchain technology in the Internet only entered the post-Internet era. As a new technology, the blockchain is undoubtedly on the cusp, and its development prospects for the general public will eventually be positive. But at present, because the blockchain technology is in the early stage of development, there are some problems, such as technology maturity and limited application scenario, the Brother Education advises users to carefully consider and discern before choosing professional Go Language + blockchain training institution.


When iterate the entire map, it is safe to use delete. This is not the same as C + +, C + + at the time of delete, will cause the whole tree to change, so you can not delete the elements in the iteration.


Then why Golang map is safe, from the source point of view, Golang map uses the concept of barrels, elements are hash to the bucket storage, each bucket preset is stored eight kv, and in the head has a uint8 TOPHASH[8] structure, Stores the high eight bits of each key (that is, hash (key)» (64-8)), and if the position is not placed on the element, there is a special flag empty. When inserting deletes, the first comparison is whether the uint8 is equal to the hash (key). Of course, buckets also utilize the overflow pointer, which can grow infinitely, like a linked list.


Therefore, the For loop is actually iterating over each bucket, judging each uint8 position, and deleting the operation is not the actual memset, but the position of the corresponding Tophash is set to empty. Therefore, it is safe to use delete during the map process of the iteration Golang.


struct HMAP

{

Uintgo count;  # Live Cells = = size of map. Must is first (used by Len () builtin)

UInt32 flags;

UInt32 Hash0; Hash seed

Uint8 B; Log_2 of # of buckets (can hold up to LOAD * 2^b items)

Uint8 keysize; Key size in bytes

Uint8 valuesize; Value Size in bytes

UInt16 bucketsize; Bucket size in bytes


BYTE *buckets; Array of 2^b Buckets. May is nil if count==0.

BYTE *oldbuckets; Previous bucket array of half the size, Non-nil only when growing

UIntPtr nevacuate; Progress counter for evacuation (buckets less than this has been evacuated)

};


typedef struct Bucket bucket;

struct Bucket

{

Uint8 Tophash[bucketsize]; Top 8 bits of hash of each entry (0 = empty)

Bucket *overflow; Overflow bucket, if any

BYTE data[1]; Bucketsize keys followed by bucketsize values

};

high-energy early warning, brother even education blockchain live course August continues to hit the hot!

The original price of 1188 Yuan of 12 block chain advanced courses, now only need 1 Yuan!

Also can receive free "Go Language foundation actual combat project development" and "Go language Advanced Combat Project development" textbook Two!! Limited time limit!! First come first served!!

Http://www.ydma.cn/open/course/24

Follow brother Lian Blockchain technology public number get more technical dry Goods Oh!!!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.