-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ordered Map and Ordered Set #136
base: master
Are you sure you want to change the base?
Conversation
First implementation of Ordered Map and Ordered Set
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wrote some change suggestions, There might be more down the line, but most importantly we need tests. With merging of #116 there is a way of testing stdlib, so add more tests there.
Small changes to address my mistakes in naming.
First implementation of queues based on implementation of Hood Melville queues from "Purely Functional Data Structures" Chris Okasaki.
Little correction of definitions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wrote some comments, suggestions made in them apply in more places than specified, and i feel like some of them i already pointed out in my previous review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pointed out some needed of changes, couple of them need to be applied across whole file, or commit (mainly fixing spacing, indentation, and formatting). Also please add documentation comments to all public facing constructs, since in many instances it isn't clear what functions do without diving into implementation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally this is headed in a good direction, but still needs some changes.
Key -> [] (Pair (T Val) Bool) | ||
, method member : {type Val} -> T Val -> Key -> [] Bool | ||
, method find : {type Val} -> T Val -> Key -> [] Option Val | ||
(** @brief method that searches for an item and returns value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment looks great, but i think all function/methods in this signature deserve one.
pub let assert condition msg = | ||
if condition then () else ((printStrLn msg) ; exit 1) | ||
|
||
pub data Comparable = Eq| Noteq |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this definition is redundant, since simple Bool accomplishes this well enough.
, method intersection = intersection compare | ||
, method difference = difference compare | ||
, method eq = fn set1 set2 => | ||
eqMain (fn e1 e2 => (compare e1 e2).toComparable) (T set1 Nil) (T set2 Nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pretty sure this can be accomplished with compare e1 e2 == Equal
match queue with | ||
| HMQueue Zero _ _ _ _ => None | ||
| HMQueue _ (x::xs) _ _ _ => Some x | ||
| _ => None // Impossible |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After merging of #158 this will have to me replaced with impossible
zipBlack | ||
tree (Right Red right2 value1 :: Right Black left2 value2 :: rest) | ||
|
||
//Impossible |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, impossible
from #158
pub data Interval Value = Inclusion of Value | Exclusion of Value | ||
|
||
pub data Set Elem = Set of { | ||
T |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as with Map
, this signature requires documentation.
match tree2 with | ||
| Leaf => tree1 | ||
| _ => | ||
let (value_out, left2, right2) = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be sequence of definitions
@@ -43,3 +43,17 @@ pub module Int64 | |||
pub let one = 1L | |||
pub let ofInt (n : Int) = n.toInt64 | |||
end | |||
|
|||
pub let assert condition msg = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like this PR is up so long, that this will be replaced by assert
from #158
@@ -0,0 +1,81 @@ | |||
import Map |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests will have to be somewhat rewritten to be compatible with #158
let upperBoundLeqTErr compare (MapT tree) key = | ||
upperBoundLeqErr compare tree key | ||
|
||
pub let make {Key} (compare : Key -> Key -> [] Ordered) = Map { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add another make
(I don't know what the name should be), that will take as an argument type of key, and get comparator from method compare?
The same would be useful with sets
First implementation of Ordered Map and Ordered Set