3 ms·
How do you build the hash table at the first place? "We look up the key in the hash table and get a value (referred to as v2)." Do you know Haskell a bit? Try
by babo 17y ago
How do you build the hash table at the first place? "We look up the key in the hash table and get a value (referred to as v2)."
Do you know Haskell a bit? Try to write your examples in real Haskell, a friendly type system helps a lot to clean up your pseudo-code.
- sgk284 17y agoThink of the hashtable as a defaultdict or the fold as having an initial value for when the key doesn't have a value yet.
- babo 17y agoSure, but what value is it?
- sgk284 17y agoAh, that would be specific to the job. If your doing a sum, maybe 0, or if you're building a list, it'd be an empty list. I suspect that a good default would just be whatever the first value generated by the mapper is, in which case the first value of any key wouldn't be folded, but rather just set in the hash table. But that is all job specific. If you can recommend a better solution, I'm all ears. Furthermore, I should have explained the types better. As described, the HashFold framework would require the output of the map, the arguments of the fold, and the output of the fold all be the same type. This isn't as limiting as it sounds and if it turns out to be limiting for some problem domains, there are solutions to each of those.
- babo 17y agoThanks, that makes sense.