anchor.diff:                      ((if cxa = 0 then l else addRange measurer (Range (rangeAB.MinValue, measurer.Previous x)) l),
                          true,
                          (if cbx = 0 then r else addRange measurer (Range (measurer.Next x, rangeAB.MaxValue)) r))
  -
  -    /// Builds a new DIET from the elements of a sequence.
  -    let ofSeq (measurer : IMeasurer<_>) (sequence : seq<_>) : Diet<'T> =
  -        (Empty, sequence)
  -        ||> Seq.fold (fun tree el ->
  -            add measurer el tree)
  -
  -    /// Builds a new DIET from the elements of an F# list.
  -    let ofList (measurer : IMeasurer<_>) (list : _ list) : Diet<'T> =
  -        (Empty, list)
  -        ||> List.fold (fun tree el ->
  -            add measurer el tree)
  -
  -    /// Builds a new DIET from the elements of an array.
  -    let ofArray (measurer : IMeasurer<_>) (array : _[]) : Diet<'T> =
  -        (Empty, array)
  -        ||> Array.fold (fun tree el ->
  -            add measurer el tree)
  -
  -    //
  -    let forall (predicate : 'T -> bool) (measurer : IMeasurer<_>) (t : Diet<'T>) =
  -        // OPTIMIZE : Rewrite this to short-circuit and return early
  -        // if we find a non-matching element.
  -        (measurer, true, t)
  -        |||> fold (fun state el ->
  -            state && predicate el)
   
   
   /// Character set implementation based on a Discrete Interval Encoding Tree.
  
positive.code: 
      override this.ToString () =
          sprintf "[%O, %O]" this.MinValue this.MaxValue
  
  /// A Discrete Interval Encoding Tree (DIET).
  type private Diet<'T when 'T : comparison> =
  
negative.code:         
          cardinal_aux 0 [t]
  
      /// Returns the number of intervals in the set.
      let intervalCount (t : Diet<'T>) =
          let rec cardinal_aux acc = function
              | [] -> acc
              | AvlTree.Empty :: ts ->
                  cardinal_aux acc ts
              | AvlTree.Node (range : Range<_>, left, right, _) :: ts ->
                  cardinal_aux (acc + 1) (left :: right :: ts)
          
          cardinal_aux 0 [t]
  
      /// Applies the given accumulating function to all elements in a DIET.
      let fold (folder : 'State -> _ -> 'State) (measurer : IMeasurer<_>) (state : 'State) (tree : Diet<'T>) =
          let rangeFolder (state : 'State) (range : Range<_>) =
              let q = range.MaxValue
              // Fold over the items in increasing order.
              let mutable state = state
              let mutable currentItem = range.MinValue
              while currentItem <> q do
                  state <- folder state currentItem
                  currentItem <- measurer.Next currentItem
  
              // Apply the folder function to the last value in the range 'q'.
              folder state q
  
          AvlTree.fold rangeFolder state tree
  
      /// Applies the given accumulating function to all elements in a DIET.
      let foldBack (folder : _ -> 'State -> 'State) (measurer : IMeasurer<_>) (tree : Diet<'T>) (state : 'State) =
          let rangeFolder (range : Range<_>) (state : 'State) =
              let p = range.MinValue
  
              // Fold over the items in decreasing order.
              let mutable state = state
              let mutable currentItem = range.MaxValue
              while currentItem <> p do
                  state <- folder currentItem state
                  currentItem <- measurer.Previous currentItem
  
              // Apply the folder function to the first value in the range 'p'.
              folder p state
  
          AvlTree.foldBack rangeFolder tree state
  
      //
      let rec toSeq (measurer : IMeasurer<_>) (tree : Diet<'T>) =
          seq {
          match tree with
          | Empty -> ()
          | Node (range : Range<_>, l, r, _) ->
              yield! toSeq measurer l
              yield! range.ToSeq measurer
              yield! toSeq measurer r
          }
  
      //
      let toList (measurer : IMeasurer<_>) (tree : Diet<'T>) =
          (measurer, [], tree)
          |||> fold (fun list el ->
              el :: list)
  
      //
      let toArray (measurer : IMeasurer<_>) (tree : Diet<'T>) =
          let elements = ResizeArray ()
          // TODO : Simplify this to use 'iter' instead of 'fold'.
          (measurer, elements, tree)
          |||> fold (fun resizeArr el ->
              resizeArr.Add el
              resizeArr)
          |> ignore
          elements.ToArray ()
  
      //
      let forall (predicate : 'T -> bool) (measurer : IMeasurer<_>) (t : Diet<'T>) =
          // OPTIMIZE : Rewrite this to short-circuit and return early
          // if we find a non-matching element.
          (measurer, true, t)
          |||> fold (fun state el ->
              state && predicate el)
  
      //
      let rec private addRec (measurer : IMeasurer<_>) p (tree : Diet<'T>) cont : Diet<_> =
          let inline compare a b =
              measurer.Compare (a, b)
  
          match tree with
          | Empty ->
              singleton p
              |> cont
          | Node (rangeXY, left, right, h) as t ->
              if compare p rangeXY.MinValue >= 0 then
                  if compare p rangeXY.MaxValue <= 0 then
                      cont t
  
                  elif compare p (measurer.Next rangeXY.MaxValue) > 0 then
                      addRec measurer p right <| fun right ->
                          AvlTree.join rangeXY left right
                          |> cont
  
                  elif AvlTree.isEmpty right then
                      AvlTree.Node (Range (rangeXY.MinValue, p), left, right, h)
                      |> cont
  
                  else
                      let rangeUV, r = AvlTree.extractMin measurer right
                      if measurer.Previous rangeUV.MinValue = p then
                          let rangeXV = Range (rangeXY.MinValue, rangeUV.MaxValue)
                          AvlTree.join rangeXV left r
                      else
                          let rangeXP = Range (rangeXY.MinValue, p)
                          AvlTree.Node (rangeXP, left, right, h)
                      |> cont
  
              elif compare p (measurer.Previous rangeXY.MinValue) < 0 then
                  addRec measurer p left <| fun left ->
                      AvlTree.join rangeXY left right
                      |> cont
  
              elif AvlTree.isEmpty left then
                  let rangePY = Range (p, rangeXY.MaxValue)
                  AvlTree.Node (rangePY, left, right, h)
                  |> cont
  
              else
                  let rangeUV, l = AvlTree.extractMax measurer left
                  if measurer.Next rangeUV.MaxValue = p then
                      let rangeUY = Range (rangeUV.MinValue, rangeXY.MaxValue)
                      AvlTree.join rangeUY l right
                  else
                      let rangePY = Range (p, rangeXY.MaxValue)
                      AvlTree.Node (rangePY, left, right, h)
                  |> cont
  
      /// Returns a new set with the specified value added to the set.
  