take maxsize into account for balanced preferred content
This is very innefficient, it will need to be optimised not to calculate the sizes of repos every time. Also, fixed a bug in balancedPicker that caused it to pick a too high index when some repos were excluded due to being full.
This commit is contained in:
parent
b201792391
commit
745bc5c547
5 changed files with 60 additions and 11 deletions
|
@ -21,14 +21,14 @@ type BalancedPicker = S.Set UUID -> Key -> UUID
|
|||
|
||||
-- The set of UUIDs provided here are all the UUIDs that are ever
|
||||
-- expected to be picked amoung. A subset of that can be provided
|
||||
-- when later using the BalancedPicker.
|
||||
-- when later using the BalancedPicker. Neither set can be empty.
|
||||
balancedPicker :: S.Set UUID -> BalancedPicker
|
||||
balancedPicker s = \s' key ->
|
||||
let n = calcMac tointeger HmacSha256 combineduuids (serializeKey' key)
|
||||
m = fromIntegral (S.size s')
|
||||
in S.elemAt (fromIntegral (n `mod` m)) s'
|
||||
where
|
||||
combineduuids = mconcat (map fromUUID (S.toAscList s))
|
||||
m = fromIntegral (S.size s)
|
||||
|
||||
tointeger :: Digest a -> Integer
|
||||
tointeger = foldl' (\i b -> (i `shiftL` 8) + fromIntegral b) 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue