|
| 1 | +{-# LANGUAGE DerivingVia #-} |
| 2 | + |
1 | 3 | module U.Codebase.Sqlite.LocalIds where |
2 | 4 |
|
| 5 | +import Data.Bifoldable (Bifoldable (bifoldMap)) |
| 6 | +import Data.Bifunctor (Bifunctor (bimap)) |
| 7 | +import Data.Bitraversable (Bitraversable (bitraverse)) |
| 8 | +import Data.Bits (Bits) |
3 | 9 | import Data.Vector (Vector) |
| 10 | +import Data.Word (Word64) |
4 | 11 | import U.Codebase.Sqlite.DbId |
5 | | -import Data.Bitraversable (Bitraversable(bitraverse)) |
6 | | -import Data.Bifoldable (Bifoldable(bifoldMap)) |
7 | | -import Data.Bifunctor (Bifunctor(bimap)) |
8 | 12 |
|
9 | | --- |A mapping between index ids that are local to an object and the ids in the database |
| 13 | +-- | A mapping between index ids that are local to an object and the ids in the database |
10 | 14 | data LocalIds' t h = LocalIds |
11 | 15 | { textLookup :: Vector t, |
12 | 16 | defnLookup :: Vector h |
13 | 17 | } |
14 | 18 |
|
15 | 19 | type LocalIds = LocalIds' TextId ObjectId |
| 20 | + |
16 | 21 | type WatchLocalIds = LocalIds' TextId HashId |
17 | 22 |
|
| 23 | +-- | represents an index into a textLookup |
| 24 | +newtype LocalTextId = LocalTextId Word64 deriving (Eq, Ord, Num, Real, Enum, Integral, Bits) via Word64 |
| 25 | + |
| 26 | +-- | represents an index into a defnLookup |
| 27 | +newtype LocalDefnId = LocalDefnId Word64 deriving (Eq, Ord, Num, Real, Enum, Integral, Bits) via Word64 |
| 28 | + |
18 | 29 | instance Bitraversable LocalIds' where |
19 | 30 | bitraverse f g (LocalIds t d) = LocalIds <$> traverse f t <*> traverse g d |
| 31 | + |
20 | 32 | instance Bifoldable LocalIds' where |
21 | 33 | bifoldMap f g (LocalIds t d) = foldMap f t <> foldMap g d |
| 34 | + |
22 | 35 | instance Bifunctor LocalIds' where |
23 | 36 | bimap f g (LocalIds t d) = LocalIds (f <$> t) (g <$> d) |
0 commit comments