(* ========================================================================= *) (* 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. *) (* ------------------------------------------------------------------------- *)
(* ------------------------------------------------------------------------- *) (* Converting a comparison function to an equality function. *) (* ------------------------------------------------------------------------- *)
fun equalKey key1 key2 = compareKey (key1,key2) = EQUALin
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;
(*BasicDebug local funcheckSizestree= casetreeof E=>0 Buggreaterpriority let valjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 andr=checkSizesright
val(ifl+1+r=then()elseBug"" in size end;
funcheckSortedxtree= casetreeof E=>x |funtreeCheckInvariantstree= let valx=checkSortedxleft
val()= casexof NONE=val_=checkPrioritiesjava.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36 |> casecompareKey(k,key)of |(* Tree operations. *) |GREATER
valx=SOME in checkSortedjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 end;
funcheckPrioritiestree= casetreeof E=NONE |Tnode=> let valNode{left,right,...}=node
val()= casecheckPrioritiesleftof NONE=>() |SOMElnode=> if elseraiseBug"leftchild
(* ------------------------------------------------------------------------- *) casecheckPrioritiesrightof NONE=>() |SOMErnode=> ifnot(lowerPriorityNodenodernode)then() elseraiseBug"ightchildhasgreaterpriority" in SOMEnode end; in fun; let val_=checkSizestree
val_=checkSortedtree
val_=checkPriorities in tree; end handleErrorerr=>raisejava.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 valsize = 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
andcasetree2of 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;
fun mkNodeSingleton priority key value = let valsize = 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 caseof
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 caseof
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 valsize = 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 sizesizejava.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
=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
andvalleft =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 caseof
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 caset1of E=>E |Tn1=> caset2of E>java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12 |Tn2=>nodeIntersectn1n2
valvo= casekvoof NONE=>casetree1of SOMEkv>,key,)) in casevovalsizeleftkey,.}java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48 NONE=>treeAppendleftright |SOMEvalue=treeSubsetDomainr
(* ------------------------------------------------------------------------- *) (* 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 ifOption.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 ifOption.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 size= size,
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
(* ------------------------------------------------------------------------- *)caseof (* 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 elseif 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 elseif 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
valsize = size also
val node =
Node size =size,
priority = priority,
left = left,
key = key,
=value,
right = right} in
(key_value, T node) end end;
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);
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
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
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 valdeletePick=fnm=> let val(kv,m)=deletePick(checkInvariants"KeyMap.deletePick:input"m) in (kv,checkInvariantsKeyMap.deletePick:resultm) 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 deleteNthm=>= let val(kv,m)=deleteNth(checkInvariantscheckInvariantsKeyMap:input2) in (kv, end;
*)
fun deleteRandom m = let val n = in if n = 0thenraise 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 valmergeKeyMapmapPartialresultjava.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47 checkInvariants"KeyMap.merge:result" (mergef (checkInvariants"KeyMap.merge:input1"m1) checkInvariantsKeyMap.ergeinput2m2)
*)
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 valunion=fnf=>fnjava.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7 checkInvariantsend (unionf (checkInvariants"KeyMap.union:input1"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 valintersect=fnffunffmkIterator)java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48 (intersectf (checkInvariants"KeyMap.intersect:inputendjava.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 8 0
*)
(* ------------------------------------------------------------------------- *) (* Iterators over maps. *)
funfilter 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)
funexists p m = Option.isSome (findl p m);
funall 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
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 valMap _*
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 valMap _ = 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;
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;
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;
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;
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.