khash associative array / hash map / hash set
James Blachly
james.blachly at gmail.com
Mon Aug 24 01:39:26 UTC 2020
In addition to our interval tree implementation (
https://forum.dlang.org/thread/rhrgbl$2n1h$1@digitalmars.com ), I wanted
to share another tool we have been using extensively here, a D templates
port of attractivechaos' klib (https://github.com/attractivechaos/klib)
component khash.
https://code.dlang.org/packages/dklib
https://github.com/blachlylab/dklib
I namespaced this as `dklib.khash` as ultimately we will place some
other klib components in this package as we use them (kavl for instance
is already used in our intervaltree implementation)
Although it is a relatively faithful straight port of the C code, I
tried to turn attractivechaos' classic C-style generic programming
(#define hell) into templated code which looks a bit awkward in places,
but I think turns out very nicely in practice.
opAssign, opIndex, .require, .byKey() are all implemented for ergonomics.
As always, as computational biologists rather than professional software
engineers, we would be glad to hear feedback and hope others will find
this useful.
OH, I almost forgot the best part. It is crazy fast.
https://attractivechaos.wordpress.com/2018/01/13/revisiting-hash-table-performance/
https://attractivechaos.wordpress.com/2019/12/28/deletion-from-hash-tables-without-tombstones/
My naive benchmark shows -- compared to emsi_containers.HashMap -- 30%
faster inserts, 80% faster serial retrieval and 70% faster random
retrieval. Perhaps I am doing something wrong?
James
More information about the Digitalmars-d-announce
mailing list