mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
map: fix in
for deleted keys
This commit is contained in:
parent
39adc984a8
commit
57fbf0b8a9
@ -16,7 +16,7 @@ pub:
|
|||||||
struct mapnode {
|
struct mapnode {
|
||||||
left &mapnode
|
left &mapnode
|
||||||
right &mapnode
|
right &mapnode
|
||||||
is_empty bool
|
is_empty bool // set by delete()
|
||||||
key string
|
key string
|
||||||
val voidptr
|
val voidptr
|
||||||
}
|
}
|
||||||
@ -97,7 +97,7 @@ fn (n & mapnode) find(key string, out voidptr, element_size int) bool{
|
|||||||
|
|
||||||
// same as `find`, but doesn't return a value. Used by `exists`
|
// same as `find`, but doesn't return a value. Used by `exists`
|
||||||
fn (n & mapnode) find2(key string, element_size int) bool{
|
fn (n & mapnode) find2(key string, element_size int) bool{
|
||||||
if n.key == key {
|
if n.key == key && !n.is_empty {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
else if n.key > key {
|
else if n.key > key {
|
||||||
|
@ -168,6 +168,17 @@ fn test_mut_arg() {
|
|||||||
assert m['a'] == 10
|
assert m['a'] == 10
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn test_delete() {
|
||||||
|
mut m := map[string]int
|
||||||
|
m['one'] = 1
|
||||||
|
m['two'] = 2
|
||||||
|
println(m['two']) // => "2"
|
||||||
|
m.delete('two')
|
||||||
|
println(m['two']) // => 0
|
||||||
|
assert 'two' in m == false
|
||||||
|
println('two' in m) // => true, on Linux and Windows <-- wrong !
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
fn test_ref() {
|
fn test_ref() {
|
||||||
m := { 'one': 1 }
|
m := { 'one': 1 }
|
||||||
|
Loading…
Reference in New Issue
Block a user