Debian Codegraph @

test/fixedbugs/issue62203.go

raw
1 // run
2
3 // Copyright 2023 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
6
7 package main
8
9 import (
10 "fmt"
11 "maps"
12 )
13
14 func main() {
15 m := map[string]struct{}{}
16
17 // Fill m up to the max for 4 buckets = 48 entries.
18 for i := 0; i < 48; i++ {
19 m[fmt.Sprintf("%d", i)] = struct{}{}
20 }
21
22 // Add a 49th entry, to start a grow to 8 buckets.
23 m["foo"] = struct{}{}
24
25 // Remove that 49th entry. m is still growing to 8 buckets,
26 // but a clone of m will only have 4 buckets because it
27 // only needs to fit 48 entries.
28 delete(m, "foo")
29
30 // Clone an 8-bucket map to a 4-bucket map.
31 _ = maps.Clone(m)
32 }