Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After calling clear() on a map several times, duplicate keys are allowed #22145

Closed
ratkingsminion opened this issue Sep 1, 2024 · 0 comments · Fixed by #22146
Closed

After calling clear() on a map several times, duplicate keys are allowed #22145

ratkingsminion opened this issue Sep 1, 2024 · 0 comments · Fixed by #22146
Labels
Bug This tag is applied to issues which reports bugs. Modules: builtin Bugs and problems, concerning the builtin types in V - array, maps, strings, runes. Status: Confirmed This bug has been confirmed to be valid by a contributor.

Comments

@ratkingsminion
Copy link

ratkingsminion commented Sep 1, 2024

Describe the bug

Code: https://play.vlang.io/p/e1f1a32c15

t := [30, 38, 36, 31, 39, 37, 24, 32, 25, 33, 18, 26, 11, 18, 12,
	  4, 10, 17, 16, 11, 3, 9, 2, 23, 30, 24, 16, 22, 23, 17, 9,
	  15, 10, 2, 8, 3, 1, 0, 7, 14, 29, 21]
println("array t len: ${t.len}")
mut m := map[int]int{}
for i in 0..12 {
	m.clear()
	mut n := map[int]int{}
	for e in t {
		m[e] = 0
		n[e] = 0
	}
	println("index ${i}")
	println(">> map m: ${m.len}") // - ${m.keys()}") // was cleared
	println(">> map n: ${n.len}") // - ${n.keys()}") // is a new map
}

Reproduction Steps

Run the code above

Expected Behavior

Map m and map n should always have the same number of elements.

Current Behavior

After around 8 iterations, map m begins to allow duplicate keys, which gets worse later on.

Output:

array t len: 42
index 0
>> map m: 31
>> map n: 31
index 1
>> map m: 31
>> map n: 31
index 2
>> map m: 31
>> map n: 31
index 3
>> map m: 31
>> map n: 31
index 4
>> map m: 31
>> map n: 31
index 5
>> map m: 31
>> map n: 31
index 6
>> map m: 31
>> map n: 31
index 7
>> map m: 31
>> map n: 31
index 8
>> map m: 32
>> map n: 31
index 9
>> map m: 36
>> map n: 31
index 10
>> map m: 36
>> map n: 31
index 11
>> map m: 36
>> map n: 31

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.7 fc31b44

Environment details (OS name and version, etc.)

V full version: V 0.4.7 fc31b44
OS: linux, Debian GNU/Linux 11 (bullseye) (VM)
Processor: 1 cpus, 64bit, little endian, Intel(R) Xeon(R) CPU E5-2686 v4 @ 2.30GHz

getwd: /home/admin/playground
vexe: /home/admin/v/v
vexe mtime: 2024-09-01 14:42:05

vroot: OK, value: /home/admin/v
VMODULES: OK, value: .vmodules
VTMP: OK, value: /tmp/v_0

Git version: git version 2.30.2
Git vroot status: Error: fatal: detected dubious ownership in repository at '/home/admin/v'
To add an exception for this directory, call:

	git config --global --add safe.directory /home/admin/v
.git/config present: true

CC version: cc (Debian 10.2.1-6) 10.2.1 20210110
thirdparty/tcc status: Error: fatal: detected dubious ownership in repository at '/home/admin/v/thirdparty/tcc'
To add an exception for this directory, call:

	git config --global --add safe.directory /home/admin/v/thirdparty/tcc
 Error: fatal: detected dubious ownership in repository at '/home/admin/v/thirdparty/tcc'
To add an exception for this directory, call:

	git config --global --add safe.directory /home/admin/v/thirdparty/tcc

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

@ratkingsminion ratkingsminion added the Bug This tag is applied to issues which reports bugs. label Sep 1, 2024
spytheman added a commit to spytheman/v that referenced this issue Sep 1, 2024
…}`, after multiple iterations of setting keys and clearing (fix vlang#22145)
@spytheman spytheman added Modules: builtin Bugs and problems, concerning the builtin types in V - array, maps, strings, runes. Status: Confirmed This bug has been confirmed to be valid by a contributor. labels Sep 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs. Modules: builtin Bugs and problems, concerning the builtin types in V - array, maps, strings, runes. Status: Confirmed This bug has been confirmed to be valid by a contributor.
Projects
None yet
2 participants