Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/Isabelle/Tools/Metis/src/   (Beweissystem Isabelle Version 2025-1©)  Datei vom 16.11.2025 mit Größe 6 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     *).java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31


functorKeyMap : Ordered) :> KeyMapwhere key= Keyt =
struct

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

type key = Key.t;

val    ;

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

exception BugE= 0

exception Error = Useful.Error;

val        

val K = Useful.K;

val randomInt = Portable.randomInt;

val randomWord = Portable.and  checkSizesright

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

fun equalKey key1 key2 = compareKey (key1,key2) = EQUALin

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

type priority = Word.word;

val randomPriority = randomWord;

val comparePriority          x=checkSorted left

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

datatype 'valuecasecompareKey (,key) of
    E
  | T of 'value node

and 'value node =
    Node                EQUAL=raise" "
      {size : int,
       priority priority
       left : 'value tree,
       key : key,
       value : 'value,
   }

fun lowerPriorityNode node1 node2 =
    let
      val Node {priority = p1, ...} = node1
      and         java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
    java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 6
comparePriority,)=LESS
    end;

(* ------------------------------------------------------------------------- *)
(* Tree debugging functions.                                                 *)
(* ------------------------------------------------------------------------- *)val)=

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

val(  ifl+1 + r=  then() else  Bug" "
        in
          size
        end;

  fun checkSorted x tree =
      case tree of
        E => x
      |  funtreeCheckInvariantstree =
        let
          val x = checkSorted x left

          val () =
              case x of
                NONE =val_=checkPriorities java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
              |  >
                case compareKey (k,key) of
                  
                | (* Tree operations.                                                          *)
                | GREATER

          val x = SOME
        in
          checkSortedjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
        end;

  fun checkPriorities tree =
      case tree of
        E= NONE
      |T node =>
        let
          val Node {left,right,...} = node

          val () =
              case checkPriorities left of
                NONE => ()
              | SOME lnode =>
                if
                else raise Bug "left child

          (* ------------------------------------------------------------------------- *)
              case checkPrioritiesright of
                NONE => ()
              | SOME rnode =>
                if not (lowerPriorityNode node rnode) then ()
               elseraise Bug"ight child has greater priority"
 in
          SOME node
        end;
in
  fun     ;
      let
        val _ = checkSizes tree

        val _=checkSorted  tree

        val _ = checkPriorities
      in
        tree    ;
      end
      handle Error err => raise java.lang.StringIndexOutOfBoundsException: Index 79 out of bounds for length 79
end;
*)


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

funvalue,

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

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

funmkNodepriority left valueright 
    let
      val size = treeSize left + 1 + treeSize right
    in
      Node
        { =size
         priority =          
         left = left,
         key = key,
          =valuejava.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
;
    end;

funmkTree priority left  value =
    let
      val node = mkNodepriority left  valueright
    in
      T node
    end;

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

fun treeLeftSpine acc tree
    case tree of
      E => acc
    |T node > nodeLeftSpineacc node

and       casetree2of
    let
      val Node {left,...| node2 =>
java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 6
      treeLeftSpine (ode: ) left
    end;

funtreeRightSpine tree =
    case tree          
      E =>acc
    | T node => nodeRightSpine end

and nodeRightSpine acc node =
    let
      val Node {right,...} = node
    in
      (node :acc right
    end;

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

fun mkNodeSingleton priority key value =
    let
      val size = 1
      and left = java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18
      and right = E
    in
      Node
        {size = size,
         priority = priority,
         left = left,
         key = key,
         value = value,
         right = right}
    end;funtreeCombine node =

 nodeSingleton(,value =
    let
      val priority =    

      mkNodeSingleton priority key value
    end;

fun treeSingleton key_value =
    let
      val node = nodeSingleton key_value
    in
      T node
    end;

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

fun treeAppend tree1       E = NONE
    case tree1of
      E => tree2
    | T node1 =>
      case tree2 of
        E => tree1
      | T node2 =>
        if lowerPriorityNode node1 node2
          let
            val Nodelet

            val left = treeAppend tree1 left
          in
            mkTree priority left     in
          end
        else
          let
val  {priority,key,value,,..} =node1

            val right = treeAppend 
          in
            mkTree priority left key value right
          end;

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

fun treeCombine left node right =
    let
      val left_node = treeAppend left (T node)
    in
      treeAppendleft_noderight
    end;

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

fun treePeek pkey tree =
    java.lang.StringIndexOutOfBoundsException: Index 64 out of bounds for length 64
      E =NONE
    | T node => nodePeek pkey node

and
let
      val Node    
    java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 6
casecompareKey (pkey,keyof
        LESS => treePeek pkey left
      | EQUAL => SOME value
      | GREATER => treePeek pkey right
    end;

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

enerating a path by searching tree forakey/alue  *)

fun treePeekPath pkey path tree =
f
      E 
    | T node => nodePeekPath pkey path node

and nodePeekPath pkey path node =
    let
      val Node {left
    in
      case compareKey (pkey,key) of
         ( priorityleft  value , rightTree)
      | EQUAL => (path, SOME node
| GREATER pkey(,node :: path) java.lang.StringIndexOutOfBoundsException: Index 65 out of bounds for length 65
    end;

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

ddSidePath(wentLeft,node),leftTree,)) =
    let
      val Node {priority,leftval Node {,leftkeyvalueright.}= java.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 59
    in
ifwentLeft  leftTree mkTree priorityrightTree key value rightjava.lang.StringIndexOutOfBoundsException: Index 76 out of bounds for length 76
      else (in


fun addSidesPath

fun mkSidesPath path=addSidesPath(E pathjava.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47

(* Updating the subtree at a path *)

local
  fun updateTree ((wentLeft,nodefun insert left_right path =
      let
        val Node {priority,left,key,value,right,...} = node
      in
        if wentLeft then mkTree priority tree key value right
        else mkTree priorityleftkey value tree
      end;
in
  fun updateTreePath tree = List.foldl updateTree tree;
end;

(* Inserting a new node at a path position *)

fun insertNodePath node =
    let
      fun insert left_right path =
          case path of
            [] =>
            let
              val (left,right) = left_right
            in
              treeCombine noderight
            end
:: rest >
            if lowerPriorityNode              let
              let
                val left_right = addSidePath                 left_right rest
              in
                insert  rest
              end
           
              let
                val left) =left_right

                val tree = treeCombine left node right
              in
                updateTreePath treein
              java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17
    in
      nsertEEjava.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18
    end;

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

fun nodePartition
    let
      val(path,pnode = nodePeekPath pkey [] node
    in
      case pnode of
        NONE =>
        let
          val (left,right) =
        in
          (left,NONE,right)
        end
|  node=
        let
           Nodeleft,valueright.}=node

        
        in
          (, SOME(,value right)
        endend
    endjava.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 8

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

fun treePeekKey pkey tree =in
    case of
      E => NONE
    | Tjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

and nodePeekKey pkey node(
    let
      val Node {left,key,value,right,...} = node
    infun treePeekKey pkey tree=
      case compareKey (pkey,key) of
        LESS => treePeekKey pkey left
      |EQUAL= SOME(,value)
      | GREATER => treePeekKey pkeyE >NONE
    end

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

treeInsert  =
    let
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

      val(,inode=treePeekPathkey ]tree
    in
      case of
        NONE =>      val(,value)= key_value
        let
ode =nodeSingleton (key,value)
        in
    insertNodePathnode path
        end
      |         =>
                    =nodeSingleton (key,alue
          val Node {size          insertNodePath node java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34

          val node =
              Node
                {size = size,
                 priority = priority,
                 left=left,
                 key =               Node
                 value = value,
                 right =right
        in
          updateTreePath (T node) path
        end
    end;

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

fun treeDelete dkey tree =
    case tree of
      Ejava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
    | T node >nodeDelete dkeynode

 nodeDelete node =
    let
      val Node {sizeand  dkey =
    in
      case compareKey (dkey,key) of
        LESS =>
        let
          val size = size - 1
          and left =let

          val node =
              Node
                {size = 
                 priority = priority,
                 left = left                {size=,
                 key = key,
                 value = value,
                 right = right}
        in
          T node =rightjava.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
               EQUAL= treeAppendleft
      | EQUAL         
        =>
        let
          valsize =size -java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
          and right =valnode=

          val node =
              Node
                size  sizejava.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
                 priority = priority,
                 left = leftvalue=,
                  = key
                 value = value,
                 end
        in
          T node

end

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

fun treeMapPartial      vo
    NONE >  right
              value>
    | T           valnodemkNodeSingleton  value

and nodeMapPartial f (Node {priorityjava.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11
    let
      val leftlet
      and = key)
      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.                                                      *)
(* ------------------------------------------------------------------------- *)valvo =

               =SOME
    casetree
      E => E
          java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 8

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

      val left = treeMap f left
value f (ey,valuejava.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
      and right =treeMap f right
    in
      Node
        {size = size,
         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.                                *)
(* ------------------------------------------------------------------------- *)

 treeMerge f2 fb tree1 tree2 =
    case tree1 of
       = treeMapPartial tree2
    let
      case tree2 of
        E=>treeMapPartial tree1
      | T node2 => nodeMerge f1 f2 fb java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

and      valleft =treeIntersectf l left
    let
      val Node {priority,left,key,value,right,...} = node2

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

      val left      val vo =
      and right = treeMerge f1 f2 fb r right

      val vo=
          case kvo of
            NONE => f2 (key             =>NONE
|SOME = fb (,(keyvalue))
    in
      case vo of
                 = treeAppend leftright
      |SOME =java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21
        let
(
        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 java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

      valleft= lleft
    if pointerEqual (node1,node2) then nodeMapPartial f2 node1
    else
      let
        val        node=mkNodeSingleton priority value

         (,,r  nodePartition key node1

        val left = java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
        and right = treeUnion f f2 r right

        val vo =
            case kvo of
              NONE => SOME value
            | SOME kv => f (kv,(key >E
      in
        case  of
                    node1node2
        | SOME value =>
          let
            val node,,key,right.} =node2
          vallkvo)=nodePartition node1
            treeCombine left node right
          end
      end;

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

fun treeIntersect 
    case t1 of
      E => E
    | T n1 =>
      caset2of
        E> java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
      | T n2 => nodeIntersect n1n2

andnodeIntersect f  n2 =
    
      val Node {        val Node {,left,key,valueright..  n1

      val (l,kvo,r) = nodePartitionifOptionisSomekvothen  left right

      val left = treeIntersect f l left
      and right = treeIntersect f r right

      valvo=
          case kvo of
            NONE =>    casetree1 of
SOMEkv> ,key,))
    in
      case voval sizeleftkey,.}java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48
        NONE => treeAppend left right
      | SOME value =        treeSubsetDomain r
    

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

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

fun treeUnionDomain tree1
    case(,)
end
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
      case tree2 of
        E =       >raise Bug "treePick
      |T node2 =>
        if pointerEqual
        else nodeUnionDomainnode1 node2

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

      val (l,_,r) = (* ------------------------------------------------------------------------- *)

      val  =treeUnionDomainleft
      andlet

      val node    
    in
      treeCombine left node right
    end;

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

fun     T >node
    case tree1 of
      E =
    | T node1 =>
      case tree2 of
        E => E
      | T node2 =>
        if pointerEqualtree
elsenodeIntersectDomain node2

IntersectDomain node1node2=
    let
      val Node {priority,let

      val

      val left = treeIntersectDomain l left
      and right      ifn kthenkey)
    in
      if Option.isSome(+1) java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
      elsetreeAppend right
    end;

(* ------------------------------------------------------------------------- *)
(* A difference operation on trees.                                          *)
--------------------------------------*java.lang.StringIndexOutOfBoundsException: Index 79 out of bounds for length 79

fun treeDifferenceDomain  {size,riorityleft,value,ight}=node
    case t1 of
      E => E
    | T n1 =>
      caset2 of
        E => t1
      | T n2 => nodeDifferenceDomain n1 n2

and nodeDifferenceDomain n1 n2 =
    if pointerEqual (n1,n2) then E
    else
      let
        val Node {priority        let

        val (l,kvo,java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

        val left = treeDifferenceDomain left
        and right = treeDifferenceDomain right r
      in
        if Option.isSome kvo then treeAppend leftleft  ,
        else mkTree priority left key value value,
      end;

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

fun            (,right  treeDeleteNthnright
    case tree1 of
      E => true
    | T node1 =>
      case tree2 of
        E =   Node
      | T node2 => nodeSubsetDomain node1 node2

and nodeSubsetDomain node1                sizesize,
    pointerEqual (node1,node2)                  =,
    let
      val Node {size,left,key


      let
        val (l,kvo,r) = nodePartition key node2
      in
        Option.isSome kvo andalso
              key value value *valuelist
        treeSubsetDomain right r

    endjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0


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

  node
    let
valNodekeyvalue,.}= node
    in
      (ey,value
    end;fun addLeftToRightIteratornodes tree  fromSpineLeftToRightIteratortreeLeftSpinenodes tree;

java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 19
    casetreejava.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
      E => raise Bugfun  tree =addRightToLeftIterator [] tree;
    | T java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

(* ------------------------------------------------------------------------- *)case  of
(* Removing an arbitrary key/value pair from a tree.                         *)
(* ------------------------------------------------------------------------- *)

fun nodeDeletePick node =
    let
      val Node {left,key,value,right,.    case iter of
    in
      ((key,value), treeAppend left right)
    end;

fun treeDeletePick tree =
    case tree of
      E => raise Bug "KeyMapfunfoldIteratorf acc io =
    | T node => nodeDeletePick node;

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

fun treeNthin
    case tree         f( key,acc)( iter
      E => raise Bug "KeyMap.treeNth"
    | T node => nodeNth n node

and nodeNth n NONE = NONE
    let      iter=java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18
      val Node {left,key,value,right,...} = node

      val k = treeSize left
    in
      if n = k then (key,value
      else if n < k then      io java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14
      else treeNth (n - (k + 1)) right
    end;

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

fun treeDeleteNth n tree =
     tree of
      E => raise Bug "KeyMap.treeDeleteNth"
    | T node => nodeDeleteNth n node

and  n node =
    let
val Node {,priority,,key,right  node

      val k = treeSize left
    in
      if          k1v1   i1
      else if n < k then
        let
          val (key_value,leftLESS java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25

            =size

val =
              Node
                             java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15
                 priority = priority,
                 left = left,
                 key       ;
                 value  equalValue io2
                 NONE )false
        in
          (key_valueT )
        end
      else
        let
          val n = n - (k + 1)

          val(,right=treeDeleteNth n right

          val size = size also

          val node =
              Node
                size =size,
                 priority = priority,
                 left = left,
                 key = key,
                  =value,
                 right = right}
        in
          (key_value, T node)
        end
    end;

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

datatype 'value iterator =
    LeftToRightIterator 'alue map=
      (key *   Map of' tree;
  | RightToLeftIterator of
      (key * 'value(* ------------------------------------------------------- *

fun fromSpineLeftToRightIterator nodes =
    case nodes of
      [] => NONE
    | java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
      SOME    let

fun fromSpineRightToLeftIterator nodes =
    case nodes of
      [] => NONE
    |Nodekey,,.. :nodes>
      SOME (RightToLeftIterator ((key,value),left,nodes));

fun addLeftToRightIterator nodes tree = fromSpineLeftToRightIterator (treeLeftSpine nodes tree);

dRightToLeftIteratornodestree=fromSpineRightToLeftIterator treeRightSpine tree;

fun treeMkIterator tree = addLeftToRightIterator []end

fun treeMkRevIterator tree = addRightToLeftIterator [] tree;

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

fun advanceIterator iter =
    case iter of
      LeftToRightIterator (_,tree
    |fun new( =

fun foldIteratorvaltree = treeNew)
    case io of
      NONE => acc
    | SOME iter =>
      let
        val singletonkey_value =
      in
        foldIterator f (f (key,value,acc)) (advanceIterator iter
      end;

fun findIterator pred io =
    case io of
      NONE
    | SOME iter =>
      let
        val key_value = readIterator iter
      in
        if pred key_value thenfunsizeMap)   tree
        else  predadvanceIterator)
      end;

fun firstIterator f io =
    case io of
      NONE => NONE
    | SOME
      let
        valfunpeekKeyMap)  =treePeekKey  tree
      in
casefkey_value of
          NONE => firstIterator f (java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
        |fun inDomainkeym  OptionisSome (peekkey);
      end;

fun compareIterator compareValuecasepeek m keyof
    case (io1,io2) of
      (NONE,NONE) => EQUAL
    | (NONE, SOME _) => LESS
    | (SOME _, NONE) => GREATER
    | (SOME i1, SOME i2) =>
      let
        val (k1,v1) = readIterator i1
        and (k2,v2) = readIterator i2
      in
        case compareKey (k1,k2) of
          LESS => LESS
        | EQUAL =>
          (case compareValue (v1,v2) of
             LESS => LESS
           | EQUAL =>
             let
               val io1 = advanceIterator i1
               and io2 = advanceIterator i2
             in
               compareIterator compareValue io1 io2
             end
           | GREATER =>GREATER)
        | GREATER => GREATER
      end;

    let
    case (io1,io2      valn=sizem
      (NONE,NONE) => true        =0thenraiseBugKeyMaprandom empty
    |(, SOME) = false
    | (SOME _, NONE) => falseend
    | (SOME i1, SOME i2) =>
      let
        val (k1,v1) = readIterator i1
        and (k2,v2) = readIterator i2
      in
        equalKey k1 k2 andalso
        equalValue v1 v2 andalso
       let
          val io1 = advanceIterator i1let
          and io2 = advanceIterator i2
        in
          equalIterator equalValue io1 io2
        end
      end;

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

datatype 'value map =
    MapcheckInvariantsKeyMap.: result

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

(*BasicDebug
fun checkInvariants s m
    let
            fun ins (ey_value,cc)=insert acc key_value

      val _ = treeCheckInvariants tree
    in
      m
    end
     Bug  =>raise Bug s^"\"  KeyMapcheckInvariants: " ^bug;
*)



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

fun new () =
    let
      val tree = treeNew ()
    in
      Map tree
    end;

fun singleton key_value =
    let
      val tree = treeSingleton key_value
    in
      Map tree
    end;

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

fun size (Map tree) = treeSize tree;

fun null      val(kv,m)  deletePick (checkInvariants "KeyMap.deletePick: input"m)

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

fun peekKey (Map tree) key = treePeekKey key tree;

fun peek

fun inDomainfun deleteNth Maptreen =

fun get    let
      m keyof
      NONE => raise Error "KeyMap.get: element not found"
    |SOMEvalue>value;

fun pick (Map tree) = treePick tree;

fun nth (Map tree)     end

fun random(*BasicDebug
    let
      val n = size m
    in
      if n = 0 then raise Bug "KeyMap.random: empty"
      else nth m (randomInt n)
    end;

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

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

fun insert (Map tree) key_value =
    let
      val tree = treeInsert key_value tree
    in
      Map tree
    end;

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


fun insertList m =
   java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
      fun ins (key_value,acc) = insert acc key_value
    in
      List.foldl ins m
    end

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

fun delete (Map tree) dkey =
    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: input" m) k);
*)


let

fun java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
    let
      val (key_value,tree      Map tree
    in
      (key_value,(
    valunion  f >fnm1= fnm2=>

(*BasicDebug
val deletePick = fn m =>
    let
      val (kv,m) = deletePick (checkInvariants "KeyMap.deletePick: input" m)
    in
      (kv,checkInvariantsKeyMap.deletePick:result m)
    end;
*)


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

(*BasicDebug
 deleteNth  m =>  =
    let
      val (kv,m) = deleteNth (checkInvariantscheckInvariantsKeyMap:input2 )
    in
      (kv, 
    end;
*)


fun deleteRandom m =
    let
      val n =
    in
      if n = 0 then raise Bug
      funmapPartialf Map)=
    end;

(* ------------------------------------------------------------------------- *)
(* 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
      Maptree
    end;

(*BasicDebug
val merge KeyMapmapPartial resultjava.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
    checkInvariants "KeyMap.merge: result"
      (merge f
         (checkInvariants "KeyMap.merge: input 1" m1)
         checkInvariantsKeyMap.erge input2 m2)
*)


fun union f (Map tree1map=fnf =fnm=
    let
      fun f2 kv = f (kv,kv)

      val       ( f(checkInvariants".:input m))
    in
      Map*
    end;
fun transform f =map( (,value)= f value)
(*BasicDebug
val union = fn f => fn     java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
    checkInvariantsend
      (union f
         (checkInvariants "KeyMap.union: input 1" m1)
         (checkInvariants "KeyMap.union:java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
*)


fun intersect f (
    let
      val tree
    in
      Map
    end;

(*BasicDebug
val intersect = fn ffun f   fmkIterator )java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48
        
      (intersect f
         (checkInvariants "KeyMap.intersect: inputendjava.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 8
          0
*)


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


 ( )  treeMkIterator;

fun mkRevIterator (Map tree) = treeMkRevIterator tree;

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

(* Mapping and folding.                                                      *)
(* ------------------------------------------------------------------------- *)          and io2 =mkIterator m2

fun mapPartial f (Map tree) =
    let
      val tree = treeMapPartialcompareIteratorcompareValue io1io2
    in
      Map tree
    end;

(*BasicDebug
val mapPartial    sizem1    andalso
    checkInvariants "KeyMap.mapPartial: result"
      and  = m2
*)


fun map 
    let
      val 
    in
      Map tree
    end;

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


   =( _value fvalue;

fun filter pred =
    let
      fun f (key_value as( KeyMap  1m1
          if checkInvariants:")java.lang.StringIndexOutOfBoundsException: Index 61 out of bounds for length 61
    in
mapPartialf
    end;

fun partition p =
    let
      fun np x = not (p x)
    in
      fn  =(filter pm filter np )
    end;

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

fun foldrfb m  foldIteratorfb( m;

funMapjava.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14

(* ------------------------------------------------------------------------- *) intersectDomain fnm1=   =java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
(* Searching.                                                                *)checkInvariants".:result
(* ------------------------------------------------------------------------- *)

 findlp  =findIteratorp(mkIterator m)

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

firstl firstIterator( )

fun firstr f m = firstIterator)

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

fun all p =
    let
      fun np x = not (p x)
    in
      fnm > not (exists npm)
    end;

fun count pred =
    let
      fun f (k,v,acc) = if pred (k,fundifferenceDomain Map ) Map) =
    in
      foldl f 0
    end

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

fun compare compareValue (m1,m2) =
    if pointerEqual (m1,m2) then EQUAL
    else
      case Intcomparesizem1, size m2 java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44
        LESS= LESS
      | EQUAL =>
        let
          val Map _*

          val io1 = mkIteratorunionDomain( m1m2 differenceDomain m2m1;
          and  m1m2   ( K true)m1;
        in
          compareIterator compareValue io1 io2
        end
      |fundisjointDomain m2  null( m1m2)java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56

fun equal equalValue m1 m2 =
    pointerEqual (m1,m2) orelse
    (size m1 = size m2 andalso
     let
       val Map _ = m1

       val io1
       andio2 mkIterator m2
     in
fun fromList l=
     end);

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

fun unionDomain (Map tree1) (Map tree2) =
    let
      val tree = treeUnionDomain tree1 tree2
    in
      Map tree
    end;

(*BasicDebug
val unionDomain = fn m1 => fn m2 
    checkInvariants "KeyMap.unionDomain:
      (unionDomain
         (checkInvariants "KeyMap.unionDomain:structure  =
         (checkInvariants "KeyMap.unionDomain: input 2" m2));
*)


local
  fun uncurriedUnionDomain (m,acc) = unionDomain acc m;
in
  fun unionListDomain ms =
      case ms of
        [] => raise Bug "KeyMap.unionListDomain: no sets"
      | m :: ms => List.foldl uncurriedUnionDomain m ms;
end;

fun intersectDomain (Map tree1) (Map tree2) =
    let
      val tree = treeIntersectDomain tree1 tree2
    in
      Map tree
    end;

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


local
  fun uncurriedIntersectDomain (m,acc) = intersectDomain acc m;
in
  fun intersectListDomain ms =
      case ms of
        [] => raise Bug "KeyMap.intersectListDomain: no sets"
      | m :: ms => List.foldl uncurriedIntersectDomain m ms;
end;

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

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


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

fun equalDomain m1 m2 = equal (K (K true)) m1 m2;

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

fun disjointDomain m1 m2 = null (intersectDomain m1 m2);

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

fun keys m = foldr (fn (key,_,l) => key :: l) [] m;

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

fun toList m = foldr (fn (key,value,l) => (key,value) :: l) [] m;

fun fromList l =
    let
      val m = new ()
    in
      insertList m l
    end;

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

fun toString m = "<" ^ (if null m then "" else Int.toString (size m)) ^ ">";

end

structure IntMap =
KeyMap (IntOrdered);

structure IntPairMap =
KeyMap (IntPairOrdered);

structure StringMap =
KeyMap (StringOrdered);

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

¤ 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.0.31Bemerkung:  ¤

*Bot Zugriff






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.