Skip to content
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

Open
wants to merge 22 commits into
base: master
Choose a base branch
from

Conversation

MinionJakub
Copy link
Contributor

First implementation of Ordered Map and Ordered Set

First implementation of Ordered Map and Ordered Set
Copy link
Collaborator

@Foxinio Foxinio left a 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.

lib/OrderedMap.fram Outdated Show resolved Hide resolved
lib/OrderedMap.fram Outdated Show resolved Hide resolved
lib/OrderedMap.fram Outdated Show resolved Hide resolved
lib/OrderedMap.fram Outdated Show resolved Hide resolved
lib/OrderedMap.fram Outdated Show resolved Hide resolved
lib/OrderedMap.fram Outdated Show resolved Hide resolved
lib/OrderedMap.fram Outdated Show resolved Hide resolved
lib/OrderedMap.fram Outdated Show resolved Hide resolved
lib/OrderedMap.fram Outdated Show resolved Hide resolved
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.
Copy link
Collaborator

@Foxinio Foxinio left a 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.

lib/OrderedMap.fram Outdated Show resolved Hide resolved
lib/OrderedMap.fram Outdated Show resolved Hide resolved
lib/OrderedMap.fram Outdated Show resolved Hide resolved
lib/OrderedMap.fram Outdated Show resolved Hide resolved
lib/OrderedMap.fram Outdated Show resolved Hide resolved
test/stdlib/stdlib0002_Set.fram Outdated Show resolved Hide resolved
lib/OrderedMap.fram Outdated Show resolved Hide resolved
lib/OrderedMap.fram Outdated Show resolved Hide resolved
test/stdlib/stdlib0003_Queue.fram Outdated Show resolved Hide resolved
test/stdlib/stdlib0003_Queue.fram Outdated Show resolved Hide resolved
lib/OrderedMap.fram Outdated Show resolved Hide resolved
lib/OrderedMap.fram Outdated Show resolved Hide resolved
lib/OrderedMap.fram Outdated Show resolved Hide resolved
Copy link
Collaborator

@Foxinio Foxinio left a 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

lib/Map.fram Outdated Show resolved Hide resolved
lib/Map.fram Outdated Show resolved Hide resolved
lib/Map.fram Outdated Show resolved Hide resolved
lib/Map.fram Outdated Show resolved Hide resolved
lib/Map.fram Outdated Show resolved Hide resolved
lib/Set.fram Outdated Show resolved Hide resolved
lib/Set.fram Outdated Show resolved Hide resolved
test/stdlib/stdlib0001_Map.fram Show resolved Hide resolved
test/stdlib/stdlib0002_Set.fram Outdated Show resolved Hide resolved
test/stdlib/stdlib0002_Set.fram Outdated Show resolved Hide resolved
@MinionJakub MinionJakub requested a review from Foxinio December 13, 2024 22:48
Copy link
Collaborator

@Foxinio Foxinio left a 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
Copy link
Collaborator

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
Copy link
Collaborator

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)
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link
Collaborator

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) =
Copy link
Collaborator

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 =
Copy link
Collaborator

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
Copy link
Collaborator

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 {
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants