forked from mozart/mozart2-compiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGroundZip.oz
74 lines (69 loc) · 1.61 KB
/
GroundZip.oz
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
%%%
%%% Author:
%%% Christian Schulte <[email protected]>
%%%
%%% Copyright:
%%% Christian Schulte, 1999
%%%
%%% Last change:
%%% $Date$ by $Author$
%%% $Revision$
%%%
%%% This file is part of Mozart, an implementation of Oz 3:
%%% http://www.mozart-oz.org
%%%
%%% See the file "LICENSE" or
%%% http://www.mozart-oz.org/LICENSE.html
%%% for information on usage and redistribution
%%% of this file, and for a DISCLAIMER OF ALL
%%% WARRANTIES.
%%%
%%% This is an extremely poor compression module for Oz data structures.
%%% It makes sharing in ground data structures explicit
functor
export Zip
define
local
fun {IsIn KXs K}
case KXs of nil then false
[] KX|KXr then
KX.1==K orelse {IsIn KXr K}
end
end
fun {Get (K1|X)|KXr K2}
if K1==K2 then X else {Get KXr K2} end
end
in
class AnyTab
attr kxs:nil
meth init skip end
meth isIn(K $)
{IsIn @kxs K}
end
meth put(K X)
kxs <- (K|X)|@kxs
end
meth get(K $)
{Get @kxs K}
end
end
end
RecordTab = {New AnyTab init}
IntTab = {Dictionary.new}
fun {Zip X}
if {IsInt X} then
if {Not {Dictionary.member IntTab X}} then
{Dictionary.put IntTab X X}
end
{Dictionary.get IntTab X}
elseif {IsLiteral X} then X
elseif {IsRecord X} then
if {RecordTab isIn(X $)} then skip else T in
{RecordTab put(X T)}
T={Record.map X Zip}
end
{RecordTab get(X $)}
else X
end
end
end