From 74c361d7dec8f93863d1b0e91f89cbd3f646777e Mon Sep 17 00:00:00 2001 From: Steffen Jost Date: Fri, 1 Oct 2021 14:09:58 +0200 Subject: [PATCH 1/3] fix(build): update frontend hash --- nix/uniworx/well-known.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nix/uniworx/well-known.nix b/nix/uniworx/well-known.nix index 9e0ab278f..8fb593780 100644 --- a/nix/uniworx/well-known.nix +++ b/nix/uniworx/well-known.nix @@ -18,6 +18,6 @@ outputHashMode = "recursive"; outputHashAlgo = "sha256"; - outputHash = "tDaffdAT5EGPKdDJ2ovo9XSGdV48W3Efqe+iBmakh6g="; + outputHash = "+KhpKGRRBVyDm+uBfI02uRpMDuMykZl5yWO6QjOCii4="; }; } From f411fde42d913d5a9ef357674ab77934c8e1ba42 Mon Sep 17 00:00:00 2001 From: Steffen Jost Date: Mon, 4 Oct 2021 16:43:58 +0200 Subject: [PATCH 2/3] fix(holidays): minor improvement to memoization --- src/Utils/Holidays.hs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Utils/Holidays.hs b/src/Utils/Holidays.hs index 71235acf6..49c140e95 100644 --- a/src/Utils/Holidays.hs +++ b/src/Utils/Holidays.hs @@ -2,7 +2,8 @@ Module: Utils.Holidays Description: German bank holidays -Following module Data.Time.Calendar.BankHoliday.EnglandAndWales +Interfaces follows module Data.Time.Calendar.BankHoliday.EnglandAndWales +isBankHolidayArea uses laziness to provide some simple memoization for a fixed range of years -} module Utils.Holidays ( Feiertagsgebiet(..) @@ -13,7 +14,7 @@ module Utils.Holidays import Import.NoModel -import qualified Data.Set as Set (Set, member, unions) +import qualified Data.Set as Set (Set, member) import qualified Data.Map as Map --import Data.Time.Calendar.WeekDate @@ -112,12 +113,16 @@ isBankHolidayArea land dd = dd `Set.member` holidays holidays | year >= cacheMinYear , year <= cacheMaxYear - , (Just hds) <- Map.lookup land cacheHolidays = hds + , (Just hys) <- Map.lookup land cacheHolidays + , (Just hds) <- Map.lookup year hys = hds | otherwise = bankHolidaysAreaSet land year cacheMinYear, cacheMaxYear :: Integer cacheMinYear = 2020 cacheMaxYear = 2075 -cacheHolidays :: Map.Map Feiertagsgebiet (Set.Set Day) -cacheHolidays = Map.fromList [ (land, Set.unions $ bankHolidaysAreaSet land <$> [cacheMinYear..cacheMaxYear]) | land <- universeF ] +cacheHolidays :: Map.Map Feiertagsgebiet (Map.Map Integer (Set.Set Day)) +cacheHolidays = Map.fromList [(land, Map.fromList + [(year, bankHolidaysAreaSet land year) + | year <- [cacheMinYear..cacheMaxYear]]) + | land <- universeF] \ No newline at end of file From d2938e3ae90def29736ccb884bfebfcd275cb4a9 Mon Sep 17 00:00:00 2001 From: Steffen Jost Date: Tue, 5 Oct 2021 12:35:12 +0200 Subject: [PATCH 3/3] fix(holidays): add proper memoization to yet unused function --- src/Utils/Holidays.hs | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/src/Utils/Holidays.hs b/src/Utils/Holidays.hs index 49c140e95..5b8d317a3 100644 --- a/src/Utils/Holidays.hs +++ b/src/Utils/Holidays.hs @@ -105,24 +105,35 @@ isBankHolidayArea land dd = dd `Set.member` holidays -} -- | Returns whether a day is a bank holiday for years >= 1995 --- | Repeated calls are handled efficiently using a lazy cache for 2020--2075 +-- | Repeated calls are handled efficiently using lazy memoization isBankHolidayArea :: Feiertagsgebiet -> Day -> Bool isBankHolidayArea land dd = dd `Set.member` holidays where (year, _, _) = toGregorian dd holidays - | year >= cacheMinYear - , year <= cacheMaxYear - , (Just hys) <- Map.lookup land cacheHolidays - , (Just hds) <- Map.lookup year hys = hds + | (Just hys) <- Map.lookup land memoHolidays + , (Just hds) <- index hys $ fromInteger $ year2index year = hds | otherwise = bankHolidaysAreaSet land year -cacheMinYear, cacheMaxYear :: Integer -cacheMinYear = 2020 -cacheMaxYear = 2075 +-- memoize holidays +memoHolidays :: Map.Map Feiertagsgebiet [Set.Set Day] +memoHolidays = Map.fromList [(land, + [bankHolidaysAreaSet land year + | i <- [0..], let year = index2year i]) + | land <- universeF] -cacheHolidays :: Map.Map Feiertagsgebiet (Map.Map Integer (Set.Set Day)) -cacheHolidays = Map.fromList [(land, Map.fromList - [(year, bankHolidaysAreaSet land year) - | year <- [cacheMinYear..cacheMaxYear]]) - | land <- universeF] \ No newline at end of file +-- year with fastest access +memoTip :: Integer +memoTip = 2030 + +year2index :: Integer -> Integer +year2index y + | y < memoTip = 2 * (memoTip - y) - 1 + | otherwise = 2 * (y - memoTip) + +index2year :: Integer -> Integer +index2year y = result + where + (x,r) = y `divMod` 2 + result | r == 0 = memoTip + x + | otherwise = memoTip - x - 1