Skip to content

Commit

Permalink
Force BCF header dicts to be larger than needed.
Browse files Browse the repository at this point in the history
This is a tactic to reduce hash collisions due to the use of overly
simple hash functions.  It seems to typically be around 3-8% speed gain.
  • Loading branch information
jkbonfield committed Aug 1, 2023
1 parent d7e7f2c commit 10a5707
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion vcf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1370,8 +1370,11 @@ bcf_hdr_t *bcf_hdr_init(const char *mode)
bcf_hdr_t *h;
h = (bcf_hdr_t*)calloc(1, sizeof(bcf_hdr_t));
if (!h) return NULL;
for (i = 0; i < 3; ++i)
for (i = 0; i < 3; ++i) {
if ((h->dict[i] = kh_init(vdict)) == NULL) goto fail;
// Supersize the hash to make collisions very unlikely
if (kh_resize(vdict, h->dict[i], 32768) < 0) goto fail;
}

bcf_hdr_aux_t *aux = (bcf_hdr_aux_t*)calloc(1,sizeof(bcf_hdr_aux_t));
if ( !aux ) goto fail;
Expand Down

0 comments on commit 10a5707

Please sign in to comment.