Skip to content

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.

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.

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

@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.

Copy link
Member

@dominik-muc dominik-muc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I've seen and tested it works OK, however it could use some minor fixes. That being said, I think it provides a lot of functionality and we should look forward into merging. Improvements can be made later on, as they are not crucial, especially given that size of this PR is already huge.

Copy link
Collaborator

@wojpok wojpok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Core functions of HMQueue are copied from Okasaki's book, I believe there are no issues there. I recommend to delete map and foldLeft functions and replace them with combinations of toList, fromList.

Correctness of Maps and Sets hinges on the implementation of Red Black trees. The interaface of RB Trees is too robust to be read easily,. Since there are no comments that clarify any of the endless pattern matching cases, I can't do more that just believe that this implementation is ok. I would like to see some clarification about those trees.

Beside minor issues I have pointed out, this is more or less ready to be merged

| Appending of NotNegativeInt, List Val, List Val
| Done of List Val

data HoodMelvilleQueue Val =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type should be abstract. As is right now, it can't be used to annotate stuff outside this module. Also, name could be shorter, maybe HMQueue or just plain and simple Queue?

)
end

pub let emptyQueue = HMQueue Zero [] Idle Zero []
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not empty?

pub method isEmpty self = isEmpty self
pub method snoc self = snoc self
pub method tail self = tail self
pub method push self = snoc self
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remane this to cons. Push is confusing.

lib/Map.fram Outdated

{## @brief Method that returns list of keys
##}
, method domain : {type Val} -> T Val ->[] List Key
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not toKeyList? This naming is confusing

lib/Map.fram Outdated
upperBoundLeqErr compare tree key

pub let make {Key} (compare : Key -> Key ->[] Ordered) = Map {
T = MapT Key
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Size method is missing

lib/Set.fram Outdated

pub let make {Val} (compare : Val -> Val ->[] Ordered) = Set {
T = Tree Val
, empty = empty
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

size is missing

@ppolesiuk ppolesiuk requested a review from Copilot October 23, 2025 11:17
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements Ordered Map and Ordered Set data structures using a Red-Black Tree implementation, along with a Queue data structure based on the Hood-Melville algorithm.

Key Changes:

  • Added Red-Black Tree implementation as the underlying data structure for ordered collections
  • Implemented Hood-Melville Queue with lazy rotation state management
  • Added Ordered type to Base/Types for comparison operations

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
lib/RedBlackTree.fram Core red-black tree implementation with insert, delete, search, split and join operations
lib/Queue.fram Hood-Melville Queue implementation with amortized O(1) operations
test/stdlib/stdlib0005_Queue.fram Test suite for Queue operations including push, pop, head, isEmpty, and list conversions
lib/Prelude.fram Added trailing newline for consistency
lib/Base/Types.fram Added Ordered data type for comparison results (Lt, Eq, Gt)
Comments suppressed due to low confidence (1)

lib/Queue.fram:1

  • Missing space after '::' operator. Should be 'value :: zipper' for consistency with similar patterns throughout the codebase (e.g., lines 197, 199, 208).
{# This file is part of DBL, released under MIT license.

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.


data HoodMelvilleQueue Val =
| HMQueue of NotNegativeInt, List Val, RotationState Val,
NotNegativeInt, List Val
Copy link

Copilot AI Oct 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent indentation: line 29 should align with the opening parameter on line 28. The second line of the constructor parameters uses 1 space instead of 3 spaces for proper alignment.

Suggested change
NotNegativeInt, List Val
NotNegativeInt, List Val

Copilot uses AI. Check for mistakes.
@MinionJakub MinionJakub added the stdlib Work on standard library label Oct 27, 2025
@MinionJakub MinionJakub changed the title Ordered Map and Ordered Set Red Black Tree Oct 27, 2025
@MinionJakub MinionJakub requested review from Foxinio and wojpok October 27, 2025 09:08
Copy link
Collaborator

@wojpok wojpok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for cutting code, it is much easier to manage then is was before.

First and foremost, some issues from Queue module are still unresolved. Please, put queues into separate MR. They are almost ready to be merged, we don't have to wait for Maps and Sets.

Secondly, I have pointed it out on many occasions and I will hold to that. This implementation of RedBlackTrees is really robust and exposes way too much control over this structure. Zippers shouldn't be at any point a part of public interface. Some interface changes are required. You can go 2 ways from here:
You can make this interface user friendly by defining some sort of abstract iterator that will enable in place modifications. The zipper will private within this context. Or you simply make RB Tree completely private and implement really basic Map data structure. It's up to you

@wojpok
Copy link
Collaborator

wojpok commented Nov 2, 2025

I have an idea. Please begin with documenting the RBTree library. Explain each public function (its use case, assumptions, exceptions). Maybe the right documentation is everything this modile actually needs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stdlib Work on standard library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants