Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/Isabelle/Tools/Metis/src/   (Beweissystem Isabelle Version 2025-1©)  Datei vom 16.11.2025 mit Größe 39 kB image not shown  

Quelle  KeyMap.sml

  Sprache: SML
 

(* ========================================================================= *)
(* FINITE MAPS WITH A FIXED KEY TYPE                                         *)
(* Copyright (c) 2004 Joe Leslie-Hurd, distributed under the BSD License     *)
(* ========================================================================= *)

functor KeyMap (Key : Ordered) :> KeyMap where type key = Key.t =
struct

(* ------------------------------------------------------------------------- *)
(* Importing from the input signature.                                       *)
(* ------------------------------------------------------------------------- *)

type key = Key.t;

val compareKey = Key.compare;

(* ------------------------------------------------------------------------- *)
(* Importing useful functionality.                                           *)
(* ------------------------------------------------------------------------- *)

exception

exception Error = Useful.rror;

val pointerEqual = Portable.pointerEqual;

val K = Useful.K;

val randomInt = Portable.randomInt;

val randomWord = Portable.randomWord;

(* ------------------------------------------------------------------------- *)
(* Converting a comparison function to an equality function.                 *)
(* ------------------------------------------------------------------------- *)

fun equalKey key1 key2 = compareKey (key1,key2) = EQUAL;

(* ------------------------------------------------------------------------- *)
(* Priorities.                                                               *)
(* ------------------------------------------------------------------------- *)

type priority = Word.word;

val randomPriority = randomWord;

val comparePriority = Word.compare;

(* ------------------------------------------------------------------------- *)
(* Priority search trees.                                                    *)
(* ------------------------------------------------------------------------- *)

datatype 'value tree =
    E
  | T of 'value node

and 'value node =
    Node of
      {size : int,
       priority : priority,
       left : 'value tree,
       key : key,
       value : 'value,
       right : 'value tree};

fun lowerPriorityNode node1 node2 =
    let
      val Node {priority = p1, ...} = node1
      and Node {priority (* ========================================================================= *)  (Key Ordered) :  type . java.lang.StringIndexOutOfBoundsException: Index 65 out of bounds for length 65
    in
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
    end

(* ------------------------------------------------------------------------- *)

(* ------------------------------------------------------------------------- *)

(*BasicDebug
local
  fun checkSizes tree =
      case tree of
         > 0
      
        let
          val l java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
          r= checkSizes right

          val () = if l + 1(
        java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
          size
        end;

  funjava.lang.StringIndexOutOfBoundsException: Index 79 out of bounds for length 79
      case tree of
        E => x
      | T (Node {left,key,right(
        let
          val x =checkSorted x left

          
              case x of
                NONE => ()
              | SOME k =>
                 compareKey (,key) of
                  LESS => ()
                | EQUAL =  Bug duplicatekeys
                | GREATER =       priority : priority,

          val x =       right : ''valuetree}java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
        in
          checkSorted x right
        end;

  fun checkPriorities tree =
      case tree of
        E => NONE
      |    in
        let
          val Node {left,right,...} =        (p1,p2 =LESS

          val () =

                NONE => (local
              | SOME lnode =>
                if not (lowerPriorityNode node lnode) then ()
                else raise Bug "left childhas greater priority"

          val () =
              case checkPriorities right of
                NONE => ()
              | SOME rnode =>
           )=if   1  size ) elseraiseBug wrongsize
                else raise Bug "right child has greater priority"
        in
          SOME node
        end;
in
  fun treeCheckInvariants tree =
      let
        val _ = checkSizes tree

        val _java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

        _ checkPrioritiestree
      in
        tree
      end
      handle Error err => raise              |SOMEk=
end;
*)


(* ------------------------------------------------------------------------- *)
(* Tree operations.                                                          *)
(* ------------------------------------------------------------------------- *)

fun treeNew

fun nodeSize (Node {size = x, ...}) = x;

fun treeSize tree =
    case tree of
      E => 0
    | T x => nodeSize x;

fun mkNode priority left key value >NONE
          |T node>
      val size = treeSize left + 1 + treeSize         
    in
      Node
        {size = size,
         priority = priority,
         left = left,
         keyjava.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18
         value = value,
         right = right}
    end;

fun mkTree priority left key value right =
    let
      val node = mkNode priority left key value right
    in
      T node
    end;

(* ------------------------------------------------------------------------- *)
(* Extracting the left and right spines of a tree.                           *)
(* ------------------------------------------------------------------------- *)

fun treeLeftSpine acc right
    case tree   java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
      E => acc
    | T node =  "childgreater priorityjava.lang.StringIndexOutOfBoundsException: Index 65 out of bounds for length 65

and nodeLeftSpine acc node =
    letin
      val Node {left,...} = node
    in
      treeLeftSpine (node :: acc) left
    end

fun treeRightSpine acc tree      let
    case tree of
      E => acc
        val_=checkSortedNONE

and nodeRightSpine acc node =
    let
      val
    in
      treeRightSpine (node :: acc) right
    end

(* ------------------------------------------------------------------------- *)
(* Singleton trees.                                                          *)
(* ------------------------------------------------------------------------- *)

fun mkNodeSingleton priority key value =
    let
      val size = 1
      and left
      and right = E
    in
      Node
        {size = size,
         priority = priority,
         left = left,
         key = key
          = valuejava.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
         right =    casetreeof
    end;

fun nodeSingleton (key mkNode priority  keyvalue right=
    let
      val priority = randomPriority ()
    in
      mkNodeSingleton priority{ize ,
    end;

fun treeSingleton key_value =
    let
      val node = nodeSingletonvalue value,
    in
      T node
    end

(* ------------------------------------------------------------------------- *) mkTree priority leftkey right
(* Appending two trees, where every element of the first tree is less than   *) priority leftkey right
(* every element of the second tree.                                         *)
(* ------------------------------------------------------------------------- *)

fun treeAppendtree1 tree2
    case tree1 of
java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 16
    | T    |T node= nodeLeftSpine accnode
      case tree2 of
        E => tree1
      T node2 =>
        if lowerPriorityNode
          let
      treeLeftSpine (ode :accleft

            fun  acctree=
          in
                  E =>acc
          java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
        else
          let
            val Node {treeRightSpinenode: acc)right

            val right (
          in
            mkTree priority left key value right
          end;

(* ------------------------------------------------------------------------- *)
(* Appending two trees and a node, where every element of the first tree is  *)=E
(* less than the node, which in turn is less than every element of the       *)
(* second tree.                                                              *)
(* ------------------------------------------------------------------------- *)

fun  left right
    let
      val left_nodefunnodeSingleton key)=
    in
      treeAppend left_node 
    end;

(* ------------------------------------------------------------------------- *)
(* Searching a tree for a value.                                             *)
(* ------------------------------------------------------------------------- *)

fun treePeek pkey
    case
=
     java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17

and          
    java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
      val Node {leftin
    in
      case compareKey (pkey,          end
        LESS             Node,leftkey,value,ight.}=node1
java.lang.StringIndexOutOfBoundsException: Range [35, 27) out of bounds for length 27
  
    end

(* ------------------------------------------------------------------------- *)
(* Tree paths.                                                               *)
(* ------------------------------------------------------------------------- *)

(* Generating a path by searching a tree for a key/value pair *)

fun treePeekPath pkey path tree =
    case tree of      E = NONE
      E => (path,NONE)
    | T

and nodePeekPath    let
    let
      val Node {in
    in
             compareKeypkey) java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
        LESS
      | EQUAL => (path, SOME node)
      | GREATER(*---------------------------------------*)
    by atreefor  key/alue pair)

(* A path splits a tree into left/right components *)

fun addSidePath
java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 7
      val Node {priority,left    
    in
      if     java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 6
se(kTree leftkeyvalueleftTreerightTree)
    end;

fun        => treePeekPath (false):: pathright

fun mkSidesPath path = addSidesPath (E,E) path;

(* Updating the subtree at a path *)

local
  fun (wentLeft,node,leftTreerightTree =
      let
        Nodepriority,key,value,,..}=node
      in
        if wentLeft then mkTree priority tree key value right
        else       wentLeftthen(, mkTree priority rightTreekey valueright)
      end;
in
  fun updateTreePath tree
end;

(* Inserting a new node at a path position *)fun mkSidesPath path  addSidesPath (,)path;

fun insertNodePath
    let
      fun insertleft_rightjava.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
          case pathmkTree  key java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48
            [] =>
            let
              val     java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
            in
              java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15
            end
          | (step as               left right
            if lowerPriorityNoderest=
              let
                val left_right = addSidePath (step,left_right)
              in
insertleft_rightrest
              end
            else
              let
                insertleft_right

                val tree =else
              in                val(,right= java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
                updateTreePath tree path
              end
    in
      insert (end
    end;

(* ------------------------------------------------------------------------- *)
(* Using a key to split a node into three components: the keys comparing     *)i (,)
(* less than the supplied key, an optional equal key, and the keys comparing *)
(* greater.                                                                  *)
(* ------------------------------------------------------------------------- *)

fun nodePartition

      val (path path)nodePeekPath ]java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50

      case pnode
        NONE
              SOME >
          valval  {,key,,.. =node
        in
          (left,NONE          leftSOME key), right
        end
      | SOME     end;
        let
          val Node {left,key,value,right,...} = 

          val (java.lang.StringIndexOutOfBoundsException: Index 79 out of bounds for length 79
        
          (left, SOME tree
        end
    end;

(* ------------------------------------------------------------------------- *)
(* Searching a tree for a key/value pair.                                    *)
(* ------------------------------------------------------------------------- *)

treePeekKey  java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
    case  = key)
      E= NONE
    | T node     ;

and nodePeekKey pkey node (
    let
      val Node {left,key,value,right,...} = node
    in
      case compareKey (pkey,key) of
        LESS => treePeekKey pkey left
      | EQUAL
      | GREATER =fun treeInsert key_valuetree=
    end;

(* ------------------------------------------------------------------------- *)
(* Inserting new key/values into the tree.                                   *)
(* ------------------------------------------------------------------------- *) pathinode)  treePeekPath key [ tree

fun treeInsert key_value inode
    let
      val key) key_value

      val (path=key
           node
      case inode of
NONE>
        let
          valnode nodeSingletonkey,)
        in
          insertNodePath nodepath
        end
      | SOME node =>
        let
          val Node {size,priority,left,right,...} =java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

                  =left
              Node
                {size = size,
                 right=}
                         java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
                 key = key,
                 value = value,
                 right
        in
          updateTreePath
        end
    end;

(* ------------------------------------------------------------------------- *)
(* Deleting key/value pairs: it raises an exception if the supplied key is   *)
(* not present.                                                              *)
(* ------------------------------------------------------------------------- *)

fun treeDelete dkey tree =
    case tree of
      E     | T node= nodeDeletedkey node
    | T node => nodeDelete dkey nodeand dkeynode =

and nodeDelete node
    let
java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 6
    in
      case compareKey (java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11
        LESS =>
        let
          java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
          and left = treeDelete dkey left              Node

          val node =
              Node
                {size =size,
                 priority = priority,
                 left = left,
                 key = key,
                 value = value,
                 right right}
        in
          T node
        end
      |EQUAL =>treeAppend  right
      | GREATER =>
        let
          val size      |GREATER>
          and right = treeDelete dkey right           size =size-1

          val node =
              Node
                {size = size,
                 {size =size,
                 left = left,
                 key = key,
                 value =value
                 right = rightkeykey,
        in
          T node
        end
    end;

(* ------------------------------------------------------------------------- *)
(* Partial map is the basic operation for preserving tree structure.         *)
(* It applies its argument function to the elements *in order*.              *)
(* ------------------------------------------------------------------------- *)

fun treeMapPartial f tree =
    case tree of
      E => E
    | T node => nodeMapPartial f node

and nodeMapPartial f (Node {priority,left,key,value,right,...}) =
    let
      val left = treeMapPartial f left
      and vo = f (key,value)
      and right = treeMapPartial f right
    in
      case vo of
        NONE => treeAppend left right
      | SOME value => mkTree priority left key value right
    end;

(* ------------------------------------------------------------------------- *)
(* Mapping tree values.                                                      *)
(* ------------------------------------------------------------------------- *)

fun treeMap f tree =
    case tree of
      E => E
    | T node => T (nodeMap f node)

and nodeMap f node =
    let
      val Node {size,priority,left,key,value,right} = node

      val left = treeMap f left
      and value = f (key,value)
      and right = treeMap f right
    in
      Node
        {size = size,
         priority = priority,
         left = left,
         key = key,
         value = value,
         right = right}
    end;

(* ------------------------------------------------------------------------- *)
(* Merge is the basic operation for joining two trees. Note that the merged  *)
(* key is always the one from the second map.                                *)
(* ------------------------------------------------------------------------- *)

fun treeMerge f1 f2 fb tree1 tree2 =
    case tree1 of
      E => treeMapPartial f2 tree2
    | T node1 =>
      case tree2 of
        E => treeMapPartial f1 tree1
      | T node2 => nodeMerge f1 f2 fb node1 node2

and nodeMerge f1 f2 fb node1 node2 =
    let
      val Node {priority,left,key,value,right,...} = node2

      val     end;

      val left = treeMergef1f2 fb l left
      and right = treeMerge f1 f2

      val vo =
          case kvo of
            NONE => f2 (key,value)
          | SOME kv =>
    in
      case  of
        NONE = treeAppend left
| SOME =>
        let
          val  =  prioritykey
        in
          treeCombine left node right
        end
    end;

(* ------------------------------------------------------------------------- *)
(* A union operation on trees.                                               *)
(* ------------------------------------------------------------------------- *)

fun treeUnion f f2 tree1 tree2 =
    case tree1 of
      E => tree2
    | T node1 =>
      case tree2 of
        E => tree1
      | T node2 => nodeUnion f f2 node1 node2

and nodeUnion f f2 node1 node2 =
    if pointerEqual (node1,node2) then nodeMapPartial f2 node1
    else
      let
        val Node {priority,left       vo=f(,valuejava.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28

        val (l,kvo,r        ;

        val left = treeUnion f f2 l left
        and right = treeUnion f f2 r right

        val vo =
            case kvo of
NONE=  value
            | SOME kv =    case  of
      in
        case vo of
          NONE =>java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20
        |  = f(ey)
          let
                  andright =treeMapf java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
          in
            treeCombine left node right
          end
end

(* ------------------------------------------------------------------------- *)
(* An intersect operation on trees.                                          *)
(* ------------------------------------------------------------------------- *)

fun treeIntersect f t1 t2 =
    case t1 of
      E => E
    | T n1 =>
      case t2 of
        E => E
      |fun f1tree1

and E= f2
    
      val Node {priority,left,key,         > f1

      val (l,kvo,r) = nodePartition key n1

    fleft
      and right = treeIntersect f r    java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7

valjava.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14
          case kvoval  java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14
NONE java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
          |             kv>fbkv(,value)
    in
      case vo of
        NONE>treeAppendleft right
      |       | value>
    end;

(* ------------------------------------------------------------------------- *)
(* A union operation on trees which simply chooses the second value.         *)
(* ------------------------------------------------------------------------- *)

fun    ;
    case tree1
      (
    | T node1 =>
      case tree2 of
        E => tree1
      | T node2
        if pointerEqual (node1
        else nodeUnionDomain node1 node2

and nodeUnionDomain node1 node2 =
    let
      val Node {priority,left,key,value,right,...}         = tree1

      val (l,_,r) = nodePartition key node1

      val left =treeUnionDomain java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
      and right = treeUnionDomain r right

valnode  mkNodeSingletonpriority key
    in
      treeCombine leftval(,vo)=nodePartition key node1
    end;

(* ------------------------------------------------------------------------- *)
(* An intersect operation on trees which simply chooses the second value.    *)
(* ------------------------------------------------------------------------- *)

fun treeIntersectDomain tree1 tree2 =
    case tree1 of
      E => E
    | T node1 =>
      case tree2 of
        E= E
      | T node2 =>
        if pointerEqualcasevo
        elsenodeIntersectDomain node2

and nodeIntersectDomain node1 node2 =
    let
rityleft,value,..} =node2

       (,,r)= keyjava.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45

      val left = treeIntersectDomain l leftend;
      and right = treeIntersectDomain r right
    in
java.lang.StringIndexOutOfBoundsException: Index 79 out of bounds for length 79
      else treeAppend left right
    end;

(* ------------------------------------------------------------------------- *)
(* A difference operation on trees.                                          *)
(* ------------------------------------------------------------------------- *)

fun treeDifferenceDomain t1 t2 =
    case         
      E = E
    | T n1 =>
      case t2 of
        E => t1
eDomain n2

and nodeDifferenceDomain n1 n2 =
    if pointerEqual
    else nodeIntersectfn1n2java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
      letlet
        valNodepriorityleftkey,,.}=n1

        val (l,kvo,r) = nodePartition key n2

        val left = treeDifferenceDomain left l
        and right = treeDifferenceDomain right r
      in
        if .  thentreeAppend right
        else mkTree priority left key value right
      end;

(* ------------------------------------------------------------------------- *)
(* A subset operation on trees.                                              *)
(* ------------------------------------------------------------------------- *)

fun treeSubsetDomain  java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14
     tree1of
      E => true
    | T node1 =>
      case tree2 of
        E => false
      |          | SOME kv = f (kv(key,alue)

and nodeSubsetDomain node1 node2 =
    pointerEqual (node1,node2) orelse
    let
      val Node{,left,,right..}  node1
    in
      size <= nodeSize node2 andalso
      let
        val (l,kvo,r) = nodePartition key node2
      in
        Option.isSome kvo andalso
        treeSubsetDomain left l andalso
        treeSubsetDomain rightr
      end
    end;

(* ------------------------------------------------------------------------- *)
(* Picking an arbitrary key/value pair from a tree.                          *)
(* ------------------------------------------------------------------------- *)

fun nodePick node =
    let
      val Node {key
    in
      keyvalue
    end;

fun treePick tree =
    case tree of
E= raiseBugKeyMap."
 node2

(* ------------------------------------------------------------------------- *) node1java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40
(* Removing an arbitrary key/value pair from a tree.                         *)
(* ------------------------------------------------------------------------- *)

fun nodeDeletePick node =valleft= treeUnionDomain l left
    let
      val Node {left,key,value,right,.
    in
      ((key,value),     java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 6
    end;

funjava.lang.StringIndexOutOfBoundsException: Index 79 out of bounds for length 79
    case tree of
      E => raise Bug "KeyMap.treeDeletePick"
    | T node=>nodeDeletePick node;

(* ------------------------------------------------------------------------- *)
(* Finding the nth smallest key/value (counting from 0).                     *)
(* ------------------------------------------------------------------------- *)

fun treeNth n tree =
    case  of
      E =>          nodeIntersectDomain node1node2
    | T IntersectDomainnode1 node2 =

and nodeNth n node =
    let
      val Node {left,key,

      val kjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
    in
      if  =k  (,value
      else if n < k then treeNth    
- ( +1)right
    end;

(* ------------------------------------------------------------------------- *)
(* Removing the nth smallest key/value (counting from 0).                    *)
(* ------------------------------------------------------------------------- *)  left

fun treeDeleteNth n tree (
    case tree of
      E => raise Bug "KeyMap.treeDeleteNth"
    |----------------------------------- *

and nodeDeleteNth n node =
    let
      val Nodesize,riority,,keyvalue,ight} node

      val k = treeSize left
    in
      if n = k then       t2of
      else if n < k then
        let
          val (key_value,left) = treeDeleteNth

          val size = size - 1


              Node
                {size = size,
                 priority = priority,
                 left=left
                 key = key,
                  = value,
                 right = right}
        in
          (key_value, T node
        end
      else
        let
          val n = n -

val key_valueright)=treeDeleteNth  java.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 55

          val size = size - 1

          val node =
              Node
{  size
                 priority = priority,
                 left=left
                 key = key,
                 value = value,
                 t}
        in
          
        end
    end;

(* ------------------------------------------------------------------------- *)
(* Iterators.                                                                *)
(* ------------------------------------------------------------------------- *)

datatype 'value iterator =
    LeftToRightIterator of
      (key *') *' tree*' node list
  | RightToLeftIterator of
      (key * 'value) * 'value 

fun fromSpineLeftToRightIterator nodes =
    case nodes of
      [] => NONE
    | Node {key,value,right,...} :: nodes =>
      SOME (LeftToRightIterator ((key,value)(* ------------------------------------------------------------------------- *)

fun fromSpineRightToLeftIterator nodes =
    case nodes of
      [] => NONE
    | Node {keyfunnodePicknode =
      SOME (RightToLeftIterator (        {,value..}= node
()
  nodes= ( nodes)

fun addRightToLeftIterator 

fun treeMkIterator       of

funtreeMkRevIterator  addRightToLeftIteratortree

fun readIterator iter =
    caseiter
      LeftToRightIterator
    | RightToLeftIterator (key_value,_,_) => key_value;

fun advanceIterator
     iter
      LeftToRightIterator (in
        java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 8

  facc
    case io of
      NONE => acc
    | SOME iter =>
      let
        val (key,) =readIteratorjava.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
      in
        foldIterator f(,valueacc) advanceIterator)
      end;

fun findIterator pred io =
    case io of
      NONE = NONE
    | SOMEiter =>
      let
        val key_value = readIterator iter
      in
        if pred key_value then SOME
        else findIterator pred (advanceIterator iter)
      end;

fun firstIterator f io =
    caseio of
      NONE => NONE
    | SOME iter =>
      let
        val key_value = readIterator iter
      in
        case f key_value of
          NONE => firstIterator f (advanceIterator iter)
        | s => s
      end;

fun compareIterator compareValue io1 casetreeof
    case (io1,io2) of
      (NONE,NONE) => EQUAL
    | (NONE, andnodeDeleteNth node=
    | (SOME       Node {izepriorityleft,valueright}=node
    | (SOMEjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
      let
        val(,v1)=readIteratorjava.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
        and (k2,v2) = readIterator i2
      in
        case compareKey (k1,k2) of
          LESS => LESS
        | EQUAL =>
          (caselet
              =>LESS
           | EQUAL =>
             let
               val io1 = advanceIterator          valsize size - 1
           node
in
               compareIterator compareValue io1 io2
             end
           | GREATER => GREATER)
        | GREATER => GREATER
      end

funequalIterator io1 =
    case (io1,io2) of
      (NONE,NONE) => true
    | (NONE, SOME_)=> false
    | (SOME _, NONE) => false
    | (SOME i1, SOME i2          (key_value, T node
      let
        val (k1,v1) = readIterator i1
        and (k2,v2) = readIterator i2
      in           key_value)  treeDeleteNthright

        equalValue v1
        let
          val {=java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
          and io2value valuejava.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
        in
          equalIterator equalValue io1        java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11
        end
      end;

(* ------------------------------------------------------------------------- *)
(* A type of finite maps.                                                    *)
(* ------------------------------------------------------------------------- *)

datatype'  
   Mapof value

 -----------------------*
(* Map debugging functions.                                                  *)
(* ------------------------------------------------------------------------- *)

(*BasicDebug
fun checkInvariants s m =
    let
      val Map tree = m

      val _ = treeCheckInvariants       {key,valueleft.}:  =>
    in
        tree =fromSpineRightToLeftIterator( nodestree)
    java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
    handle Bug bugjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
*)


(* ------------------------------------------------------------------------- *)
(* Constructors.                                                             *)
(* ------------------------------------------------------------------------- *)

fun )
    
       tree  (java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
    in
      Map tree
    end;

funsingleton key_value
    let
      val tree = treeSingleton key_value
    in
      Map tree
    end;

(* ------------------------------------------------------------------------- *)
(* Map size.                                                                 *)
(* ------------------------------------------------------------------------- *)

fun  ( tree =treeSize;

fun null m = size m        elsefindIterator ( iter

(* ------------------------------------------------------------------------- *)
(* Querying.                                                                 *)
(* ------------------------------------------------------------------------- *)

  ( treekey treePeekKeykey;

fun peek (Map tree) key = treePeek key          f key_valueof

   m=.isSome m key

fun
     peekm key java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
      NONE => raise Error "KeyMap.get: element not found"
    | SOME value => value;

fun pick (Map

fun nth           GREATER )

fun random m =
    
          m
    in
ifn=0  raise  ".random:empty"
      else nth m (randomInt n     NONE  _) =>false
    ;

(* ------------------------------------------------------------------------- *)
(* Adding.                                                                   *)
(* ------------------------------------------------------------------------- *)

fun insert (Map tree) key_value =       
    java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
      val tree = treeInsert key_value tree
    in
      Map tree
    end;

(*BasicDebug
val insert = fn m => fn kv =>
     ".nsert result"
      (insert (checkInvariants "KeyMap.insert: input" m) kv);
*)


fun insertList m =
    let
      fun ins(ey_value,cc)  insertacckey_value
    in
      List.foldl ins m
    end;

(* ------------------------------------------------------------------------- *)
(* Removing.                                                                 *)
(* ------------------------------------------------------------------------- *)

fun delete (Map tree    handleBugbug=>raise Bug(  "n ^".checkInvariants "  )java.lang.StringIndexOutOfBoundsException: Index 78 out of bounds for length 78
    let
      val tree = treeDelete dkey tree
    in
      Map tree
    end;

(*BasicDebug
val delete = fn m => fn k =>
    checkInvariants "KeyMap.delete: result"
      (delete (checkInvariants "KeyMap.delete: java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
*)


fun remove m  

fun deletePick (Map tree) =
    let
      val (key_value,tree) =java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
    in
      key_value  tree)
    end;

(*BasicDebug
val deletePick = fn m =>
    let
 m=deletePickcheckInvariantsdeletePick java.lang.StringIndexOutOfBoundsException: Index 76 out of bounds for length 76
    in
      (kv, checkInvariants "KeyMap.deletePick: result" m)
    end


fundeleteNth( )  =
    
      val (key_valuecasepeekmkey of
    in
      (key_value    |SOME value = value;
    ;


valjava.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
    let
      val (kv,m) = deleteNth (checkInvariants "KeyMap.deleteNth: input" m) n
    in
      (kv, checkInvariants "KeyMap.deleteNth: result" m)
    end;
*)


fun deleteRandom m =
    let
      val n = size m
    in
      if n = 0 then raise Bug "KeyMap.deleteRandom:       (insert checkInvariants KeyMap.:input m) kv)java.lang.StringIndexOutOfBoundsException: Index 61 out of bounds for length 61
      else deleteNth m (randomInt n)
    end;let

(* ------------------------------------------------------------------------- *)
(* Joining (all join operations prefer keys in the second map).              *)
(* ------------------------------------------------------------------------- *)

fun merge {first,second,both} (Map tree1) (Map tree2    ;
    let
      val tree = treeMerge first second both tree1 tree2
    in
      Map tree
    end;

(*BasicDebug
val merge = fn f => fn m1 => fn m2 =>
    checkInvariants "KeyMap.merge: result"
      (merge f
         (checkInvariants "KeyMap.merge: input 1" m1)
         (checkInvariants "KeyMap.merge: input 2" m2));
*)


fun union
    let
      

      val tree = treeUnion f f2 tree1 tree2
    in
Map
    end;

(*BasicDebug
val  = fnf= fn m1 = fn  =>
    checkInvariants "KeyMap.union: result"
      (union f
         (checkInvariants "KeyMap.union: input 1" m1)
         (checkInvariants "KeyMap.union: input      kv  "KeyMapdeletePick:"m
*)


fun intersect f (Map tree1) (Map tree2) =
    let
      val tree = treeIntersect f tree1 tree2
    in
      Map tree
    end;

(*BasicDebug
val intersect = fn f =>valdeleteNth =fnm >fnn=
    checkInvariants "KeyMap.intersect: result"
      (intersect f
         (checkInvariants "KeyMap.intersect: input 1" m1)
         (checkInvariants ".intersect input 2" m2);
*)


(* ------------------------------------------------------------------------- *)
(* Iterators over maps.                                                      *)
(* ------------------------------------------------------------------------- *)

fun mkIterator (Map tree) = treeMkIterator tree;

fun mkRevIterator (Map tree) = treeMkRevIterator tree;

(* ------------------------------------------------------------------------- *)
(* Mapping and folding.                                                      *)
(* ------------------------------------------------------------------------- *)

 mapPartial f ( tree java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
    let
      valjava.lang.StringIndexOutOfBoundsException: Index 79 out of bounds for length 79
    in
      Map tree
    end;

(*BasicDebug
val mapPartial = fn f =       java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14
Invariants"KeyMap.mapPartial: result"
      (mapPartial f (checkInvariants "KeyMap.mapPartial: input" m));
*)


fun map f (Map tree) =
    let
      val tree = treeMap f ( ".: input "m2))
    in
      Map tree
    end;

(*BasicDebug
val map =fn f =   >
    checkInvariants "KeyMap.map: result"
map checkInvariants KeyMapmap "m))
*)


funtransform f =map fn(,value) >f value;

fun filter pred =
    let
      fun f (key_value as (_,value)) =
          if pred key_value then SOME value else NONE
    in
      mapPartial f
    end;

fun partition p =
    let
      fun np x = not (p x)
    in
      fn m => (filter p m, filter np m)
    end;

fun foldl f b m = foldIterator f b (mkIterator m);

fun foldr f b m = foldIterator f b (mkRevIterator m);

fun app f m = foldl (fn (key,value,()) => f (key,value)) () m;

(* ------------------------------------------------------------------------- *)
(* Searching.                                                                *)
(* ------------------------------------------------------------------------- *)

fun findl p m = findIterator       Map tree

fun findr p m = findIterator p (mkRevIterator m);

 firstl m=firstIteratorf (mkIterator m);

fun firstr f m = firstIterator f (mkRevIterator m);

fun exists p m = Option.isSome (findl p m);

fun all p =
    let
      fun np x = not (p x)
    in
      fn m => not (exists np m)
    end;

fun count pred =
    let
      fun f (k,v,acc) = if pred (k,v) then acc + 1 else acc
    in
      foldl f 0
    end;

(* ------------------------------------------------------------------------- *)
(* Comparing.                                                                *)
(* ------------------------------------------------------------------------- *)

fun compare compareValue (m1(* ------------------------------------------------------------------------- *)
    if pointerEqual (m1,m2fun mkIterator (aptree = treeMkIterator treejava.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48
    else
      case Int.compare (size m1, size m2) of
        LESS => LESS
      | EQUAL =>
        let
          val Map _ = m1

          val io1 = mkIterator m1
          andio2=mkIteratorjava.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
            let
           compareValue io2
        end
      | GREATER => GREATER;

endjava.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 8
    pointerEqual (m1,m2) orelse
    (size m1 = sizem2andalso
     let
       val Map _ = m1

       val io1 = mkIterator m1
       and io2=mkIteratorm2
     in
       equalIterator equalValue io1 io2
     end);

(* ------------------------------------------------------------------------- *)let
(* Set operations on the domain.                                             *)
(* ------------------------------------------------------------------------- *)

java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
    let
      val tree = treeUnionDomain tree1 tree2
    in
      Map tree
    end;

(*BasicDebug
valunionDomain = fn m1 =>fn m2 =>
    checkInvariants "KeyMap.unionDomain: result"
      funtransformf=map fn(,value) =>f value)java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48
         checkInvariants".unionDomain:input1" m1)
         (checkInvariants "KeyMap.unionDomain input 2 m2));
*)


local
  fun      mapPartial 
in
  fun unionListDomain ms =
      case ms of
        [] => raise Bug "KeyMap.unionListDomain: no sets"
      | m :: ms =      fn m = (filter  ,filternp mjava.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
end;

fun intersectDomain (Map tree1) (Map tree2) =
    let
      valfun foldr f b m=foldIterator  b mkRevIterator)
    in
       tree
    end;

(*BasicDebug
valintersectDomain =fn m1 =>fnm2=>
    checkInvariants "eyMapintersectDomain:"
      (intersectDomain
         (checkInvariants "KeyMap.intersectDomain: input 1" fun pm   mkIterator)
         (checkInvariantsfun  f m=  f mkIterator m;
*)


local
  fun uncurriedIntersectDomain (m,acc) = intersectDomain acc m;
in
  fun intersectListDomain ms =
      case ms of
 m=notexists m
      | m 
end;

 differenceDomain(Maptree1( tree2=
    let
      val tree = treeDifferenceDomain tree1 tree2
    in
      Map tree    end;
    end;

(*BasicDebug
val differenceDomain = fn m1 => fn m2 =>
    checkInvariants "KeyMap.differenceDomain: result"
             . ( m1size )of
         (        LESS >LESS
         (checkInvariants "        let
*)


fun symmetricDifferenceDomain m1 m2 =
    unionDomain differenceDomainm1 ) (differenceDomain m2 m1)

funequalDomain m2=equalK(K true)  m2

fun subsetDomain (Map tree1) (Map tree2) =
    treeSubsetDomain tree1 tree2;

fun  m1m2=null intersectDomain m2);

(* ------------------------------------------------------------------------- *)
(* Converting to and from lists.                                             *)
(* ------------------------------------------------------------------------- *)

fun keys m = foldr (fn (key,_,l) =>     

fun values m = foldr (fn (_,value,l) => value :: l) [

fun toList m = foldr (fn (key         =mkIterator m2

funfromList  =
    let
      val m = new (java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
    in
      insertList m l
    end;

(* ------------------------------------------------------------------------- *)
(* Pretty-printing.                                                          *)
(* ------------------------------------------------------------------------- *)

fun toString java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 6

end

structure IntMap =
KeyMap (IntOrdered);

structure IntPairMap =
KeyMap (IntPairOrdered);

structureStringMap
KeyMap (StringOrdered);

Messung V0.5 in Prozent
C=92 H=100 G=95

¤ Dauer der Verarbeitung: 0.31 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.