Merge pull request #1903 from josephcsible/fixer

Only perform the comparisons once
This commit is contained in:
Vidar Holen 2020-04-11 17:23:51 -07:00 committed by GitHub
commit ab1610b004
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 8 deletions

View File

@ -273,10 +273,10 @@ getPrefixSum = f 0
where
f sum _ PSLeaf = sum
f sum target (PSBranch pivot left right cumulative) =
case () of
_ | target < pivot -> f sum target left
_ | target > pivot -> f (sum+cumulative) target right
_ -> sum+cumulative
case target `compare` pivot of
LT -> f sum target left
GT -> f (sum+cumulative) target right
EQ -> sum+cumulative
-- Add a value to the Prefix Sum tree at the given index.
-- Values accumulate: addPSValue 42 2 . addPSValue 42 3 == addPSValue 42 5
@ -285,10 +285,10 @@ addPSValue key value tree = if value == 0 then tree else f tree
where
f PSLeaf = PSBranch key PSLeaf PSLeaf value
f (PSBranch pivot left right sum) =
case () of
_ | key < pivot -> PSBranch pivot (f left) right (sum + value)
_ | key > pivot -> PSBranch pivot left (f right) sum
_ -> PSBranch pivot left right (sum + value)
case key `compare` pivot of
LT -> PSBranch pivot (f left) right (sum + value)
GT -> PSBranch pivot left (f right) sum
EQ -> PSBranch pivot left right (sum + value)
prop_pstreeSumsCorrectly kvs targets =
let