(* ========================================================================= *) (* 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. *) (* ------------------------------------------------------------------------- *)
(* ------------------------------------------------------------------------- *) (* Converting a comparison function to an equality function. *) (* ------------------------------------------------------------------------- *)
fun equalKey key1 key2 = compareKey (key1,key2) = EQUAL;
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 funcheckSizestree= casetreeof >0 let valljava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 r=checkSizesright
val()=ifl+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 casetreeof E=>x |T(Node{left,key,right( let valx=checkSortedxleft
val()= casecheckPrioritiesrightof NONE=>() |SOMErnode=> )=if1size)elseraiseBugwrongsize elseraiseBug"rightchildhasgreaterpriority" in SOMEnode end; in funtreeCheckInvariantstree= let val_=checkSizestree
val_java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
_checkPrioritiestree in tree end handleErrorerr=>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> valsize = 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
fun mkNodeSingleton priority key value = let valsize = 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 inval(,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 valsize |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;
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
valend;
val left = treeMergef1f2 fb l left and right = treeMerge f1 f2
val vo = case kvo of
NONE => f2 (key,value)
| SOME kv => in caseof
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 = caseof 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 = caseof
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 elseif 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 elseif n < k then let val (key_value,left) = treeDeleteNth
valsize = 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
valsize = size - 1
val node =
Node
{ size
priority = priority,
left=left
key = key,
value = value,
t} in
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 valsizesize - 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. *) (* ------------------------------------------------------------------------- *)
(*BasicDebug funcheckInvariantssm= let valMaptree=m
val_=treeCheckInvariants{key,valueleft.}:=> in tree=fromSpineRightToLeftIterator(nodestree) java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7 handleBugbugjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
*)
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=0raise".random:empty" else nth m (randomInt n NONE _) =>false
;
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;
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 valdelete=fnm=>fnk=> 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 valdeletePick=fnm=> let m=deletePickcheckInvariantsdeletePickjava.lang.StringIndexOutOfBoundsException: Index 76 out of bounds for length 76 in (kv,checkInvariants"KeyMap.deletePick:result"m) end
fundeleteNth()= val(key_valuecasepeekmkeyof in (key_value|SOMEvalue=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 = 0thenraise 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;
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 valmapPartial=fnf=java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14 Invariants"KeyMap.mapPartial:result" (mapPartialf(checkInvariants"KeyMap.mapPartial:input"m));
*)
funmap f (Map tree) = let val tree = treeMap f ( ".: input "m2)) in Map tree end;
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 valMap _ = 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 valMap _ = 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=fnm1=>fnm2=> checkInvariants"KeyMap.unionDomain:result" funtransformf=mapfn(,value)=>fvalue)java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48 checkInvariants".unionDomain:input1"m1) (checkInvariants"KeyMap.unionDomaininput2m2));
*)
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;
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;
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.