Skip to content

Commit

Permalink
Add optional callback to the CTable:resize() method
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandergall committed Mar 15, 2018
1 parent 54780c2 commit 3002614
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/lib/ctable.lua
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ local optional_params = {
hash_seed = false,
initial_size = 8,
max_occupancy_rate = 0.9,
min_occupancy_rate = 0.0
min_occupancy_rate = 0.0,
resize_callback = false
}

function new(params)
Expand All @@ -153,6 +154,7 @@ function new(params)
ctab.occupancy = 0
ctab.max_occupancy_rate = params.max_occupancy_rate
ctab.min_occupancy_rate = params.min_occupancy_rate
ctab.resize_callback = params.resize_callback
ctab = setmetatable(ctab, { __index = CTable })
ctab:reseed_hash_function(params.hash_seed)
ctab:resize(params.initial_size)
Expand Down Expand Up @@ -236,6 +238,9 @@ function CTable:resize(size)
self:add(old_entries[i].key, old_entries[i].value)
end
end
if self.resize_callback then
self.resize_callback(self, old_size)
end
end

function CTable:get_backing_size()
Expand Down

0 comments on commit 3002614

Please sign in to comment.