Difference between revisions of "Chained Dictionary Assignment"

From CSE425S Wiki
Jump to navigation Jump to search
Line 1: Line 1:
In this and the follow up studio, you will build three implementations of a dictionary.  Each will be a persistent, mutable data structure, so you can expect to use the [http://sml-family.org/Basis/general.html#SIG:GENERAL.!:VAL ref] feature of SML, either directly or via the mutable [http://sml-family.org/Basis/array.html Array structure].
+
In this and the follow up [[Sorted_Dictionary_Assignment|Sorted Dictionary]] studio, you will build three implementations of a dictionary.  Each will be a persistent, mutable data structure, so you can expect to use the [http://sml-family.org/Basis/general.html#SIG:GENERAL.!:VAL ref] feature of SML, either directly or via the mutable [http://sml-family.org/Basis/array.html Array structure].
  
 
  <nowiki>signature DICTIONARY = sig
 
  <nowiki>signature DICTIONARY = sig

Revision as of 19:06, 2 March 2020

In this and the follow up Sorted Dictionary studio, you will build three implementations of a dictionary. Each will be a persistent, mutable data structure, so you can expect to use the ref feature of SML, either directly or via the mutable Array structure.

signature DICTIONARY = sig
    type (''k,'v) dictionary
    val get : ((''k,'v) dictionary *''k) -> 'v option
    val put : ((''k,'v) dictionary *''k *'v) -> 'v option
    val remove : ((''k,'v) dictionary *''k) -> 'v option
    val entries : (''k,'v) dictionary -> (''k*'v) list
    val keys : (''k,'v) dictionary -> ''k list
    val values : (''k,'v) dictionary -> 'v list
end

Background

Refs and Arrays

SingleList Implementation

signature SINGLE_LIST_DICTIONARY = sig include DICTIONARY
    val create_simple : unit -> (''k,'v) dictionary
end

Hashtable Implementation

Hash table

Hash table 5 0 1 1 1 1 1 LL.svg

SML Array Structure

signature HASHED_DICTIONARY = sig include DICTIONARY
    type ''k hash_function = ''k -> int
    val create_hashed : (int * ''k hash_function) -> (''k,'v) dictionary
end