https://github.com/dnmfarrell/dict
A pure ISO Prolog dictionary
https://github.com/dnmfarrell/dict
Last synced: 3 months ago
JSON representation
A pure ISO Prolog dictionary
- Host: GitHub
- URL: https://github.com/dnmfarrell/dict
- Owner: dnmfarrell
- License: mit
- Created: 2024-10-23T20:42:41.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-10-23T21:47:14.000Z (over 1 year ago)
- Last Synced: 2024-10-24T10:23:58.820Z (over 1 year ago)
- Language: Prolog
- Size: 2.93 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# dict
An ISO Prolog dictionary, implemented as an incomplete binary search tree.
Inspired by Chapter 15.3 from [The Art of Prolog](https://mitpress.mit.edu/9780262691635/the-art-of-prolog/) by Sterling and Shapiro.
Tested with [Scryer Prolog](https://scryer.pl).
## Exports
* `add(+Key, ?Dict, ?Value)` - adds a key-value pair to the dictionary, if it doesn't already exist.
* `balance(+Dict, -Dict)` - balances a dictionary.
* `get(+Key, +Dict, -Value)` - gets the value associated with the key. Fails if key does not exist.
* `height(+Key, -Height)` - calculates and returns the height of the dictionary's tree.
* `put(+Key, ?Dict, -Dict1, +Value)` - adds/updates the value of a key, returning a new dictionary.
* `to_list(+Dict, -List)` - serializes a dictionary to a list of key-value pairs.
## Testing
$ scryer-prolog -f test/dict.pl
Running test "add/get"
Running test "put"
Running test "to_list"
Running test "height/balance"
## See Also
Many prologs ship with a balanced tree dictionary implementation called [assoc](https://www.scryer.pl/assoc).