- val middle : t -> elt option

- val find : elt -> t -> elt option

+ val unsafe_binary : t -> (t * elt * t) option

+ val unsafe_middle : t -> elt option

+ val unsafe_find : elt -> t -> elt option

module Make(Ord : OrderedType) : S with type elt = Ord.t = struct

- (* find the middle element in [t] *)

- if is_empty t then None

- let found = ref None in

- ignore (filter (fun elt ->

+ (* Warning! Unsafe operation!

+ Currently, there is no easy way to get the binary tree structure from a set,

+ though it is very handy for efficient binary search.

+ The following easily breaks when the internal implementation of Set.t is changed.

+ type t_internal = Empty | Node of t * elt * t * int

+ let unsafe_internal t = (Obj.magic t : t_internal)

- (* find the "same" element as [elt] in [t] *)

+ let _dummy () = [Empty ; Node (assert false, assert false, assert false, 0)]

+ let unsafe_binary t = match unsafe_internal t with

+ | Node (left, v, right, _) -> Some (left, v, right)

+ let unsafe_middle t = match unsafe_internal t with

+ | Node (_, v, _, _) -> Some v

+ let rec unsafe_find elt t = match unsafe_internal t with

+ | Node (left, elt', right, _) ->

match Ord.compare elt elt' with

- let l, present, _ = split elt' t in

- let _, present, r = split elt' t in

+ | -1 -> unsafe_find elt left

+ | 1 -> unsafe_find elt right