Comments (6)
I really hope that this is possible, because it is how I would like to use most O(1) lookup functions.
from hashtables.
@gregorycollins what are your thoughts on this? If you think this is OK, I might take a look at actually implementing this.
from hashtables.
My thought is, I don't really know how to do it cleanly so I haven't implemented it yet, and the use case hasn't seemed compelling enough to make the work feel worth it. All of the data types need to be reworked for pure lookup, but you want to use the same lookup algorithms everywhere, so you either have to duplicate everything or use templating/code generation.
One possibility you could consider is just to newtype around hashtables in IO, and use unsafePerformIO
to expose only the non-mutating functions. I'm sure the purists reading this thread are choking on their Yerba Matés by now.
from hashtables.
The use case is to build the hash table kust once in ST and then use it in pure code just for lookups without having to wrap the pure code in a monad.
I actually think of something similar - a newtype wrapper and runST'ing the existing lookup function.
from hashtables.
The use case is to build the hash table kust once in ST and then use it in pure code just for lookups without having to wrap the pure code in a monad.
My point is that you can already do this, with unsafePerformIO
. A newtype wrapper and maybe a build function would help make it safer though:
build
:: HashTable h
=> Maybe Int -- ^ size hint
-> (h s k v -> ST s ())
-> ST s (Pure.HashTable k v)
Pure.HashTable can just be a set of lambdas doing either runST
or unsafePerformIO
:
data HashTable k v = HashTable { _lookup :: k -> Maybe v, ... }
The extra safety comes from swapping out the STRef
inside the HashTable
objects so that the mutable table can no longer be used once the user function is finished. It probably requires a new typeclass method.
from hashtables.
P.S. runST
wants a forall s . ST s a
, which you won't be able to give it -- your hashtable will have a concrete state type s
. So here the only thing that will make it work is s=RealWorld
and using unsafePerformIO
anyways, the build function has to be:
build
:: HashTable h
=> Maybe Int
-> (IOHashTable h k v -> IO ())
-> IO (Pure.HashTable k v)
from hashtables.
Related Issues (20)
- Missing instance Eq (HashTable s k v)
- Compilation failure using GHC 7.8.4 HOT 4
- Hashtables 1.2.2.0 should be marked as depending on base >= 4.7 HOT 2
- Build error with GHC 8.4.1-alpha1 HOT 5
- 1.2.3.0 breaks ghc pre 7.10 HOT 1
- Why is performance a third of hash tables in other languages? HOT 4
- Update benchmarks to criterion 1.5
- Adding Hopscotch Hashing HOT 1
- SSE4_2 Broken For Cuckoo HashTable
- Cuckoo loses data when inserting 65th element via mutate HOT 26
- Build error using primitive 0.7.0.0 HOT 2
- Support for hashable-1.3.0.0 HOT 3
- Poor performance of Basic compared to Cuckoo HOT 3
- undefined, called at src/Data/HashTable/ST/Cuckoo.hs:406:31 HOT 2
- Compile failure with GHC 9.2 HOT 3
- How to control load factor?
- Support for hashable-1.4 HOT 3
- Noncanonical mappend HOT 2
- Performance gap between 1.2.4.2 and 1.3
- How to merge two hashtables? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hashtables.