Skip to content

An ISO Prolog dictionary, implemented as an incomplete binary search tree.

License

Notifications You must be signed in to change notification settings

dnmfarrell/dict

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

dict

An ISO Prolog dictionary, implemented as an incomplete binary search tree.

Inspired by Chapter 15.3 from The Art of Prolog by Sterling and Shapiro.

Tested with Scryer Prolog.

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.

About

An ISO Prolog dictionary, implemented as an incomplete binary search tree.

Topics

Resources

License

Stars

Watchers

Forks

Languages