Difference between revisions of "Sorted Dictionary Assignment"
Line 40: | Line 40: | ||
end) | end) | ||
− | </ | + | </syntaxhighlight> |
[[File:Sorted dictionary.svg]] | [[File:Sorted dictionary.svg]] | ||
Line 49: | Line 49: | ||
<syntaxhighlight lang="sml"> | <syntaxhighlight lang="sml"> | ||
(* TODO: replace unit with the type you decide upon *) | (* TODO: replace unit with the type you decide upon *) | ||
− | type (''k,'v) dictionary = unit | + | type (''k,'v) dictionary = unit |
</syntaxhighlight> | </syntaxhighlight> | ||
Line 56: | Line 56: | ||
<syntaxhighlight lang="sml"> | <syntaxhighlight lang="sml"> | ||
− | type ''k create_parameter_type = ''k compare_function | + | type ''k create_parameter_type = ''k compare_function |
</syntaxhighlight> | </syntaxhighlight> | ||
Line 62: | Line 62: | ||
<syntaxhighlight lang="sml"> | <syntaxhighlight lang="sml"> | ||
fun create(cmp : ''k compare_function) : (''k,'v) dictionary = | fun create(cmp : ''k compare_function) : (''k,'v) dictionary = | ||
− | raise Fail "NotYetImplemented" | + | raise Fail "NotYetImplemented" |
</syntaxhighlight> | </syntaxhighlight> | ||
Line 68: | Line 68: | ||
<syntaxhighlight lang="sml"> | <syntaxhighlight lang="sml"> | ||
fun get(dict : (''k,'v) dictionary, key : ''k) : 'v option = | fun get(dict : (''k,'v) dictionary, key : ''k) : 'v option = | ||
− | raise Fail "NotYetImplemented" | + | raise Fail "NotYetImplemented" |
</syntaxhighlight> | </syntaxhighlight> | ||
Line 76: | Line 76: | ||
<syntaxhighlight lang="sml"> | <syntaxhighlight lang="sml"> | ||
fun put(dict : (''k,'v) dictionary, key : ''k , value : 'v) : (''k,'v) dictionary * 'v option = | fun put(dict : (''k,'v) dictionary, key : ''k , value : 'v) : (''k,'v) dictionary * 'v option = | ||
− | raise Fail "NotYetImplemented" | + | raise Fail "NotYetImplemented" |
</syntaxhighlight> | </syntaxhighlight> | ||
Line 84: | Line 84: | ||
<syntaxhighlight lang="sml"> | <syntaxhighlight lang="sml"> | ||
fun remove(dict : (''k,'v) dictionary, key : ''k) : (''k,'v) dictionary * 'v option = | fun remove(dict : (''k,'v) dictionary, key : ''k) : (''k,'v) dictionary * 'v option = | ||
− | raise Fail "NotYetImplemented" | + | raise Fail "NotYetImplemented" |
</syntaxhighlight> | </syntaxhighlight> | ||
Line 92: | Line 92: | ||
<syntaxhighlight lang="sml"> | <syntaxhighlight lang="sml"> | ||
fun entries(dict : (''k,'v) dictionary) : (''k*'v) list = | fun entries(dict : (''k,'v) dictionary) : (''k*'v) list = | ||
− | raise Fail "NotYetImplemented" | + | raise Fail "NotYetImplemented" |
</syntaxhighlight> | </syntaxhighlight> | ||
Latest revision as of 19:39, 14 July 2023
Contents
Code To Use
Binary Search Tree
You will undoubtedly want to use the tree you implemented in the Binary Search Tree assignment.
DictionaryFn
The structure SortedDictionary has been setup to re-use functor DictionaryFn from the Chained Dictionary exercise.
Code To Implement
structure SortedDictionary
SortedDictionary must:
- have O(lg N) expected performance for
get
,put
, andremove
. - produce
entries
andkeys
in sorted order based on the providedcompare_function
. - produce
values
in the sorted order of each value's key based on the providedcompare_function
.
structure SortedDictionary = DictionaryFn(struct
type ''k compare_function = (''k*''k) -> order
(* TODO: replace unit with the type you decide upon *)
type (''k,'v) dictionary = unit
type ''k create_parameter_type = ''k compare_function
fun create(cmp : ''k compare_function) : (''k,'v) dictionary =
raise Fail "NotYetImplemented"
fun get(dict : (''k,'v) dictionary, key:''k) : 'v option =
raise Fail "NotYetImplemented"
fun put(dict : (''k,'v) dictionary, key:''k, value:'v) : (''k,'v) dictionary * 'v option =
raise Fail "NotYetImplemented"
fun remove(dict : (''k,'v) dictionary, key : ''k) : (''k,'v) dictionary * 'v option =
raise Fail "NotYetImplemented"
fun entries(dict : (''k,'v) dictionary) : (''k*'v) list =
raise Fail "NotYetImplemented"
end)
type dictionary
Change the definition of type (''k,'v) dictionary to support SortedDictionary.
(* TODO: replace unit with the type you decide upon *)
type (''k,'v) dictionary = unit
type create_parameter_type
Leave create_parameter_type unchanged. SortedDictionary's create method accepts a single compare_function parameter, so ''k compare_function is the correct type.
type ''k create_parameter_type = ''k compare_function
create
fun create(cmp : ''k compare_function) : (''k,'v) dictionary =
raise Fail "NotYetImplemented"
get
fun get(dict : (''k,'v) dictionary, key : ''k) : 'v option =
raise Fail "NotYetImplemented"
A function from BinarySearchTree should be useful here.
put
fun put(dict : (''k,'v) dictionary, key : ''k , value : 'v) : (''k,'v) dictionary * 'v option =
raise Fail "NotYetImplemented"
A function from BinarySearchTree should be useful here.
remove
fun remove(dict : (''k,'v) dictionary, key : ''k) : (''k,'v) dictionary * 'v option =
raise Fail "NotYetImplemented"
A function from BinarySearchTree should be useful here.
entries
fun entries(dict : (''k,'v) dictionary) : (''k*'v) list =
raise Fail "NotYetImplemented"
A function from BinarySearchTree should be useful here.
Testing
Complete
source folder: | src/test/sml/dictionary/sorted |
how to run with CM.make verbosity off: | sml -Ccm.verbose=false run_sorted_testing.sml |
how to run with CM.make verbosity on: | sml run_sorted_testing.sml |
note: ensure that you have removed all printing to receive credit for any assignment.
Without Remove
sml -Ccm.verbose=false run_sorted_testing.sml --remove=false
sml run_sorted_testing.sml --remove=false
Pledge, Acknowledgments, Citations
file: | studio-sorted-dictionary-pledge-acknowledgments-citations.txt |
More info about the Honor Pledge