{-# LANGUAGE BangPatterns, GeneralizedNewtypeDeriving, MultiParamTypeClasses,
             TypeFamilies #-}
module Data.SearchEngine.DocIdSet (
    DocId(DocId),
    DocIdSet(..),
    null,
    size,
    empty,
    singleton,
    fromList,
    toList,
    insert,
    delete,
    member,
    union,
    unions,
    intersection,
    invariant,
  ) where

import Data.Word
import qualified Data.Vector.Unboxed         as Vec
import qualified Data.Vector.Unboxed.Mutable as MVec
import qualified Data.Vector.Generic         as GVec
import qualified Data.Vector.Generic.Mutable as GMVec
import Control.Monad.ST
import Control.Monad (liftM)
import qualified Data.Set as Set
import Data.List (foldl', sortBy)
import Data.Function (on)

import Prelude hiding (null)


newtype DocId = DocId { DocId -> Word32
unDocId :: Word32 }
  deriving (DocId -> DocId -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DocId -> DocId -> Bool
$c/= :: DocId -> DocId -> Bool
== :: DocId -> DocId -> Bool
$c== :: DocId -> DocId -> Bool
Eq, Eq DocId
DocId -> DocId -> Bool
DocId -> DocId -> Ordering
DocId -> DocId -> DocId
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: DocId -> DocId -> DocId
$cmin :: DocId -> DocId -> DocId
max :: DocId -> DocId -> DocId
$cmax :: DocId -> DocId -> DocId
>= :: DocId -> DocId -> Bool
$c>= :: DocId -> DocId -> Bool
> :: DocId -> DocId -> Bool
$c> :: DocId -> DocId -> Bool
<= :: DocId -> DocId -> Bool
$c<= :: DocId -> DocId -> Bool
< :: DocId -> DocId -> Bool
$c< :: DocId -> DocId -> Bool
compare :: DocId -> DocId -> Ordering
$ccompare :: DocId -> DocId -> Ordering
Ord, Int -> DocId -> ShowS
[DocId] -> ShowS
DocId -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DocId] -> ShowS
$cshowList :: [DocId] -> ShowS
show :: DocId -> String
$cshow :: DocId -> String
showsPrec :: Int -> DocId -> ShowS
$cshowsPrec :: Int -> DocId -> ShowS
Show, Int -> DocId
DocId -> Int
DocId -> [DocId]
DocId -> DocId
DocId -> DocId -> [DocId]
DocId -> DocId -> DocId -> [DocId]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: DocId -> DocId -> DocId -> [DocId]
$cenumFromThenTo :: DocId -> DocId -> DocId -> [DocId]
enumFromTo :: DocId -> DocId -> [DocId]
$cenumFromTo :: DocId -> DocId -> [DocId]
enumFromThen :: DocId -> DocId -> [DocId]
$cenumFromThen :: DocId -> DocId -> [DocId]
enumFrom :: DocId -> [DocId]
$cenumFrom :: DocId -> [DocId]
fromEnum :: DocId -> Int
$cfromEnum :: DocId -> Int
toEnum :: Int -> DocId
$ctoEnum :: Int -> DocId
pred :: DocId -> DocId
$cpred :: DocId -> DocId
succ :: DocId -> DocId
$csucc :: DocId -> DocId
Enum, DocId
forall a. a -> a -> Bounded a
maxBound :: DocId
$cmaxBound :: DocId
minBound :: DocId
$cminBound :: DocId
Bounded)

newtype DocIdSet = DocIdSet (Vec.Vector DocId)
  deriving (DocIdSet -> DocIdSet -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DocIdSet -> DocIdSet -> Bool
$c/= :: DocIdSet -> DocIdSet -> Bool
== :: DocIdSet -> DocIdSet -> Bool
$c== :: DocIdSet -> DocIdSet -> Bool
Eq, Int -> DocIdSet -> ShowS
[DocIdSet] -> ShowS
DocIdSet -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DocIdSet] -> ShowS
$cshowList :: [DocIdSet] -> ShowS
show :: DocIdSet -> String
$cshow :: DocIdSet -> String
showsPrec :: Int -> DocIdSet -> ShowS
$cshowsPrec :: Int -> DocIdSet -> ShowS
Show)

-- represented as a sorted sequence of ids
invariant :: DocIdSet -> Bool
invariant :: DocIdSet -> Bool
invariant (DocIdSet Vector DocId
vec) =
    forall {a}. Ord a => [a] -> Bool
strictlyAscending (forall a. Unbox a => Vector a -> [a]
Vec.toList Vector DocId
vec)
  where
    strictlyAscending :: [a] -> Bool
strictlyAscending (a
a:xs :: [a]
xs@(a
b:[a]
_)) = a
a forall a. Ord a => a -> a -> Bool
< a
b Bool -> Bool -> Bool
&& [a] -> Bool
strictlyAscending [a]
xs
    strictlyAscending [a]
_  = Bool
True


size :: DocIdSet -> Int
size :: DocIdSet -> Int
size (DocIdSet Vector DocId
vec) = forall a. Unbox a => Vector a -> Int
Vec.length Vector DocId
vec

null :: DocIdSet -> Bool
null :: DocIdSet -> Bool
null (DocIdSet Vector DocId
vec) = forall a. Unbox a => Vector a -> Bool
Vec.null Vector DocId
vec

empty :: DocIdSet
empty :: DocIdSet
empty = Vector DocId -> DocIdSet
DocIdSet forall a. Unbox a => Vector a
Vec.empty

singleton :: DocId -> DocIdSet
singleton :: DocId -> DocIdSet
singleton = Vector DocId -> DocIdSet
DocIdSet forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Unbox a => a -> Vector a
Vec.singleton

fromList :: [DocId] -> DocIdSet
fromList :: [DocId] -> DocIdSet
fromList = Vector DocId -> DocIdSet
DocIdSet forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Unbox a => [a] -> Vector a
Vec.fromList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Set a -> [a]
Set.toAscList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Ord a => [a] -> Set a
Set.fromList

toList ::  DocIdSet -> [DocId]
toList :: DocIdSet -> [DocId]
toList (DocIdSet Vector DocId
vec) = forall a. Unbox a => Vector a -> [a]
Vec.toList Vector DocId
vec

insert :: DocId -> DocIdSet -> DocIdSet
insert :: DocId -> DocIdSet -> DocIdSet
insert DocId
x (DocIdSet Vector DocId
vec) =
    case Vector DocId -> Int -> Int -> DocId -> (Int, Bool)
binarySearch Vector DocId
vec Int
0 (forall a. Unbox a => Vector a -> Int
Vec.length Vector DocId
vec forall a. Num a => a -> a -> a
- Int
1) DocId
x of
      (Int
_, Bool
True)  -> Vector DocId -> DocIdSet
DocIdSet Vector DocId
vec
      (Int
i, Bool
False) -> case forall a. Unbox a => Int -> Vector a -> (Vector a, Vector a)
Vec.splitAt Int
i Vector DocId
vec of
                      (Vector DocId
before, Vector DocId
after) ->
                        Vector DocId -> DocIdSet
DocIdSet (forall a. Unbox a => [Vector a] -> Vector a
Vec.concat [Vector DocId
before, forall a. Unbox a => a -> Vector a
Vec.singleton DocId
x, Vector DocId
after])

delete :: DocId -> DocIdSet -> DocIdSet
delete :: DocId -> DocIdSet -> DocIdSet
delete DocId
x (DocIdSet Vector DocId
vec) =
    case Vector DocId -> Int -> Int -> DocId -> (Int, Bool)
binarySearch Vector DocId
vec Int
0 (forall a. Unbox a => Vector a -> Int
Vec.length Vector DocId
vec forall a. Num a => a -> a -> a
- Int
1) DocId
x of
      (Int
_, Bool
False) -> Vector DocId -> DocIdSet
DocIdSet Vector DocId
vec
      (Int
i, Bool
True)  -> case forall a. Unbox a => Int -> Vector a -> (Vector a, Vector a)
Vec.splitAt Int
i Vector DocId
vec of
                      (Vector DocId
before, Vector DocId
after) ->
                        Vector DocId -> DocIdSet
DocIdSet (Vector DocId
before forall a. Unbox a => Vector a -> Vector a -> Vector a
Vec.++ forall a. Unbox a => Vector a -> Vector a
Vec.tail Vector DocId
after)

member :: DocId -> DocIdSet -> Bool
member :: DocId -> DocIdSet -> Bool
member DocId
x (DocIdSet Vector DocId
vec) = forall a b. (a, b) -> b
snd (Vector DocId -> Int -> Int -> DocId -> (Int, Bool)
binarySearch Vector DocId
vec Int
0 (forall a. Unbox a => Vector a -> Int
Vec.length Vector DocId
vec forall a. Num a => a -> a -> a
- Int
1) DocId
x)

binarySearch :: Vec.Vector DocId -> Int -> Int -> DocId -> (Int, Bool)
binarySearch :: Vector DocId -> Int -> Int -> DocId -> (Int, Bool)
binarySearch Vector DocId
vec !Int
a !Int
b !DocId
key
  | Int
a forall a. Ord a => a -> a -> Bool
> Int
b     = (Int
a, Bool
False)
  | Bool
otherwise =
    let mid :: Int
mid = (Int
a forall a. Num a => a -> a -> a
+ Int
b) forall a. Integral a => a -> a -> a
`div` Int
2
     in case forall a. Ord a => a -> a -> Ordering
compare DocId
key (Vector DocId
vec forall a. Unbox a => Vector a -> Int -> a
Vec.! Int
mid) of
          Ordering
LT -> Vector DocId -> Int -> Int -> DocId -> (Int, Bool)
binarySearch Vector DocId
vec Int
a (Int
midforall a. Num a => a -> a -> a
-Int
1) DocId
key
          Ordering
EQ -> (Int
mid, Bool
True)
          Ordering
GT -> Vector DocId -> Int -> Int -> DocId -> (Int, Bool)
binarySearch Vector DocId
vec (Int
midforall a. Num a => a -> a -> a
+Int
1) Int
b DocId
key

unions :: [DocIdSet] -> DocIdSet
unions :: [DocIdSet] -> DocIdSet
unions = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' DocIdSet -> DocIdSet -> DocIdSet
union DocIdSet
empty
         -- a bit more effecient if we merge small ones first
       forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. (a -> a -> Ordering) -> [a] -> [a]
sortBy (forall a. Ord a => a -> a -> Ordering
compare forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` DocIdSet -> Int
size)

union :: DocIdSet -> DocIdSet -> DocIdSet
union :: DocIdSet -> DocIdSet -> DocIdSet
union DocIdSet
x DocIdSet
y | DocIdSet -> Bool
null DocIdSet
x = DocIdSet
y
          | DocIdSet -> Bool
null DocIdSet
y = DocIdSet
x
union (DocIdSet Vector DocId
xs) (DocIdSet Vector DocId
ys) =
    Vector DocId -> DocIdSet
DocIdSet (forall a. Unbox a => (forall s. ST s (MVector s a)) -> Vector a
Vec.create (forall (m :: * -> *) a.
(PrimMonad m, Unbox a) =>
Int -> m (MVector (PrimState m) a)
MVec.new Int
sizeBound forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall s.
Vector DocId
-> Vector DocId -> MVector s DocId -> ST s (MVector s DocId)
writeMergedUnion Vector DocId
xs Vector DocId
ys))
  where
    sizeBound :: Int
sizeBound = forall a. Unbox a => Vector a -> Int
Vec.length Vector DocId
xs forall a. Num a => a -> a -> a
+ forall a. Unbox a => Vector a -> Int
Vec.length Vector DocId
ys

writeMergedUnion :: Vec.Vector DocId -> Vec.Vector DocId ->
                    MVec.MVector s DocId -> ST s (MVec.MVector s DocId)
writeMergedUnion :: forall s.
Vector DocId
-> Vector DocId -> MVector s DocId -> ST s (MVector s DocId)
writeMergedUnion Vector DocId
xs0 Vector DocId
ys0 !MVector s DocId
out = do
    Int
i <- Vector DocId -> Vector DocId -> Int -> ST s Int
go Vector DocId
xs0 Vector DocId
ys0 Int
0
    forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$! forall a s. Unbox a => Int -> MVector s a -> MVector s a
MVec.take Int
i MVector s DocId
out
  where
    go :: Vector DocId -> Vector DocId -> Int -> ST s Int
go !Vector DocId
xs !Vector DocId
ys !Int
i
      | forall a. Unbox a => Vector a -> Bool
Vec.null Vector DocId
xs = do forall a (m :: * -> *).
(Unbox a, PrimMonad m) =>
MVector (PrimState m) a -> Vector a -> m ()
Vec.copy (forall a s. Unbox a => Int -> Int -> MVector s a -> MVector s a
MVec.slice Int
i (forall a. Unbox a => Vector a -> Int
Vec.length Vector DocId
ys) MVector s DocId
out) Vector DocId
ys
                         forall (m :: * -> *) a. Monad m => a -> m a
return (Int
i forall a. Num a => a -> a -> a
+ forall a. Unbox a => Vector a -> Int
Vec.length Vector DocId
ys)
      | forall a. Unbox a => Vector a -> Bool
Vec.null Vector DocId
ys = do forall a (m :: * -> *).
(Unbox a, PrimMonad m) =>
MVector (PrimState m) a -> Vector a -> m ()
Vec.copy (forall a s. Unbox a => Int -> Int -> MVector s a -> MVector s a
MVec.slice Int
i (forall a. Unbox a => Vector a -> Int
Vec.length Vector DocId
xs) MVector s DocId
out) Vector DocId
xs
                         forall (m :: * -> *) a. Monad m => a -> m a
return (Int
i forall a. Num a => a -> a -> a
+ forall a. Unbox a => Vector a -> Int
Vec.length Vector DocId
xs)
      | Bool
otherwise   = let x :: DocId
x = forall a. Unbox a => Vector a -> a
Vec.head Vector DocId
xs; y :: DocId
y = forall a. Unbox a => Vector a -> a
Vec.head Vector DocId
ys
                      in case forall a. Ord a => a -> a -> Ordering
compare DocId
x DocId
y of
                          Ordering
GT -> do forall (m :: * -> *) a.
(PrimMonad m, Unbox a) =>
MVector (PrimState m) a -> Int -> a -> m ()
MVec.write MVector s DocId
out Int
i DocId
y
                                   Vector DocId -> Vector DocId -> Int -> ST s Int
go           Vector DocId
xs  (forall a. Unbox a => Vector a -> Vector a
Vec.tail Vector DocId
ys) (Int
iforall a. Num a => a -> a -> a
+Int
1)
                          Ordering
EQ -> do forall (m :: * -> *) a.
(PrimMonad m, Unbox a) =>
MVector (PrimState m) a -> Int -> a -> m ()
MVec.write MVector s DocId
out Int
i DocId
x
                                   Vector DocId -> Vector DocId -> Int -> ST s Int
go (forall a. Unbox a => Vector a -> Vector a
Vec.tail Vector DocId
xs) (forall a. Unbox a => Vector a -> Vector a
Vec.tail Vector DocId
ys) (Int
iforall a. Num a => a -> a -> a
+Int
1)
                          Ordering
LT -> do forall (m :: * -> *) a.
(PrimMonad m, Unbox a) =>
MVector (PrimState m) a -> Int -> a -> m ()
MVec.write MVector s DocId
out Int
i DocId
x
                                   Vector DocId -> Vector DocId -> Int -> ST s Int
go (forall a. Unbox a => Vector a -> Vector a
Vec.tail Vector DocId
xs)           Vector DocId
ys  (Int
iforall a. Num a => a -> a -> a
+Int
1)

intersection :: DocIdSet -> DocIdSet -> DocIdSet
intersection :: DocIdSet -> DocIdSet -> DocIdSet
intersection DocIdSet
x DocIdSet
y | DocIdSet -> Bool
null DocIdSet
x = DocIdSet
empty
                 | DocIdSet -> Bool
null DocIdSet
y = DocIdSet
empty
intersection (DocIdSet Vector DocId
xs) (DocIdSet Vector DocId
ys) =
    Vector DocId -> DocIdSet
DocIdSet (forall a. Unbox a => (forall s. ST s (MVector s a)) -> Vector a
Vec.create (forall (m :: * -> *) a.
(PrimMonad m, Unbox a) =>
Int -> m (MVector (PrimState m) a)
MVec.new Int
sizeBound forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall s.
Vector DocId
-> Vector DocId -> MVector s DocId -> ST s (MVector s DocId)
writeMergedIntersection Vector DocId
xs Vector DocId
ys))
  where
    sizeBound :: Int
sizeBound = forall a. Ord a => a -> a -> a
max (forall a. Unbox a => Vector a -> Int
Vec.length Vector DocId
xs) (forall a. Unbox a => Vector a -> Int
Vec.length Vector DocId
ys)

writeMergedIntersection :: Vec.Vector DocId -> Vec.Vector DocId ->
                           MVec.MVector s DocId -> ST s (MVec.MVector s DocId)
writeMergedIntersection :: forall s.
Vector DocId
-> Vector DocId -> MVector s DocId -> ST s (MVector s DocId)
writeMergedIntersection Vector DocId
xs0 Vector DocId
ys0 !MVector s DocId
out = do
    Int
i <- Vector DocId -> Vector DocId -> Int -> ST s Int
go Vector DocId
xs0 Vector DocId
ys0 Int
0
    forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$! forall a s. Unbox a => Int -> MVector s a -> MVector s a
MVec.take Int
i MVector s DocId
out
  where
    go :: Vector DocId -> Vector DocId -> Int -> ST s Int
go !Vector DocId
xs !Vector DocId
ys !Int
i
      | forall a. Unbox a => Vector a -> Bool
Vec.null Vector DocId
xs = forall (m :: * -> *) a. Monad m => a -> m a
return Int
i
      | forall a. Unbox a => Vector a -> Bool
Vec.null Vector DocId
ys = forall (m :: * -> *) a. Monad m => a -> m a
return Int
i
      | Bool
otherwise   = let x :: DocId
x = forall a. Unbox a => Vector a -> a
Vec.head Vector DocId
xs; y :: DocId
y = forall a. Unbox a => Vector a -> a
Vec.head Vector DocId
ys
                      in case forall a. Ord a => a -> a -> Ordering
compare DocId
x DocId
y of
                          Ordering
GT ->    Vector DocId -> Vector DocId -> Int -> ST s Int
go           Vector DocId
xs  (forall a. Unbox a => Vector a -> Vector a
Vec.tail Vector DocId
ys)  Int
i
                          Ordering
EQ -> do forall (m :: * -> *) a.
(PrimMonad m, Unbox a) =>
MVector (PrimState m) a -> Int -> a -> m ()
MVec.write MVector s DocId
out Int
i DocId
x
                                   Vector DocId -> Vector DocId -> Int -> ST s Int
go (forall a. Unbox a => Vector a -> Vector a
Vec.tail Vector DocId
xs) (forall a. Unbox a => Vector a -> Vector a
Vec.tail Vector DocId
ys) (Int
iforall a. Num a => a -> a -> a
+Int
1)
                          Ordering
LT ->    Vector DocId -> Vector DocId -> Int -> ST s Int
go (forall a. Unbox a => Vector a -> Vector a
Vec.tail Vector DocId
xs)           Vector DocId
ys   Int
i

------------------------------------------------------------------------------
-- verbose Unbox instances
--

instance MVec.Unbox DocId

newtype instance MVec.MVector s DocId = MV_DocId (MVec.MVector s Word32)

instance GMVec.MVector MVec.MVector DocId where
    basicLength :: forall s. MVector s DocId -> Int
basicLength          (MV_DocId MVector s Word32
v) = forall (v :: * -> * -> *) a s. MVector v a => v s a -> Int
GMVec.basicLength MVector s Word32
v
    basicUnsafeSlice :: forall s. Int -> Int -> MVector s DocId -> MVector s DocId
basicUnsafeSlice Int
i Int
l (MV_DocId MVector s Word32
v) = forall s. MVector s Word32 -> MVector s DocId
MV_DocId (forall (v :: * -> * -> *) a s.
MVector v a =>
Int -> Int -> v s a -> v s a
GMVec.basicUnsafeSlice Int
i Int
l MVector s Word32
v)
    basicUnsafeNew :: forall s. Int -> ST s (MVector s DocId)
basicUnsafeNew     Int
l              = forall s. MVector s Word32 -> MVector s DocId
MV_DocId forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM` forall (v :: * -> * -> *) a s. MVector v a => Int -> ST s (v s a)
GMVec.basicUnsafeNew Int
l
    basicInitialize :: forall s. MVector s DocId -> ST s ()
basicInitialize      (MV_DocId MVector s Word32
v) = forall (v :: * -> * -> *) a s. MVector v a => v s a -> ST s ()
GMVec.basicInitialize MVector s Word32
v
    basicUnsafeReplicate :: forall s. Int -> DocId -> ST s (MVector s DocId)
basicUnsafeReplicate Int
l DocId
x          = forall s. MVector s Word32 -> MVector s DocId
MV_DocId forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM` forall (v :: * -> * -> *) a s.
MVector v a =>
Int -> a -> ST s (v s a)
GMVec.basicUnsafeReplicate Int
l (DocId -> Word32
unDocId DocId
x)
    basicUnsafeRead :: forall s. MVector s DocId -> Int -> ST s DocId
basicUnsafeRead  (MV_DocId MVector s Word32
v) Int
i   = Word32 -> DocId
DocId forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM`    forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> Int -> ST s a
GMVec.basicUnsafeRead MVector s Word32
v Int
i
    basicUnsafeWrite :: forall s. MVector s DocId -> Int -> DocId -> ST s ()
basicUnsafeWrite (MV_DocId MVector s Word32
v) Int
i DocId
x = forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> Int -> a -> ST s ()
GMVec.basicUnsafeWrite MVector s Word32
v Int
i (DocId -> Word32
unDocId DocId
x)
    basicClear :: forall s. MVector s DocId -> ST s ()
basicClear       (MV_DocId MVector s Word32
v)     = forall (v :: * -> * -> *) a s. MVector v a => v s a -> ST s ()
GMVec.basicClear MVector s Word32
v
    basicSet :: forall s. MVector s DocId -> DocId -> ST s ()
basicSet         (MV_DocId MVector s Word32
v) DocId
x   = forall (v :: * -> * -> *) a s. MVector v a => v s a -> a -> ST s ()
GMVec.basicSet MVector s Word32
v (DocId -> Word32
unDocId DocId
x)
    basicUnsafeGrow :: forall s. MVector s DocId -> Int -> ST s (MVector s DocId)
basicUnsafeGrow  (MV_DocId MVector s Word32
v) Int
l   = forall s. MVector s Word32 -> MVector s DocId
MV_DocId forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM` forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> Int -> ST s (v s a)
GMVec.basicUnsafeGrow MVector s Word32
v Int
l
    basicUnsafeCopy :: forall s. MVector s DocId -> MVector s DocId -> ST s ()
basicUnsafeCopy  (MV_DocId MVector s Word32
v) (MV_DocId MVector s Word32
v') = forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> v s a -> ST s ()
GMVec.basicUnsafeCopy MVector s Word32
v MVector s Word32
v'
    basicUnsafeMove :: forall s. MVector s DocId -> MVector s DocId -> ST s ()
basicUnsafeMove  (MV_DocId MVector s Word32
v) (MV_DocId MVector s Word32
v') = forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> v s a -> ST s ()
GMVec.basicUnsafeMove MVector s Word32
v MVector s Word32
v'
    basicOverlaps :: forall s. MVector s DocId -> MVector s DocId -> Bool
basicOverlaps    (MV_DocId MVector s Word32
v) (MV_DocId MVector s Word32
v') = forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> v s a -> Bool
GMVec.basicOverlaps   MVector s Word32
v MVector s Word32
v'
    {-# INLINE basicLength #-}
    {-# INLINE basicUnsafeSlice #-}
    {-# INLINE basicOverlaps #-}
    {-# INLINE basicUnsafeNew #-}
    {-# INLINE basicInitialize #-}
    {-# INLINE basicUnsafeReplicate #-}
    {-# INLINE basicUnsafeRead #-}
    {-# INLINE basicUnsafeWrite #-}
    {-# INLINE basicClear #-}
    {-# INLINE basicSet #-}
    {-# INLINE basicUnsafeCopy #-}
    {-# INLINE basicUnsafeMove #-}
    {-# INLINE basicUnsafeGrow #-}

newtype instance Vec.Vector DocId = V_DocId (Vec.Vector Word32)

instance GVec.Vector Vec.Vector DocId where
    basicUnsafeFreeze :: forall s. Mutable Vector s DocId -> ST s (Vector DocId)
basicUnsafeFreeze (MV_DocId MVector s Word32
mv)  = Vector Word32 -> Vector DocId
V_DocId  forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM` forall (v :: * -> *) a s. Vector v a => Mutable v s a -> ST s (v a)
GVec.basicUnsafeFreeze MVector s Word32
mv
    basicUnsafeThaw :: forall s. Vector DocId -> ST s (Mutable Vector s DocId)
basicUnsafeThaw   (V_DocId  Vector Word32
v)   = forall s. MVector s Word32 -> MVector s DocId
MV_DocId forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM` forall (v :: * -> *) a s. Vector v a => v a -> ST s (Mutable v s a)
GVec.basicUnsafeThaw Vector Word32
v
    basicLength :: Vector DocId -> Int
basicLength       (V_DocId  Vector Word32
v)   = forall (v :: * -> *) a. Vector v a => v a -> Int
GVec.basicLength Vector Word32
v
    basicUnsafeSlice :: Int -> Int -> Vector DocId -> Vector DocId
basicUnsafeSlice Int
i Int
l (V_DocId Vector Word32
v) = Vector Word32 -> Vector DocId
V_DocId (forall (v :: * -> *) a. Vector v a => Int -> Int -> v a -> v a
GVec.basicUnsafeSlice Int
i Int
l Vector Word32
v)
    basicUnsafeIndexM :: Vector DocId -> Int -> Box DocId
basicUnsafeIndexM (V_DocId  Vector Word32
v) Int
i = Word32 -> DocId
DocId forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM` forall (v :: * -> *) a. Vector v a => v a -> Int -> Box a
GVec.basicUnsafeIndexM Vector Word32
v Int
i
    basicUnsafeCopy :: forall s. Mutable Vector s DocId -> Vector DocId -> ST s ()
basicUnsafeCopy   (MV_DocId MVector s Word32
mv)
                      (V_DocId  Vector Word32
v)   = forall (v :: * -> *) a s.
Vector v a =>
Mutable v s a -> v a -> ST s ()
GVec.basicUnsafeCopy MVector s Word32
mv Vector Word32
v
    elemseq :: forall b. Vector DocId -> DocId -> b -> b
elemseq           (V_DocId  Vector Word32
v) DocId
x = forall (v :: * -> *) a b. Vector v a => v a -> a -> b -> b
GVec.elemseq Vector Word32
v (DocId -> Word32
unDocId DocId
x)
    {-# INLINE basicUnsafeFreeze #-}
    {-# INLINE basicUnsafeThaw #-}
    {-# INLINE basicLength #-}
    {-# INLINE basicUnsafeSlice #-}
    {-# INLINE basicUnsafeIndexM #-}
    {-# INLINE basicUnsafeCopy #-}
    {-# INLINE elemseq #-}