March 2019
Intermediate to advanced
336 pages
9h 9m
English
A has a Put method, as shown in the following example, that takes the key and value parameters of the DictKey and DictVal types respectively. The Lock method of the dictionary's lock instance is invoked, and the Unlock method is deferred. If there are empty map elements in the dictionary, elements are initialized using make. The map elements are set with a key and a value if they are not empty:
// Put methodfunc (dict *Dictionary) Put(key DictKey, value DictVal) { dict.lock.Lock() defer dict.lock.Unlock() if dict.elements == nil { dict.elements = make(map[DictKey]DictVal) } dict.elements[key] = value}
The example output of the put method is as follows. The put method takes the key 1 and value 1. The map is updated with key ...
Read now
Unlock full access