klapaucius / vector-hashtables

Other
32 stars 5 forks source link

API to work with naked Dictionary_ #25

Open Bodigrim opened 3 months ago

Bodigrim commented 3 months ago

For tight inner loops a double indirection of Dictionary (pointer to MutVar# + pointer to Dictionary_) might have a significant performance cost. I'd like to have something like

insert_ :: (MVector ks k, MVector vs v, PrimMonad m, Hashable k, Eq k)
        => Dictionary_ (PrimState m) ks k vs v -> k -> v -> m Bool

If Dictionary_ is sufficient to insert without resize, return True. Otherwise return False, so that a user can wrap their Dictionary_ into DRef and MutVar, pass to a usual insert, which will perform all necessary rituals to grow sizes, and extract naked Dictionary_ back.

(A specialized API to resize Dictionary_ explicitly would be even better, but that's a bonus).

klapaucius commented 3 months ago

Sure, it can be done. We should probably try to replace the record with a mutable array like in the `structs' package.