daff 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/daff.rb +3 -0
- data/lib/daff.rb +95 -0
- data/lib/lib/coopy/alignment.rb +409 -0
- data/lib/lib/coopy/bag.rb +10 -0
- data/lib/lib/coopy/cell_info.rb +29 -0
- data/lib/lib/coopy/change.rb +48 -0
- data/lib/lib/coopy/change_type.rb +21 -0
- data/lib/lib/coopy/compare.rb +98 -0
- data/lib/lib/coopy/compare_flags.rb +46 -0
- data/lib/lib/coopy/compare_table.rb +402 -0
- data/lib/lib/coopy/coopy.rb +414 -0
- data/lib/lib/coopy/cross_match.rb +16 -0
- data/lib/lib/coopy/csv.rb +181 -0
- data/lib/lib/coopy/diff_render.rb +254 -0
- data/lib/lib/coopy/highlight_patch.rb +651 -0
- data/lib/lib/coopy/highlight_patch_unit.rb +37 -0
- data/lib/lib/coopy/index.rb +101 -0
- data/lib/lib/coopy/index_item.rb +20 -0
- data/lib/lib/coopy/index_pair.rb +87 -0
- data/lib/lib/coopy/mover.rb +195 -0
- data/lib/lib/coopy/ordering.rb +49 -0
- data/lib/lib/coopy/report.rb +23 -0
- data/lib/lib/coopy/row.rb +9 -0
- data/lib/lib/coopy/simple_cell.rb +23 -0
- data/lib/lib/coopy/simple_table.rb +242 -0
- data/lib/lib/coopy/simple_view.rb +41 -0
- data/lib/lib/coopy/sparse_sheet.rb +50 -0
- data/lib/lib/coopy/table.rb +17 -0
- data/lib/lib/coopy/table_comparison_state.rb +32 -0
- data/lib/lib/coopy/table_diff.rb +738 -0
- data/lib/lib/coopy/table_io.rb +33 -0
- data/lib/lib/coopy/table_modifier.rb +39 -0
- data/lib/lib/coopy/table_text.rb +25 -0
- data/lib/lib/coopy/unit.rb +70 -0
- data/lib/lib/coopy/view.rb +14 -0
- data/lib/lib/coopy/viewed_datum.rb +37 -0
- data/lib/lib/coopy/viterbi.rb +172 -0
- data/lib/lib/coopy/workspace.rb +22 -0
- data/lib/lib/haxe/ds/int_map.rb +14 -0
- data/lib/lib/haxe/ds/string_map.rb +14 -0
- data/lib/lib/haxe/format/json_parser.rb +264 -0
- data/lib/lib/haxe/format/json_printer.rb +239 -0
- data/lib/lib/haxe/io/bytes.rb +33 -0
- data/lib/lib/haxe/io/eof.rb +17 -0
- data/lib/lib/haxe/io/error.rb +21 -0
- data/lib/lib/haxe/io/output.rb +40 -0
- data/lib/lib/haxe/log.rb +16 -0
- data/lib/lib/hx_overrides.rb +18 -0
- data/lib/lib/imap.rb +6 -0
- data/lib/lib/lambda.rb +36 -0
- data/lib/lib/list.rb +42 -0
- data/lib/lib/rb/boot.rb +19 -0
- data/lib/lib/rb/ruby_iterator.rb +49 -0
- data/lib/lib/reflect.rb +29 -0
- data/lib/lib/string_buf.rb +14 -0
- data/lib/lib/sys.rb +19 -0
- data/lib/lib/sys/io/file.rb +19 -0
- data/lib/lib/sys/io/file_handle.rb +17 -0
- data/lib/lib/sys/io/file_output.rb +35 -0
- data/lib/lib/type.rb +32 -0
- data/lib/lib/value_type.rb +22 -0
- metadata +181 -0
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
module Coopy
|
5
|
+
class CellInfo
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_accessor :value
|
11
|
+
attr_accessor :pretty_value
|
12
|
+
attr_accessor :category
|
13
|
+
attr_accessor :category_given_tr
|
14
|
+
attr_accessor :separator
|
15
|
+
attr_accessor :updated
|
16
|
+
attr_accessor :conflicted
|
17
|
+
attr_accessor :pvalue
|
18
|
+
attr_accessor :lvalue
|
19
|
+
attr_accessor :rvalue
|
20
|
+
|
21
|
+
def to_s
|
22
|
+
return @value if !@updated
|
23
|
+
return _hx_str(@lvalue) + "::" + _hx_str(@rvalue) if !@conflicted
|
24
|
+
return _hx_str(@pvalue) + "||" + _hx_str(@lvalue) + "::" + _hx_str(@rvalue)
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
module Coopy
|
5
|
+
class Change
|
6
|
+
|
7
|
+
def initialize(txt = nil)
|
8
|
+
if txt != nil
|
9
|
+
@mode = ::Coopy::ChangeType.note_change
|
10
|
+
@change = txt
|
11
|
+
else
|
12
|
+
@mode = ::Coopy::ChangeType.no_change
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
attr_accessor :change
|
17
|
+
attr_accessor :parent
|
18
|
+
attr_accessor :local
|
19
|
+
attr_accessor :remote
|
20
|
+
attr_accessor :mode
|
21
|
+
|
22
|
+
def get_mode
|
23
|
+
return "" + _hx_str(@mode.to_s)
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_s
|
27
|
+
begin
|
28
|
+
_g = @mode
|
29
|
+
case(_g.index)
|
30
|
+
when 0
|
31
|
+
return "no change"
|
32
|
+
when 2
|
33
|
+
return "local change: " + _hx_str(@remote.to_s) + " -> " + _hx_str(@local.to_s)
|
34
|
+
when 1
|
35
|
+
return "remote change: " + _hx_str(@local.to_s) + " -> " + _hx_str(@remote.to_s)
|
36
|
+
when 3
|
37
|
+
return "conflicting change: " + _hx_str(@parent.to_s) + " -> " + _hx_str(@local.to_s) + " / " + _hx_str(@remote.to_s)
|
38
|
+
when 4
|
39
|
+
return "same change: " + _hx_str(@parent.to_s) + " -> " + _hx_str(@local.to_s) + " / " + _hx_str(@remote.to_s)
|
40
|
+
when 5
|
41
|
+
return @change
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
module Coopy
|
5
|
+
class ChangeType
|
6
|
+
ISENUM__ = true
|
7
|
+
attr_accessor :tag
|
8
|
+
attr_accessor :index
|
9
|
+
attr_accessor :params
|
10
|
+
def initialize(t,index,p = nil ) @tag = t; @index = index; @params = p; end
|
11
|
+
|
12
|
+
def ChangeType.both_change() ChangeType.new("BOTH_CHANGE",3) end
|
13
|
+
def ChangeType.local_change() ChangeType.new("LOCAL_CHANGE",2) end
|
14
|
+
def ChangeType.note_change() ChangeType.new("NOTE_CHANGE",5) end
|
15
|
+
def ChangeType.no_change() ChangeType.new("NO_CHANGE",0) end
|
16
|
+
def ChangeType.remote_change() ChangeType.new("REMOTE_CHANGE",1) end
|
17
|
+
def ChangeType.same_change() ChangeType.new("SAME_CHANGE",4) end
|
18
|
+
CONSTRUCTS__ = ["NO_CHANGE","REMOTE_CHANGE","LOCAL_CHANGE","BOTH_CHANGE","SAME_CHANGE","NOTE_CHANGE"]
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
module Coopy
|
5
|
+
class Compare
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
end
|
9
|
+
|
10
|
+
def compare(parent,local,remote,report)
|
11
|
+
ws = ::Coopy::Workspace.new
|
12
|
+
ws.parent = parent
|
13
|
+
ws.local = local
|
14
|
+
ws.remote = remote
|
15
|
+
ws.report = report
|
16
|
+
report.clear
|
17
|
+
if parent == nil || local == nil || remote == nil
|
18
|
+
report.changes.push(::Coopy::Change.new("only 3-way comparison allowed right now"))
|
19
|
+
return false
|
20
|
+
end
|
21
|
+
return self.compare_structured(ws) if parent.has_structure || local.has_structure || remote.has_structure
|
22
|
+
return self.compare_primitive(ws)
|
23
|
+
end
|
24
|
+
|
25
|
+
protected
|
26
|
+
|
27
|
+
def compare_structured(ws)
|
28
|
+
ws.tparent = ws.parent.get_table
|
29
|
+
ws.tlocal = ws.local.get_table
|
30
|
+
ws.tremote = ws.remote.get_table
|
31
|
+
if ws.tparent == nil || ws.tlocal == nil || ws.tremote == nil
|
32
|
+
ws.report.changes.push(::Coopy::Change.new("structured comparisons that include non-tables are not available yet"))
|
33
|
+
return false
|
34
|
+
end
|
35
|
+
return self.compare_table(ws)
|
36
|
+
end
|
37
|
+
|
38
|
+
def compare_table(ws)
|
39
|
+
ws.p2l = ::Coopy::TableComparisonState.new
|
40
|
+
ws.p2r = ::Coopy::TableComparisonState.new
|
41
|
+
ws.p2l.a = ws.tparent
|
42
|
+
ws.p2l.b = ws.tlocal
|
43
|
+
ws.p2r.a = ws.tparent
|
44
|
+
ws.p2r.b = ws.tremote
|
45
|
+
cmp = ::Coopy::CompareTable.new
|
46
|
+
cmp.attach(ws.p2l)
|
47
|
+
cmp.attach(ws.p2r)
|
48
|
+
c = ::Coopy::Change.new
|
49
|
+
c.parent = ws.parent
|
50
|
+
c.local = ws.local
|
51
|
+
c.remote = ws.remote
|
52
|
+
if ws.p2l.is_equal && !ws.p2r.is_equal
|
53
|
+
c.mode = ::Coopy::ChangeType.remote_change
|
54
|
+
elsif !ws.p2l.is_equal && ws.p2r.is_equal
|
55
|
+
c.mode = ::Coopy::ChangeType.local_change
|
56
|
+
elsif !ws.p2l.is_equal && !ws.p2r.is_equal
|
57
|
+
ws.l2r = ::Coopy::TableComparisonState.new
|
58
|
+
ws.l2r.a = ws.tlocal
|
59
|
+
ws.l2r.b = ws.tremote
|
60
|
+
cmp.attach(ws.l2r)
|
61
|
+
if ws.l2r.is_equal
|
62
|
+
c.mode = ::Coopy::ChangeType.same_change
|
63
|
+
else
|
64
|
+
c.mode = ::Coopy::ChangeType.both_change
|
65
|
+
end
|
66
|
+
else
|
67
|
+
c.mode = ::Coopy::ChangeType.no_change
|
68
|
+
end
|
69
|
+
ws.report.changes.push(c) if c.mode != ::Coopy::ChangeType.no_change
|
70
|
+
return true
|
71
|
+
end
|
72
|
+
|
73
|
+
def compare_primitive(ws)
|
74
|
+
sparent = ws.parent.to_s
|
75
|
+
slocal = ws.local.to_s
|
76
|
+
sremote = ws.remote.to_s
|
77
|
+
c = ::Coopy::Change.new
|
78
|
+
c.parent = ws.parent
|
79
|
+
c.local = ws.local
|
80
|
+
c.remote = ws.remote
|
81
|
+
if sparent == slocal && sparent != sremote
|
82
|
+
c.mode = ::Coopy::ChangeType.remote_change
|
83
|
+
elsif sparent == sremote && sparent != slocal
|
84
|
+
c.mode = ::Coopy::ChangeType.local_change
|
85
|
+
elsif slocal == sremote && sparent != slocal
|
86
|
+
c.mode = ::Coopy::ChangeType.same_change
|
87
|
+
elsif sparent != slocal && sparent != sremote
|
88
|
+
c.mode = ::Coopy::ChangeType.both_change
|
89
|
+
else
|
90
|
+
c.mode = ::Coopy::ChangeType.no_change
|
91
|
+
end
|
92
|
+
ws.report.changes.push(c) if c.mode != ::Coopy::ChangeType.no_change
|
93
|
+
return true
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
module Coopy
|
5
|
+
class CompareFlags
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@ordered = true
|
9
|
+
@show_unchanged = false
|
10
|
+
@unchanged_context = 1
|
11
|
+
@always_show_order = false
|
12
|
+
@never_show_order = true
|
13
|
+
@show_unchanged_columns = false
|
14
|
+
@unchanged_column_context = 1
|
15
|
+
@always_show_header = true
|
16
|
+
@acts = nil
|
17
|
+
end
|
18
|
+
|
19
|
+
attr_accessor :ordered
|
20
|
+
attr_accessor :show_unchanged
|
21
|
+
attr_accessor :unchanged_context
|
22
|
+
attr_accessor :always_show_order
|
23
|
+
attr_accessor :never_show_order
|
24
|
+
attr_accessor :show_unchanged_columns
|
25
|
+
attr_accessor :unchanged_column_context
|
26
|
+
attr_accessor :always_show_header
|
27
|
+
attr_accessor :acts
|
28
|
+
|
29
|
+
def allow_update
|
30
|
+
return true if @acts == nil
|
31
|
+
return @acts.include?("update")
|
32
|
+
end
|
33
|
+
|
34
|
+
def allow_insert
|
35
|
+
return true if @acts == nil
|
36
|
+
return @acts.include?("insert")
|
37
|
+
end
|
38
|
+
|
39
|
+
def allow_delete
|
40
|
+
return true if @acts == nil
|
41
|
+
return @acts.include?("delete")
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,402 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
module Coopy
|
5
|
+
class CompareTable
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
end
|
9
|
+
|
10
|
+
protected
|
11
|
+
|
12
|
+
attr_accessor :comp
|
13
|
+
attr_accessor :indexes
|
14
|
+
|
15
|
+
public
|
16
|
+
|
17
|
+
def attach(comp)
|
18
|
+
@comp = comp
|
19
|
+
more = self.compare_core
|
20
|
+
while(more && comp.run_to_completion)
|
21
|
+
more = self.compare_core
|
22
|
+
end
|
23
|
+
return !more
|
24
|
+
end
|
25
|
+
|
26
|
+
def align
|
27
|
+
alignment = ::Coopy::Alignment.new
|
28
|
+
self.align_core(alignment)
|
29
|
+
return alignment
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_comparison_state
|
33
|
+
return @comp
|
34
|
+
end
|
35
|
+
|
36
|
+
protected
|
37
|
+
|
38
|
+
def align_core(align)
|
39
|
+
if @comp.p == nil
|
40
|
+
self.align_core2(align,@comp.a,@comp.b)
|
41
|
+
return
|
42
|
+
end
|
43
|
+
align.reference = ::Coopy::Alignment.new
|
44
|
+
self.align_core2(align,@comp.p,@comp.b)
|
45
|
+
self.align_core2(align.reference,@comp.p,@comp.a)
|
46
|
+
align.meta.reference = align.reference.meta
|
47
|
+
end
|
48
|
+
|
49
|
+
def align_core2(align,a,b)
|
50
|
+
align.meta = ::Coopy::Alignment.new if align.meta == nil
|
51
|
+
self.align_columns(align.meta,a,b)
|
52
|
+
column_order = align.meta.to_order_pruned(false)
|
53
|
+
common_units = Array.new
|
54
|
+
begin
|
55
|
+
_g = 0
|
56
|
+
_g1 = column_order.get_list
|
57
|
+
while(_g < _g1.length)
|
58
|
+
unit = _g1[_g]
|
59
|
+
_g+=1
|
60
|
+
common_units.push(unit) if unit.l >= 0 && unit.r >= 0 && unit.p != -1
|
61
|
+
end
|
62
|
+
end
|
63
|
+
align.range(a.get_height,b.get_height)
|
64
|
+
align.tables(a,b)
|
65
|
+
align.set_rowlike(true)
|
66
|
+
w = a.get_width
|
67
|
+
ha = a.get_height
|
68
|
+
hb = b.get_height
|
69
|
+
av = a.get_cell_view
|
70
|
+
n = 5
|
71
|
+
columns = Array.new
|
72
|
+
if common_units.length > n
|
73
|
+
columns_eval = Array.new
|
74
|
+
begin
|
75
|
+
_g11 = 0
|
76
|
+
_g2 = common_units.length
|
77
|
+
while(_g11 < _g2)
|
78
|
+
i = _g11
|
79
|
+
_g11+=1
|
80
|
+
ct = 0
|
81
|
+
mem = {}
|
82
|
+
mem2 = {}
|
83
|
+
ca = common_units[i].l
|
84
|
+
cb = common_units[i].r
|
85
|
+
begin
|
86
|
+
_g21 = 0
|
87
|
+
while(_g21 < ha)
|
88
|
+
j = _g21
|
89
|
+
_g21+=1
|
90
|
+
key = av.to_s(a.get_cell(ca,j))
|
91
|
+
if !mem.include?(key)
|
92
|
+
mem[key] = 1
|
93
|
+
ct+=1
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
begin
|
98
|
+
_g22 = 0
|
99
|
+
while(_g22 < hb)
|
100
|
+
j1 = _g22
|
101
|
+
_g22+=1
|
102
|
+
key1 = av.to_s(b.get_cell(cb,j1))
|
103
|
+
if !mem2.include?(key1)
|
104
|
+
mem2[key1] = 1
|
105
|
+
ct+=1
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
columns_eval.push([i,ct])
|
110
|
+
end
|
111
|
+
end
|
112
|
+
sorter = lambda {|a1,b1|
|
113
|
+
return 1 if a1[1] < b1[1]
|
114
|
+
return -1 if a1[1] > b1[1]
|
115
|
+
return 0
|
116
|
+
}
|
117
|
+
columns_eval.sort{|a,b| sorter.call(a,b)}
|
118
|
+
columns = Lambda.array(Lambda.map(columns_eval,lambda {|v|
|
119
|
+
return v[0]
|
120
|
+
}))
|
121
|
+
columns = columns.slice(0,n - 1)
|
122
|
+
else
|
123
|
+
_g12 = 0
|
124
|
+
_g3 = common_units.length
|
125
|
+
while(_g12 < _g3)
|
126
|
+
i1 = _g12
|
127
|
+
_g12+=1
|
128
|
+
columns.push(i1)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
top = nil
|
132
|
+
begin
|
133
|
+
v1 = 2 ** columns.length
|
134
|
+
top = v1.round
|
135
|
+
end
|
136
|
+
pending = {}
|
137
|
+
begin
|
138
|
+
_g4 = 0
|
139
|
+
while(_g4 < ha)
|
140
|
+
j2 = _g4
|
141
|
+
_g4+=1
|
142
|
+
pending[j2] = j2
|
143
|
+
end
|
144
|
+
end
|
145
|
+
pending_ct = ha
|
146
|
+
begin
|
147
|
+
_g5 = 0
|
148
|
+
while(_g5 < top)
|
149
|
+
k = _g5
|
150
|
+
_g5+=1
|
151
|
+
next if k == 0
|
152
|
+
break if pending_ct == 0
|
153
|
+
active_columns = Array.new
|
154
|
+
kk = k
|
155
|
+
at = 0
|
156
|
+
while(kk > 0)
|
157
|
+
active_columns.push(columns[at]) if kk.remainder(2) == 1
|
158
|
+
kk >>= 1
|
159
|
+
at+=1
|
160
|
+
end
|
161
|
+
index = ::Coopy::IndexPair.new
|
162
|
+
begin
|
163
|
+
_g23 = 0
|
164
|
+
_g13 = active_columns.length
|
165
|
+
while(_g23 < _g13)
|
166
|
+
k1 = _g23
|
167
|
+
_g23+=1
|
168
|
+
unit1 = common_units[active_columns[k1]]
|
169
|
+
index.add_columns(unit1.l,unit1.r)
|
170
|
+
align.add_index_columns(unit1)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
index.index_tables(a,b)
|
174
|
+
h = a.get_height
|
175
|
+
h = b.get_height if b.get_height > h
|
176
|
+
h = 1 if h < 1
|
177
|
+
wide_top_freq = index.get_top_freq
|
178
|
+
ratio = wide_top_freq
|
179
|
+
ratio /= h + 20
|
180
|
+
next if ratio >= 0.1
|
181
|
+
@indexes.push(index) if @indexes != nil
|
182
|
+
fixed = Array.new
|
183
|
+
_it = ::Rb::RubyIterator.new(pending.keys)
|
184
|
+
while(_it.has_next) do
|
185
|
+
j3 = _it._next
|
186
|
+
cross = index.query_local(j3)
|
187
|
+
spot_a = cross.spot_a
|
188
|
+
spot_b = cross.spot_b
|
189
|
+
next if spot_a != 1 || spot_b != 1
|
190
|
+
fixed.push(j3)
|
191
|
+
align.link(j3,cross.item_b.lst[0])
|
192
|
+
end
|
193
|
+
begin
|
194
|
+
_g24 = 0
|
195
|
+
_g14 = fixed.length
|
196
|
+
while(_g24 < _g14)
|
197
|
+
j4 = _g24
|
198
|
+
_g24+=1
|
199
|
+
pending.delete(fixed[j4])
|
200
|
+
pending_ct-=1
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
align.link(0,0)
|
206
|
+
end
|
207
|
+
|
208
|
+
def align_columns(align,a,b)
|
209
|
+
align.range(a.get_width,b.get_width)
|
210
|
+
align.tables(a,b)
|
211
|
+
align.set_rowlike(false)
|
212
|
+
slop = 5
|
213
|
+
va = a.get_cell_view
|
214
|
+
vb = b.get_cell_view
|
215
|
+
ra_best = 0
|
216
|
+
rb_best = 0
|
217
|
+
ct_best = -1
|
218
|
+
ma_best = nil
|
219
|
+
mb_best = nil
|
220
|
+
ra_header = 0
|
221
|
+
rb_header = 0
|
222
|
+
ra_uniques = 0
|
223
|
+
rb_uniques = 0
|
224
|
+
begin
|
225
|
+
_g = 0
|
226
|
+
while(_g < slop)
|
227
|
+
ra = _g
|
228
|
+
_g+=1
|
229
|
+
break if ra >= a.get_height
|
230
|
+
begin
|
231
|
+
_g1 = 0
|
232
|
+
while(_g1 < slop)
|
233
|
+
rb1 = _g1
|
234
|
+
_g1+=1
|
235
|
+
break if rb1 >= b.get_height
|
236
|
+
ma = {}
|
237
|
+
mb = {}
|
238
|
+
ct = 0
|
239
|
+
uniques = 0
|
240
|
+
begin
|
241
|
+
_g3 = 0
|
242
|
+
_g2 = a.get_width
|
243
|
+
while(_g3 < _g2)
|
244
|
+
ca = _g3
|
245
|
+
_g3+=1
|
246
|
+
key = va.to_s(a.get_cell(ca,ra))
|
247
|
+
if ma.include?(key)
|
248
|
+
ma[key] = -1
|
249
|
+
uniques-=1
|
250
|
+
else
|
251
|
+
ma[key] = ca
|
252
|
+
uniques+=1
|
253
|
+
end
|
254
|
+
end
|
255
|
+
end
|
256
|
+
if uniques > ra_uniques
|
257
|
+
ra_header = ra
|
258
|
+
ra_uniques = uniques
|
259
|
+
end
|
260
|
+
uniques = 0
|
261
|
+
begin
|
262
|
+
_g31 = 0
|
263
|
+
_g21 = b.get_width
|
264
|
+
while(_g31 < _g21)
|
265
|
+
cb = _g31
|
266
|
+
_g31+=1
|
267
|
+
key1 = vb.to_s(b.get_cell(cb,rb1))
|
268
|
+
if mb.include?(key1)
|
269
|
+
mb[key1] = -1
|
270
|
+
uniques-=1
|
271
|
+
else
|
272
|
+
mb[key1] = cb
|
273
|
+
uniques+=1
|
274
|
+
end
|
275
|
+
end
|
276
|
+
end
|
277
|
+
if uniques > rb_uniques
|
278
|
+
rb_header = rb1
|
279
|
+
rb_uniques = uniques
|
280
|
+
end
|
281
|
+
_it = ::Rb::RubyIterator.new(ma.keys)
|
282
|
+
while(_it.has_next) do
|
283
|
+
key2 = _it._next
|
284
|
+
i0 = ma[key2]
|
285
|
+
i1 = mb[key2]
|
286
|
+
if i1 != nil
|
287
|
+
ct+=1 if i1 >= 0 && i0 >= 0
|
288
|
+
end
|
289
|
+
end
|
290
|
+
if ct > ct_best
|
291
|
+
ct_best = ct
|
292
|
+
ma_best = ma
|
293
|
+
mb_best = mb
|
294
|
+
ra_best = ra
|
295
|
+
rb_best = rb1
|
296
|
+
end
|
297
|
+
end
|
298
|
+
end
|
299
|
+
end
|
300
|
+
end
|
301
|
+
return if ma_best == nil
|
302
|
+
_it2 = ::Rb::RubyIterator.new(ma_best.keys)
|
303
|
+
while(_it2.has_next) do
|
304
|
+
key3 = _it2._next
|
305
|
+
i01 = ma_best[key3]
|
306
|
+
i11 = mb_best[key3]
|
307
|
+
align.link(i01,i11) if i11 != nil && i01 != nil
|
308
|
+
end
|
309
|
+
align.headers(ra_header,rb_header)
|
310
|
+
end
|
311
|
+
|
312
|
+
def test_has_same_columns
|
313
|
+
p = @comp.p
|
314
|
+
a = @comp.a
|
315
|
+
b = @comp.b
|
316
|
+
eq = self.has_same_columns2(a,b)
|
317
|
+
eq = self.has_same_columns2(p,a) if eq && p != nil
|
318
|
+
@comp.has_same_columns = eq
|
319
|
+
@comp.has_same_columns_known = true
|
320
|
+
return true
|
321
|
+
end
|
322
|
+
|
323
|
+
def has_same_columns2(a,b)
|
324
|
+
return false if a.get_width != b.get_width
|
325
|
+
return true if a.get_height == 0 || b.get_height == 0
|
326
|
+
av = a.get_cell_view
|
327
|
+
begin
|
328
|
+
_g1 = 0
|
329
|
+
_g = a.get_width
|
330
|
+
while(_g1 < _g)
|
331
|
+
i = _g1
|
332
|
+
_g1+=1
|
333
|
+
begin
|
334
|
+
_g3 = i + 1
|
335
|
+
_g2 = a.get_width
|
336
|
+
while(_g3 < _g2)
|
337
|
+
j = _g3
|
338
|
+
_g3+=1
|
339
|
+
return false if av.equals(a.get_cell(i,0),a.get_cell(j,0))
|
340
|
+
end
|
341
|
+
end
|
342
|
+
return false if !av.equals(a.get_cell(i,0),b.get_cell(i,0))
|
343
|
+
end
|
344
|
+
end
|
345
|
+
return true
|
346
|
+
end
|
347
|
+
|
348
|
+
def test_is_equal
|
349
|
+
p = @comp.p
|
350
|
+
a = @comp.a
|
351
|
+
b = @comp.b
|
352
|
+
eq = self.is_equal2(a,b)
|
353
|
+
eq = self.is_equal2(p,a) if eq && p != nil
|
354
|
+
@comp.is_equal = eq
|
355
|
+
@comp.is_equal_known = true
|
356
|
+
return true
|
357
|
+
end
|
358
|
+
|
359
|
+
def is_equal2(a,b)
|
360
|
+
return false if a.get_width != b.get_width || a.get_height != b.get_height
|
361
|
+
av = a.get_cell_view
|
362
|
+
begin
|
363
|
+
_g1 = 0
|
364
|
+
_g = a.get_height
|
365
|
+
while(_g1 < _g)
|
366
|
+
i = _g1
|
367
|
+
_g1+=1
|
368
|
+
begin
|
369
|
+
_g3 = 0
|
370
|
+
_g2 = a.get_width
|
371
|
+
while(_g3 < _g2)
|
372
|
+
j = _g3
|
373
|
+
_g3+=1
|
374
|
+
return false if !av.equals(a.get_cell(j,i),b.get_cell(j,i))
|
375
|
+
end
|
376
|
+
end
|
377
|
+
end
|
378
|
+
end
|
379
|
+
return true
|
380
|
+
end
|
381
|
+
|
382
|
+
def compare_core
|
383
|
+
return false if @comp.completed
|
384
|
+
return self.test_is_equal if !@comp.is_equal_known
|
385
|
+
return self.test_has_same_columns if !@comp.has_same_columns_known
|
386
|
+
@comp.completed = true
|
387
|
+
return false
|
388
|
+
end
|
389
|
+
|
390
|
+
public
|
391
|
+
|
392
|
+
def store_indexes
|
393
|
+
@indexes = Array.new
|
394
|
+
end
|
395
|
+
|
396
|
+
def get_indexes
|
397
|
+
return @indexes
|
398
|
+
end
|
399
|
+
|
400
|
+
end
|
401
|
+
|
402
|
+
end
|