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

Robindict with metadata #890

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
address review comments
  • Loading branch information
eulerkochy authored and Koustav Chowdhury committed Jan 5, 2024
commit 89b4e231398c5bcdf38c8cadc30d60c3e0bfc275
8 changes: 4 additions & 4 deletions src/robin_dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ desired_index(hash, sz) = (hash & (sz - 1)) + 1

function make_meta(hash::UInt32, dibs::Int)
meta = hash
meta = (meta << 8) | UInt32(dibs)
meta = (meta << 8) | (dibs % UInt32)
return meta
end

hash_meta(meta::UInt32) = (meta>>8)
dibs_meta(meta::UInt32) = Int(meta & 255)
dibs_meta(meta::UInt32) = Int(meta & 0x0000_00FF)

@propagate_inbounds calculate_distance(h::RobinDict, index) = dibs_meta(h.meta[index])

Expand Down Expand Up @@ -124,7 +124,7 @@ function rh_insert!(h::RobinDict{K, V}, key::K, val::V) where {K, V}
if probe_current > probe_distance
h.vals[index_curr], cval = cval, h.vals[index_curr]
h.keys[index_curr], ckey = ckey, h.keys[index_curr]
cmeta >>= 8
cmeta = hash_meta(cmeta)
h.meta[index_curr], cmeta = make_meta(cmeta, probe_current), h.meta[index_curr]
probe_current = probe_distance
end
Expand All @@ -144,7 +144,7 @@ function rh_insert!(h::RobinDict{K, V}, key::K, val::V) where {K, V}
# println(ckey, " ", index_curr, " ", index_init, " ", probe_current)
@inbounds h.vals[index_curr] = cval
@inbounds h.keys[index_curr] = ckey
cmeta >>= 8
cmeta = hash_meta(cmeta)
@inbounds h.meta[index_curr] = make_meta(cmeta, probe_current)

@assert probe_current >= 0
Expand Down