From 206df031b380b810b230611a3f8dd983684555fd Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Wed, 12 Feb 2025 12:25:08 +0000 Subject: [PATCH] implement 'insRight' function for inserting to the right --- src/gap_map.sml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/gap_map.sml b/src/gap_map.sml index 8d42af1..d3f8c4b 100644 --- a/src/gap_map.sml +++ b/src/gap_map.sml @@ -477,4 +477,20 @@ struct tryJoinMaxSide (hdKeys, hdVals, leftKeys, leftVals, rightKeys, rightVals) end + + fun add (newKey, newVal, map as {leftKeys, leftVals, rightKeys, rightVals}: t) = + (* look at elements to see which way to traverse *) + case rightKeys of + hd :: _ => + let + val rfirst = Vector.sub (hd, 0) + in + if Fn.g (new, rfirst) then + insRight (newKey, newVal, leftKeys, leftVals, rightKeys, rightVals) + else if Fn.l (new, rfirst) then + insLeft (newKey, newVal, leftKeys, leftVals, rightKeys, rightVals) + else + map + end + | [] => insLeft (newKey, newVal, leftKeys, leftVals, rightKeys, rightVals) end