3 ms·
How does this compare to using ArrayBuffer/DataView, which seems like the more obvious choice for this sort of thing? This wouldn't require any bitwise operati
by sltkr 1y ago
How does this compare to using ArrayBuffer/DataView, which seems like the more obvious choice for this sort of thing?
This wouldn't require any bitwise operations to store/retrieve fields, assuming they are all byte-aligned.
- recursive 1y agoThey are more obvious, but it wouldn't work in Set or as Map keys, which seems to be a design goal here.
- sltkr 1y agoAccording to the author that wasn't a design goal: > While looking all this up, I found Justin Fagnani’s article Composite Map Keys in JavaScript with Bitsets, which is mostly unrelated to what I’m doing here In fact, the author specifically wants his records to be mutable, which precludes using them as Set or Map keys (at least at the same time). So immutable bigints seem like sort of the wrong tool for the job: changing any single field requires creating a completely new number (and while in theory a compiler might be able to optimize away the copy, in practice I doubt this happens).
- recursive 1y agoOh yeah. Huh. I guess I read that wrong.
- dullcrisp 1y agoMaybe just implement a hash function and some buckets and return an interned object? You could implement something with the same functionality but have a lot more flexibility if you’re not relying on cramming things into a bigint.
- vanderZwan 1y agoI suspect the "find all keys with identical values" example would be fastest if they'd use a struct-of-arrays approach where each key gets its own typed array and objects are identified by a unique index. Just iterate over each array and as soon as a value isn't eqoal to the next then that key is thrown out.