summaryrefslogtreecommitdiff
path: root/Types/Key.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-08-01 18:00:47 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-08-01 18:00:47 -0400
commitddbf5df3c9940473663a6e562f8ee3583867046e (patch)
tree40dc81d0c2693b5fd5fc3e5b9cd8df17e0505ec5 /Types/Key.hs
parent154cb13180fbe877d2030d83a415b30150ac7298 (diff)
parentd0a8e3d6217f2924b864393d425b6d7582370d07 (diff)
Merge branch 'newchunks'
I am happy enough with this to make it live!
Diffstat (limited to 'Types/Key.hs')
-rw-r--r--Types/Key.hs15
1 files changed, 15 insertions, 0 deletions
diff --git a/Types/Key.hs b/Types/Key.hs
index 90f66f23e..154e813ff 100644
--- a/Types/Key.hs
+++ b/Types/Key.hs
@@ -13,6 +13,8 @@ module Types.Key (
stubKey,
key2file,
file2key,
+ nonChunkKey,
+ chunkKeyOffset,
prop_idempotent_key_encode,
prop_idempotent_key_decode
@@ -47,6 +49,19 @@ stubKey = Key
, keyChunkNum = Nothing
}
+-- Gets the parent of a chunk key.
+nonChunkKey :: Key -> Key
+nonChunkKey k = k
+ { keyChunkSize = Nothing
+ , keyChunkNum = Nothing
+ }
+
+-- Where a chunk key is offset within its parent.
+chunkKeyOffset :: Key -> Maybe Integer
+chunkKeyOffset k = (*)
+ <$> keyChunkSize k
+ <*> (pred <$> keyChunkNum k)
+
fieldSep :: Char
fieldSep = '-'