10 examples of 'assignment to entry in nil map' in Go

Every line of 'assignment to entry in nil map' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Go code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
16func (m *ConcurrentReadMap) initMapEntry(key string, newEntry func() interface{}) (value interface{}) {
17 m.Lock()
18 defer m.Unlock()
19 if value, ok := m.items[key]; ok {
20 return value
21 }
22 value = newEntry()
23 m.items[key] = value
24 return value
25}
328func AssignListEntryInt(e *error, la ipld.ListAssembler, v int64) {
329 if *e != nil {
330 return
331 }
332 *e = la.AssembleValue().AssignInt(v)
333}
12func (buffer *dictEntryBuffer) entry(key Word) *dictEntry {
13 bucketIndex := int(key) >> dictEntryBucketSizeBits
14 index := int(key & ((1 << dictEntryBucketSizeBits) - 1))
15
16 for bucketIndex >= len(buffer.buckets) {
17 buffer.buckets = append(buffer.buckets, new(dictEntryBucket))
18 }
19
20 return &buffer.buckets[bucketIndex][index]
21}
893func (n *mapArrayNode) set(key, value interface{}, shift uint, keyHash uint32, h Hasher, mutable bool, resized *bool) mapNode {
894 idx := n.indexOf(key, h)
895
896 // Mark as resized if the key doesn't exist.
897 if idx == -1 {
898 *resized = true
899 }
900
901 // If we are adding and it crosses the max size threshold, expand the node.
902 // We do this by continually setting the entries to a value node and expanding.
903 if idx == -1 && len(n.entries) >= maxArrayMapSize {
904 var node mapNode = newMapValueNode(h.Hash(key), key, value)
905 for _, entry := range n.entries {
906 node = node.set(entry.key, entry.value, 0, h.Hash(entry.key), h, false, resized)
907 }
908 return node
909 }
910
911 // Update in-place if mutable.
912 if mutable {
913 if idx != -1 {
914 n.entries[idx] = mapEntry{key, value}
915 } else {
916 n.entries = append(n.entries, mapEntry{key, value})
917 }
918 return n
919 }
920
921 // Update existing entry if a match is found.
922 // Otherwise append to the end of the element list if it doesn't exist.
923 var other mapArrayNode
924 if idx != -1 {
925 other.entries = make([]mapEntry, len(n.entries))
926 copy(other.entries, n.entries)
927 other.entries[idx] = mapEntry{key, value}
928 } else {
929 other.entries = make([]mapEntry, len(n.entries)+1)
930 copy(other.entries, n.entries)
931 other.entries[len(other.entries)-1] = mapEntry{key, value}
932 }
933 return &other
934}
235func (t *redBlack) _put(n *rbNode, key, value interface{}) *rbNode {
236 if n == nil {
237 return &rbNode{
238 key: key,
239 value: value,
240 size: 1,
241 color: red,
242 }
243 }
244
245 cmp := t.compareKey(key, n.key)
246 switch {
247 case cmp < 0:
248 n.left = t._put(n.left, key, value)
249 case cmp > 0:
250 n.right = t._put(n.right, key, value)
251 default:
252 n.value = value
253 }
254
255 // fix-up any right-leaning links
256 if t.isRed(n.right) && !t.isRed(n.left) {
257 n = t.rotateLeft(n)
258 }
259 if t.isRed(n.left) && t.isRed(n.left.left) {
260 n = t.rotateRight(n)
261 }
262 if t.isRed(n.left) && t.isRed(n.right) {
263 t.flipColors(n)
264 }
265
266 n.size = 1 + t.size(n.left) + t.size(n.right)
267 return n
268}
27func (t *TrieRWay) put(node *TRNode, key string, val interface{}, position int) *TRNode {
28 if node == nil {
29 node = &TRNode{
30 Next: make([]*TRNode, t.N),
31 }
32 }
33 if position == len(key)-1 {
34 node.Key = val
35 return node
36 }
37 index := key[position] - 'a'
38 node.Next[index] = t.put(node.Next[index], key, val, position+1)
39 return node
40}
111func (t *table) put(l *State, k, v value) {
112 switch k := k.(type) {
113 case nil:
114 l.runtimeError("table index is nil")
115 case float64:
116 if i := int(k); float64(i) == k {
117 t.putAtInt(i, v)
118 } else if math.IsNaN(k) {
119 l.runtimeError("table index is NaN")
120 } else if v == nil {
121 delete(t.hash, k)
122 } else {
123 t.hash[k] = v
124 }
125 case string:
126 if v == nil {
127 delete(t.hash, k)
128 } else {
129 t.hash[k] = v
130 }
131 default:
132 if v == nil {
133 delete(t.hash, k)
134 } else {
135 t.hash[k] = v
136 }
137 }
138}
819func mapassign(typ unsafe.Pointer, m unsafe.Pointer, key, val unsafe.Pointer)
27func (kv *KeyValue) Put(key, value []byte) {
28 if n := len(kv.entries); n > 0 && cmp.Compare(kv.entries[n-1].key, key) >= 0 {
29 panic(fmt.Sprintf("Put: keys are not in increasing order: %q, %q", kv.entries[n-1].key, key))
30 }
31 kv.entries = append(kv.entries, KeyValueEntry{key, value})
32 kv.nbytes += len(key) + len(value)
33}
267func AssignMapEntryBytes(e *error, ma ipld.MapAssembler, k string, v []byte) {
268 if *e != nil {
269 return
270 }
271 va, err := ma.AssembleEntry(k)
272 if err != nil {
273 *e = err
274 return
275 }
276 *e = va.AssignBytes(v)
277}

Related snippets