[pure-lang-svn] SF.net SVN: pure-lang:[640] pure/trunk/lib
Status: Beta
Brought to you by:
agraef
From: <ag...@us...> - 2008-08-27 21:07:21
|
Revision: 640 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=640&view=rev Author: agraef Date: 2008-08-27 21:07:30 +0000 (Wed, 27 Aug 2008) Log Message: ----------- Keep the namespace clean. Modified Paths: -------------- pure/trunk/lib/array.pure pure/trunk/lib/dict.pure pure/trunk/lib/heap.pure pure/trunk/lib/set.pure Modified: pure/trunk/lib/array.pure =================================================================== --- pure/trunk/lib/array.pure 2008-08-27 20:35:47 UTC (rev 639) +++ pure/trunk/lib/array.pure 2008-08-27 21:07:30 UTC (rev 640) @@ -55,9 +55,12 @@ *************************************************************************/ -/* Empty tree constant, consider this private. */ -nullary nil; +/* Tree constructors. */ +private nullary nil; +private tip bin; +private mkbin; + // array type check arrayp (Array _) = 1; arrayp _ = 0; @@ -76,7 +79,7 @@ with mkarray x n::int = nil if n <= 0; = tip x if n == 1; - = array_mkbin (n mod 2) + = mkbin (n mod 2) (mkarray x (n - n div 2)) (mkarray x (n div 2)); end; @@ -150,16 +153,16 @@ rmfirst (Array a) = Array (rmfirst a) with rmfirst (tip _) = nil; - rmfirst (bin 0 a1 a2) = array_mkbin 1 a2 (rmfirst a1); - rmfirst (bin 1 a1 a2) = array_mkbin 0 a2 (rmfirst a1); + rmfirst (bin 0 a1 a2) = mkbin 1 a2 (rmfirst a1); + rmfirst (bin 1 a1 a2) = mkbin 0 a2 (rmfirst a1); end; // remove the last member from an array rmlast (Array a) = Array (rmlast a) with rmlast (tip _) = nil; - rmlast (bin 0 a1 a2) = array_mkbin 1 a1 (rmlast a2); - rmlast (bin 1 a1 a2) = array_mkbin 0 (rmlast a1) a2; + rmlast (bin 0 a1 a2) = mkbin 1 a1 (rmlast a2); + rmlast (bin 1 a1 a2) = mkbin 0 (rmlast a1) a2; end; // insert a new member at the beginning of an array @@ -167,8 +170,8 @@ with insert nil y = tip y; insert (tip x) y = bin 0 (tip y) (tip x); - insert (bin 0 a1 a2) y = array_mkbin 1 (insert a2 y) a1; - insert (bin 1 a1 a2) y = array_mkbin 0 (insert a2 y) a1; + insert (bin 0 a1 a2) y = mkbin 1 (insert a2 y) a1; + insert (bin 1 a1 a2) y = mkbin 0 (insert a2 y) a1; end; // append a new member at the end of an array @@ -176,8 +179,8 @@ with append nil y = tip y; append (tip x) y = bin 0 (tip x) (tip y); - append (bin 0 a1 a2) y = array_mkbin 1 (append a1 y) a2; - append (bin 1 a1 a2) y = array_mkbin 0 a1 (append a2 y); + append (bin 0 a1 a2) y = mkbin 1 (append a1 y) a2; + append (bin 1 a1 a2) y = mkbin 0 a1 (append a2 y); end; // update a given array position with a new value @@ -225,9 +228,9 @@ = b1 != b2 || neq a1 a3 || neq a2 a4; end; -/* Private functions, don't invoke these directly. */ +/* Private functions. */ // construct a binary array node -array_mkbin _ nil a2 = a2; -array_mkbin _ a1 nil = a1; -array_mkbin b::int a1 a2 = bin b a1 a2; +mkbin _ nil a2 = a2; +mkbin _ a1 nil = a1; +mkbin b::int a1 a2 = bin b a1 a2; Modified: pure/trunk/lib/dict.pure =================================================================== --- pure/trunk/lib/dict.pure 2008-08-27 20:35:47 UTC (rev 639) +++ pure/trunk/lib/dict.pure 2008-08-27 21:07:30 UTC (rev 640) @@ -30,8 +30,9 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ -/* Empty tree constant, consider this private. */ -nullary nil; +/* Tree constructors. */ +private nullary nil; +private bin; /***** Tree for dict and hdict is either: @@ -69,6 +70,7 @@ *************************************************************************/ +private adjustd avl_geq; // Dict and hdict type checks dictp (Dict _) = 1; @@ -148,7 +150,7 @@ rebal 0 (bin k v _ l r) b = bin k v b l r; - rebal 1 oldTree _ = (Dict_avl_geq oldTree)!0; + rebal 1 oldTree _ = (avl_geq oldTree)!0; /* // Balance rules for insertions @@ -187,7 +189,7 @@ = [l, 1] if key == k; deleted (bin k _ b (bin kl vl bl rl ll) r ) key - = Dict_adjustd leftHasChanged (bin lastk lastv b newl r) (-1) + = adjustd leftHasChanged (bin lastk lastv b newl r) (-1) when [lastk, lastv] = last (bin kl vl bl rl ll); [newl, leftHasChanged] @@ -196,14 +198,14 @@ if key == k; deleted (bin k v b l r) key - = Dict_adjustd leftHasChanged (bin k v b newl r) (-1) + = adjustd leftHasChanged (bin k v b newl r) (-1) when [newl, leftHasChanged] = deleted l key end if key < k; deleted (bin k v b l r) key - = Dict_adjustd rightHasChanged (bin k v b l newr) ( 1) + = adjustd rightHasChanged (bin k v b l newr) ( 1) when [newr, rightHasChanged] = deleted r key end @@ -230,7 +232,7 @@ if k == key; deleteh (bin k::int xys b (bin kl vl bl rl ll) r) key::int x - = Dict_adjustd leftHasChanged (bin lastk lastv b newl r) (-1) + = adjustd leftHasChanged (bin lastk lastv b newl r) (-1) when [lastk, lastv] = last (bin kl vl bl rl ll); [newl, leftHasChanged] = rmlast (bin kl vl bl rl ll) @@ -242,14 +244,14 @@ if k == key; deleteh (bin k::int v b l r) key::int x - = Dict_adjustd leftHasChanged (bin k v b newl r) (-1) + = adjustd leftHasChanged (bin k v b newl r) (-1) when [newl, leftHasChanged] = deleteh l key x end if key < k; deleteh (bin k::int v b l r) key::int x - = Dict_adjustd rightHasChanged (bin k v b l newr) ( 1) + = adjustd rightHasChanged (bin k v b l newr) ( 1) when [newr, rightHasChanged] = deleteh r key x end @@ -262,7 +264,7 @@ rmlast nil = [nil, 0]; rmlast (bin _ _ _ l nil) = [l, 1]; rmlast (bin k v b::int l r ) - = Dict_adjustd rightHasChanged (bin k v b l newr) ( 1) + = adjustd rightHasChanged (bin k v b l newr) ( 1) when [newr, rightHasChanged] = rmlast r end; last (bin x y _ _ nil) = [x, y]; @@ -356,7 +358,7 @@ rmfirst nil = [nil, 0]; rmfirst (bin _ _ _ nil r) = [r, 1]; rmfirst (bin k v b l r) - = Dict_adjustd leftHasChanged (bin k v b newl r) (-1) + = adjustd leftHasChanged (bin k v b newl r) (-1) when [newl, leftHasChanged] = rmfirst l end @@ -368,7 +370,7 @@ rmlast nil = [nil 0]; rmlast (bin _ _ _ l nil) = [l, 1]; rmlast (bin k v b l r) - = Dict_adjustd rightHasChanged (bin k v b l newr) ( 1) + = adjustd rightHasChanged (bin k v b l newr) ( 1) when [newr, rightHasChanged] = rmlast r end @@ -489,9 +491,9 @@ d1@(Dict _) != d2@(Dict _) = (members d1) != (members d2); d1@(Hdict _) != d2@(Hdict _) = not (d1 == d2); -/* Private functions, don't invoke these directly. */ +/* Private functions. */ -Dict_adjustd ToF::int tree LoR::int +adjustd ToF::int tree LoR::int = adjust ToF tree LoR with adjust 0 oldTree _ = [oldTree, 0]; @@ -505,7 +507,7 @@ rebal 0 (bin k v _ l r) b whatHasChanged = [bin k v b l r, whatHasChanged]; - rebal 1 oldTree _ _ = Dict_avl_geq oldTree; + rebal 1 oldTree _ _ = avl_geq oldTree; /* // Balance rules for deletions @@ -543,7 +545,7 @@ deletion any pattern can occur and so we return 1 or 0 as a flag of a height change. */ -Dict_avl_geq d = avl_geq d +avl_geq d = avl_geq d with avl_geq (bin a va (-1) alpha (bin b vb (-1) beta gamma)) = [bin b vb ( 0) (bin a va ( 0) alpha beta) gamma, 1]; Modified: pure/trunk/lib/heap.pure =================================================================== --- pure/trunk/lib/heap.pure 2008-08-27 20:35:47 UTC (rev 639) +++ pure/trunk/lib/heap.pure 2008-08-27 21:07:30 UTC (rev 640) @@ -41,8 +41,9 @@ *************************************************************************/ -/* Empty tree constant, consider this private. */ -nullary nil; +/* Tree constructors. */ +private nullary nil; +private bin; // create an empty heap emptyheap = Heap nil; Modified: pure/trunk/lib/set.pure =================================================================== --- pure/trunk/lib/set.pure 2008-08-27 20:35:47 UTC (rev 639) +++ pure/trunk/lib/set.pure 2008-08-27 21:07:30 UTC (rev 640) @@ -50,8 +50,9 @@ *************************************************************************/ -/* Empty tree constant, consider this private. */ -nullary nil; +/* Tree constructors. */ +private nullary nil; +private bin; /***** Tree for set and bag is either: @@ -62,6 +63,8 @@ Balance: ( 1), ( 0), or (-1) denoting |L|-|R| = 1, 0, or -1, respectively *****/ +private adjustd avl_geq; + // set and bag type checks bagp (Bag _) = 1; bagp _ = 0; @@ -109,7 +112,7 @@ = bin k b l r; rebal 1 oldTree _ - = (Set_avl_geq oldTree)!0; + = (avl_geq oldTree)!0; /* // Balance rules for insertions // balance where balance whole tree to be @@ -145,7 +148,7 @@ = [l, 1] if key == k; delete (bin k b::int x@(bin kl bl::int rl ll) r) key - = Set_adjustd leftHasChanged (bin lk b newL r) (-1) + = adjustd leftHasChanged (bin lk b newL r) (-1) when lk = last x; [newL, leftHasChanged] = rmlast x @@ -153,14 +156,14 @@ if key == k; delete (bin k b::int l r) key - = Set_adjustd leftHasChanged (bin k b newL r) (-1) + = adjustd leftHasChanged (bin k b newL r) (-1) when [newL, leftHasChanged] = delete l key end if key < k; delete (bin k b::int l r) key - = Set_adjustd rightHasChanged (bin k b l newR) ( 1) + = adjustd rightHasChanged (bin k b l newR) ( 1) when [newR, rightHasChanged] = delete r key end @@ -169,7 +172,7 @@ rmlast nil = [nil, 0]; rmlast (bin _ _ l nil) = [l, 1]; rmlast (bin k b::int l r ) - = Set_adjustd rightHasChanged (bin k b l newR) ( 1) + = adjustd rightHasChanged (bin k b l newR) ( 1) when [newR, rightHasChanged] = rmlast r end; last (bin x _ _ nil) = x; @@ -245,7 +248,7 @@ rmfirst nil = [nil, 0]; rmfirst (bin _ _ nil r) = [r, 1]; rmfirst (bin k b::int l r) - = Set_adjustd leftHasChanged (bin k b newL r) (-1) + = adjustd leftHasChanged (bin k b newL r) (-1) when [newL, leftHasChanged] = rmfirst l end end; @@ -257,7 +260,7 @@ rmlast nil = [nil, 0]; rmlast (bin _ _ l nil) = [l, 1]; rmlast (bin k b::int l r ) - = Set_adjustd rightHasChanged (bin k b l newR) ( 1) + = adjustd rightHasChanged (bin k b l newR) ( 1) when [newR, rightHasChanged] = rmlast r end end; @@ -300,9 +303,9 @@ = m1 - (m1 - m2); -/* Private functions, don't invoke these directly. */ +/* Private functions. */ -Set_adjustd ToF::int tree LoR::int +adjustd ToF::int tree LoR::int = adjust ToF tree LoR with adjust 0 oldTree _ = [oldTree, 0]; @@ -321,7 +324,7 @@ rebal 0 (bin k _ l r) b::int whatHasChanged = [bin k b l r, whatHasChanged]; - rebal 1 oldTree _ _ = Set_avl_geq oldTree; + rebal 1 oldTree _ _ = avl_geq oldTree; // Balance rules for deletions /* @@ -360,7 +363,7 @@ a height change. */ -Set_avl_geq x = avl_geq x +avl_geq x = avl_geq x with avl_geq (bin a (-1) alpha (bin b (-1) beta gamma)) = [bin b ( 0) (bin a ( 0) alpha beta) gamma, 1]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |