-
Notifications
You must be signed in to change notification settings - Fork 276
/
Copy pathLocalIds.hs
47 lines (34 loc) · 1.79 KB
/
LocalIds.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
{-# LANGUAGE DerivingVia #-}
module U.Codebase.Sqlite.LocalIds where
import Control.Lens
import Data.Bifoldable (Bifoldable (bifoldMap))
import Data.Bitraversable (Bitraversable (bitraverse))
import Data.Bits (Bits)
import Data.Vector (Vector)
import Data.Word (Word64)
import U.Codebase.Sqlite.DbId
-- | A mapping between index ids that are local to an object and the ids in the database
data LocalIds' t h = LocalIds
{ textLookup :: Vector t,
defnLookup :: Vector h
}
deriving (Functor, Show)
type LocalIds = LocalIds' TextId ObjectId
type WatchLocalIds = LocalIds' TextId HashId
-- | represents an index into a textLookup
newtype LocalTextId = LocalTextId Word64 deriving (Eq, Ord, Show, Num, Real, Enum, Integral, Bits) via Word64
-- | represents an index into a defnLookup
--
-- In this context, "definition" means an object that is either a term component or a (type) decl component, not a
-- patch, namespace, or any other kind of object.
newtype LocalDefnId = LocalDefnId Word64 deriving (Eq, Ord, Show, Num, Real, Enum, Integral, Bits) via Word64
-- | a local index to a hash, used when the corresponding object is allowed to be absent
newtype LocalHashId = LocalHashId Word64 deriving (Eq, Ord, Show, Num, Real, Enum, Integral, Bits) via Word64
newtype LocalPatchObjectId = LocalPatchObjectId Word64 deriving (Eq, Ord, Show, Num, Real, Enum, Integral, Bits) via Word64
newtype LocalBranchChildId = LocalBranchChildId Word64 deriving (Eq, Ord, Show, Num, Real, Enum, Integral, Bits) via Word64
instance Bitraversable LocalIds' where
bitraverse f g (LocalIds t d) = LocalIds <$> traverse f t <*> traverse g d
instance Bifoldable LocalIds' where
bifoldMap f g (LocalIds t d) = foldMap f t <> foldMap g d
instance Bifunctor LocalIds' where
bimap f g (LocalIds t d) = LocalIds (f <$> t) (g <$> d)