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 where
f sum _ PSLeaf = sum f sum _ PSLeaf = sum
f sum target (PSBranch pivot left right cumulative) = f sum target (PSBranch pivot left right cumulative) =
case () of case target `compare` pivot of
_ | target < pivot -> f sum target left LT -> f sum target left
_ | target > pivot -> f (sum+cumulative) target right GT -> f (sum+cumulative) target right
_ -> sum+cumulative EQ -> sum+cumulative
-- Add a value to the Prefix Sum tree at the given index. -- Add a value to the Prefix Sum tree at the given index.
-- Values accumulate: addPSValue 42 2 . addPSValue 42 3 == addPSValue 42 5 -- 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 where
f PSLeaf = PSBranch key PSLeaf PSLeaf value f PSLeaf = PSBranch key PSLeaf PSLeaf value
f (PSBranch pivot left right sum) = f (PSBranch pivot left right sum) =
case () of case key `compare` pivot of
_ | key < pivot -> PSBranch pivot (f left) right (sum + value) LT -> PSBranch pivot (f left) right (sum + value)
_ | key > pivot -> PSBranch pivot left (f right) sum GT -> PSBranch pivot left (f right) sum
_ -> PSBranch pivot left right (sum + value) EQ -> PSBranch pivot left right (sum + value)
prop_pstreeSumsCorrectly kvs targets = prop_pstreeSumsCorrectly kvs targets =
let let