Skip to content

Commit 10a5707

Browse files
committed
Force BCF header dicts to be larger than needed.
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.
1 parent d7e7f2c commit 10a5707

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

vcf.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1370,8 +1370,11 @@ bcf_hdr_t *bcf_hdr_init(const char *mode)
13701370
bcf_hdr_t *h;
13711371
h = (bcf_hdr_t*)calloc(1, sizeof(bcf_hdr_t));
13721372
if (!h) return NULL;
1373-
for (i = 0; i < 3; ++i)
1373+
for (i = 0; i < 3; ++i) {
13741374
if ((h->dict[i] = kh_init(vdict)) == NULL) goto fail;
1375+
// Supersize the hash to make collisions very unlikely
1376+
if (kh_resize(vdict, h->dict[i], 32768) < 0) goto fail;
1377+
}
13751378

13761379
bcf_hdr_aux_t *aux = (bcf_hdr_aux_t*)calloc(1,sizeof(bcf_hdr_aux_t));
13771380
if ( !aux ) goto fail;

0 commit comments

Comments
 (0)