This commit is contained in:
voidlizard 2025-07-30 20:03:55 +03:00
parent a5d9f4193b
commit 8d7728ad71
2 changed files with 10 additions and 11 deletions

View File

@ -25,7 +25,7 @@ unpackIndexEntry entryBs = do
let (fks,rest1) = BS.splitAt 4 entryBs
let (offs,rest2) = BS.splitAt 8 rest1
let ss = BS.take 4 rest2
let fk = FileKey (N.word32 fks)
let fk = FileKey (N.word64 fks)
let off = N.word64 offs
let size = N.word32 ss
IndexEntry fk off size
@ -34,11 +34,9 @@ unpackIndexEntry entryBs = do
emptyKey :: ByteString
emptyKey = BS.replicate 32 0
-- FIXME: better-hashtable-params
ncqIndexAlloc :: NWayHashAlloc
ncqIndexAlloc = nwayAllocDef 1.10 32 8 16
ncqIndexAllocForMerge :: NWayHashAlloc
ncqIndexAllocForMerge = nwayAllocDef 0.8 32 8 16
ncqIndexAlloc = nwayAllocDef 1.15 32 8 32
ncqLookupIndex :: MonadUnliftIO m
=> HashRef
@ -80,10 +78,11 @@ ncqIndexFile n fk = runMaybeT do
_ -> do
-- we need size in order to return block size faster
-- w/o search in fossil
let fks = N.bytestring32 (coerce fk)
let fks = N.bytestring64 (coerce fk)
let rs = (w + ncqSLen) & fromIntegral @_ @Word32 & N.bytestring32
let os = fromIntegral @_ @Word64 offset & N.bytestring64
let record = fks <> os <> rs
let padding = BS.replicate 12 0
let record = fks <> os <> rs <> padding
-- debug $ "WRITE INDEX ENTRY" <+> pretty (BS.length record)
S.yield (coerce key, record)

View File

@ -22,7 +22,7 @@ type Shard = TVar (HashMap HashRef NCQEntry)
type StateVersion = Word64
newtype FileKey = FileKey Word32
newtype FileKey = FileKey Word64
deriving newtype (Eq,Ord,Show,Num,Enum,Real,Integral,Pretty,Hashable)
deriving stock (Data,Generic)
@ -119,10 +119,10 @@ instance ToFileName (DataFile FileKey) where
toFileName (DataFile fk) = ncqMakeFossilName fk
instance ToFileName (IndexFile FileKey) where
toFileName (IndexFile fk) = printf "i-%08x.cq" (coerce @_ @Word32 fk)
toFileName (IndexFile fk) = printf "i-%016x.cq" (coerce @_ @Word64 fk)
instance ToFileName (StateFile FileKey) where
toFileName (StateFile fk) = printf "s-%08x" (coerce @_ @Word32 fk)
toFileName (StateFile fk) = printf "s-%016x" (coerce @_ @Word64 fk)
instance Monoid NCQState where
@ -144,7 +144,7 @@ instance Pretty Location where
InMemory _ -> "in-memory"
ncqMakeFossilName :: FileKey -> FilePath
ncqMakeFossilName = printf "f-%08x.data" . coerce @_ @Word32
ncqMakeFossilName = printf "f-%016x.data" . coerce @_ @Word64
withSem :: forall a m . MonadUnliftIO m => TSem -> m a -> m a
withSem sem action =