I have the following C formula
bucket = (hash - _min) * ((_capacity-1) / range());
What I need to to rearran开发者_高级运维ge the equation to return the _capacity instead of bucket (I have all other variables apart from _capacity). e.g.
96 = (926234929-805306368) * (( x -1) /1249540730)
836 = (1852139639-805306368) * ((x -1) /1249540730)
As you can see it's a fairly simple equation, all I need is x on the left. But my algebra is very rusty, so any help appreciated.
capacity = (range() * bucket) / (hash - _min) + 1;
bucket = (hash - _min) * ((_capacity - 1) / range()); // start
bucket = ((hash - _min) * (_capacity - 1)) / range(); // rearrange
range() * bucket = (hash - _min) * (_capacity - 1); // multiply by range
(range() * bucket) / (hash - _min) = _capacity - 1; // divide by (hash - _min)
(range() * bucket) / (hash - _min) + 1 = _capacity; // add 1
capacity = (range() * bucket) / (hash - _min) + 1; // rearrange
_capacity = 1 + bucket / (hash - _min) * range();
with the provision that hash
can no longer equal _min
.
精彩评论