map: faster get and exists

pull/4799/head
ka-weihe 2020-05-09 12:42:01 +02:00 committed by GitHub
parent 1c8d2c21b5
commit 85763d0539
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 39 additions and 35 deletions

View File

@ -340,28 +340,32 @@ fn (m mut map) cached_rehash(old_cap u32) {
fn (m map) get3(key string, zero voidptr) voidptr {
mut index,mut meta := m.key_to_index(key)
index,meta = m.meta_less(index, meta)
for meta == m.metas[index] {
for {
if meta == m.metas[index] {
kv_index := m.metas[index + 1]
if fast_string_eq(key, m.key_values.keys[kv_index]) {
return voidptr(m.key_values.values + kv_index * m.value_bytes)
}
}
index += 2
meta += probe_inc
if meta > m.metas[index] { break }
}
return zero
}
fn (m map) exists(key string) bool {
mut index,mut meta := m.key_to_index(key)
index,meta = m.meta_less(index, meta)
for meta == m.metas[index] {
for {
if meta == m.metas[index] {
kv_index := m.metas[index + 1]
if fast_string_eq(key, m.key_values.keys[kv_index]) {
return true
}
}
index += 2
meta += probe_inc
if meta > m.metas[index] { break }
}
return false
}