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

Remove fns #38

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open

Remove fns #38

wants to merge 13 commits into from

Conversation

FayCarsons
Copy link

@FayCarsons FayCarsons commented Feb 11, 2024

Implemented removal by equality and by envelope in a way I'm pretty happy about.

Testing is needed (which, I'm not super sure how to go about that) and I think the aux functions for both can be combined into a single removal by predicate fn? But there's also potential branching optimizations in the case of the removal by envelope operation that may clash with that? Will investigate!

Copy link
Contributor

@patricoferris patricoferris left a comment

Choose a reason for hiding this comment

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

This is looking great, thanks @FayCarsons !!

In terms of testing, I think we can add some unit tests to basic.ml. Maybe something like:

let test_remove () =
  let module R = R1 in
  let lines =
    [
      { p1 = (0., 0.); p2 = (1., 1.) };
      { p1 = (1., 1.); p2 = (2., 2.) };
      { p1 = (2., 2.); p2 = (3., 3.) };
      { p1 = (3., 3.); p2 = (4., 4.) };
    ]
  in
  let idx = R.load ~max_node_load:2 lines in
  let t' = R.remove_eq idx (List.hd lines) in
  match t' with
    | None -> failwith "Unexpected none returned from remove"
    | Some (vs, t') ->
    assert (R.size t' = 3);
    assert (List.hd vs = List.hd lines)

There might nicer/more rigorous tests too.

src/rtree.ml Outdated
| Empty -> ([], Empty)

let remove_env t env =
match remove_env' env t with [], _ -> None | elts, t' -> Some (elts, t')
Copy link
Contributor

@patricoferris patricoferris Feb 20, 2024

Choose a reason for hiding this comment

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

We'll probably want to expose this in the Rtree interface (module type S) as something like:

val remove_env : t -> Envelope.t -> (Value.t list * t) option

In which case the implementation will have to unwrap the tree and rewrap it as a t, something like:

Suggested change
match remove_env' env t with [], _ -> None | elts, t' -> Some (elts, t')
match remove_env' env t.tree with
| [], _ -> None
| elts, t' -> Some (elts, { t with tree = t' })

Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly for remove_eq

src/rtree.ml Outdated
(elts, Leaf non_matching)
| Empty -> ([], Empty)

let remove_eq t ty e =
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let remove_eq t ty e =
let remove_eq t e =

Note that we don't have to explicitly pass the runtime type into this function. Instead, it has already been made available as an argument to the functor we are currently inside, so we can just pass V.t directly to Repr.equal.

@patricoferris
Copy link
Contributor

Sorry for the delay!

@FayCarsons
Copy link
Author

Thanks for the feedback! Applied suggestions and added unit test, will try to add more later when I can take a closer look at the test suite.

@FayCarsons
Copy link
Author

Added more unit tests. Testing removal on an empty tree, removal from a tree w/ one elt, removing an elt that doesn't exist, removing a lot of elts. I wanted to add a test for removing from a degenerate tree but wasn't sure how to construct a degenerate tree. Can explore later. Fixed doc comments.

@FayCarsons
Copy link
Author

Added another unit test that inserts 100 random elts, half within an envelope and half out, and then removes the half within the envelope.

I'm not super experienced with unit testing, would love any suggestions for new unit tests if this is not comprehensive enough!

@FayCarsons
Copy link
Author

Hi @patricoferris ! Was just reminded of this PR and was wondering if there's anything I can do to get it merged?

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.

2 participants