# Hash table in standard lib

**URL:** <https://swi-prolog.discourse.group/t/hash-table-in-standard-lib/2641>\
**Category:** Request For Comments\
**Created:** [July 16, 2020, 1:45pm UTC](https://swi-prolog.discourse.group/t/hash-table-in-standard-lib/2641 "2020-07-16T13:45:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [July 16, 2020, 1:45pm UTC](https://swi-prolog.discourse.group/t/hash-table-in-standard-lib/2641/1 "2020-07-16T13:45:55Z")

</div>

I have pushed [library(hashtable)](https://github.com/SWI-Prolog/swipl-devel/blob/7e19090fd5de60a79832c7add8d3d0f0e49f8d8c/library/hashtable.pl) as a proposed new library. It implements hash tables as a mutable and backtrackable data structure. Not very Prolog-like of course, but relational style updates do not work for hash tables and (binary) trees are the way to go for relational key-value pair dictionaries with O log(N). Hash tables are often faster though and us less memory. The code is also sufficiently simple to be eventually moved to the C core.

CHR provided chr\_hashtable\_store.pl, but the interface is quite tightly connected to what CHR needs.

I’ve implemented this as a _closed hashtable_, which seems to perform about equal to the open hash tables of CHR, but uses considerably less memory.

Is there an established API for this in the Prolog world? In that case I’m happy to sync.
