Difference between revisions of "Chained Dictionary Assignment"
(→Spec) |
|||
Line 16: | Line 16: | ||
=Spec= | =Spec= | ||
==get== | ==get== | ||
− | Behaves much like [https://docs.oracle.com/javase/8/docs/api/java/util/Map.html#get-java.lang.Object- java.util.Map<K,V>'s get method] except instead of returning null or the associated value, it returns an option. | + | Behaves much like [https://docs.oracle.com/javase/8/docs/api/java/util/Map.html#get-java.lang.Object- java.util.Map<K,V>'s get(key) method] except instead of returning null or the associated value, it returns an option. |
==put== | ==put== | ||
+ | Behaves much like [https://docs.oracle.com/javase/8/docs/api/java/util/Map.html#put-K-V- java.util.Map<K,V>'s put(key,value) method] except instead of returning null or the previously associated value, it returns an option. | ||
==remove== | ==remove== | ||
+ | Behaves much like [https://docs.oracle.com/javase/8/docs/api/java/util/Map.html#remove-java.lang.Object- java.util.Map<K,V>'s remove(key) method] except instead of returning null or the previously associated value, it returns an option. | ||
+ | ==entries== | ||
+ | Behaves much like [https://docs.oracle.com/javase/8/docs/api/java/util/Map.html#entrySet-- java.util.Map<K,V>'s entrySet() method]. | ||
+ | ==keys== | ||
+ | Behaves much like [https://docs.oracle.com/javase/8/docs/api/java/util/Map.html#keySet-- java.util.Map<K,V>'s keySet() method]. | ||
+ | ==values== | ||
+ | Behaves much like [https://docs.oracle.com/javase/8/docs/api/java/util/Map.html#values-- java.util.Map<K,V>'s values() method]. | ||
+ | |||
=SingleList Implementation= | =SingleList Implementation= | ||
<nowiki>signature SINGLE_LIST_DICTIONARY = sig include DICTIONARY | <nowiki>signature SINGLE_LIST_DICTIONARY = sig include DICTIONARY |
Revision as of 19:13, 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
Contents
Background
Spec
get
Behaves much like java.util.Map<K,V>'s get(key) method except instead of returning null or the associated value, it returns an option.
put
Behaves much like java.util.Map<K,V>'s put(key,value) method except instead of returning null or the previously associated value, it returns an option.
remove
Behaves much like java.util.Map<K,V>'s remove(key) method except instead of returning null or the previously associated value, it returns an option.
entries
Behaves much like java.util.Map<K,V>'s entrySet() method.
keys
Behaves much like java.util.Map<K,V>'s keySet() method.
values
Behaves much like java.util.Map<K,V>'s values() method.
SingleList Implementation
signature SINGLE_LIST_DICTIONARY = sig include DICTIONARY val create_simple : unit -> (''k,'v) dictionary end
Hashtable Implementation
signature HASHED_DICTIONARY = sig include DICTIONARY type ''k hash_function = ''k -> int val create_hashed : (int * ''k hash_function) -> (''k,'v) dictionary end