Skip to content

Commit

Permalink
[enhance] stdlib, map: max_binding
Browse files Browse the repository at this point in the history
  • Loading branch information
BourgerieQuentin committed Jan 30, 2012
1 parent 32e38cc commit 53f1fc8
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions stdlib/core/map/map.opa
Expand Up @@ -190,6 +190,8 @@ type Map('key,'order) =

min_binding: ordered_map('key,'val,'order) -> ('key, 'val)

max_binding: ordered_map('key,'val,'order) -> ('key, 'val)

/**
* Determine if a key appears in a map.
*
Expand Down Expand Up @@ -451,6 +453,14 @@ Map_private =
| { empty } -> error("Map.min_binding: Not Found")
aux(m)

max_binding(m : Map_private.map) =
rec aux(a_map : Map_private.map) =
match a_map with
| { left = _ ~key ~value right = ({ empty } : map) ... } -> (key, value)
| { left = _ key = _ value = _ ~right ... } -> aux(right)
| { empty } -> error("Map.max_binding: Not Found")
aux(m)

remove_min_binding(m : Map_private.map) =
rec aux(a_map : Map_private.map) =
match a_map with
Expand Down Expand Up @@ -727,6 +737,9 @@ Map_make(order: order('key,'order) ) : Map =
min_binding(m : ordered_map('key, 'val, 'order)) =
Map_private.min_binding(m)

max_binding(m : ordered_map('key, 'val, 'order)) =
Map_private.max_binding(m)

// remove_min_binding(m) = @wrap(_remove_min_binding(@unwrap(m)))


Expand Down

0 comments on commit 53f1fc8

Please sign in to comment.