Difference between revisions of "Sorted Dictionary Assignment"

From CSE425S Wiki
Jump to navigation Jump to search
(Created page with " <nowiki>signature DICTIONARY = sig type (''k,'v) dictionary val get : ((''k,'v) dictionary *''k) -> 'v option val put : ((''k,'v) dictionary *''k *'v) -> 'v optio...")
 
Line 8: Line 8:
 
     val values : (''k,'v) dictionary -> 'v list
 
     val values : (''k,'v) dictionary -> 'v list
 
end</nowiki>
 
end</nowiki>
 +
=Code To Use=
  
=Sorted Implementation=
+
<nowiki>signature BINARY_TREE = sig
 +
val map : ('a -> 'b) -> ('a binary_tree) -> 'b binary_tree
 +
val filter : ('a -> bool) -> ('a binary_tree) -> 'a binary_tree
 +
val find_lnr : ('a -> bool) -> ('a binary_tree) -> 'a option
 +
val find_rnl : ('a -> bool) -> ('a binary_tree) -> 'a option
 +
val fold_lnr : (('a * 'b) -> 'b) -> ('b) -> ('a binary_tree) -> 'b
 +
val fold_rnl : (('a * 'b) -> 'b) -> ('b) -> ('a binary_tree) -> 'b
 +
end</nowiki>
 +
 
 +
=Code To Implement=
 +
==Sorted Implementation==
 
  <nowiki>signature SORTED_DICTIONARY = sig include DICTIONARY
 
  <nowiki>signature SORTED_DICTIONARY = sig include DICTIONARY
 
   type ''k compare_function = (''k*''k) -> order
 
   type ''k compare_function = (''k*''k) -> order
 
   val create_sorted : ''k compare_function -> (''k,'v) dictionary
 
   val create_sorted : ''k compare_function -> (''k,'v) dictionary
end
+
end</nowiki>
</nowiki>
 

Revision as of 15:52, 26 June 2019

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

Code To Use

signature BINARY_TREE = sig
 val map : ('a -> 'b) -> ('a binary_tree) -> 'b binary_tree
 val filter : ('a -> bool) -> ('a binary_tree) -> 'a binary_tree
 val find_lnr : ('a -> bool) -> ('a binary_tree) -> 'a option
 val find_rnl : ('a -> bool) -> ('a binary_tree) -> 'a option
 val fold_lnr : (('a * 'b) -> 'b) -> ('b) -> ('a binary_tree) -> 'b
 val fold_rnl : (('a * 'b) -> 'b) -> ('b) -> ('a binary_tree) -> 'b
end

Code To Implement

Sorted Implementation

signature SORTED_DICTIONARY = sig include DICTIONARY
   type ''k compare_function = (''k*''k) -> order
   val create_sorted : ''k compare_function -> (''k,'v) dictionary
end