everypolitician-daff 1.3.26
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +252 -0
- data/bin/daff.rb +3 -0
- data/lib/daff.rb +150 -0
- data/lib/lib/coopy/alignment.rb +307 -0
- data/lib/lib/coopy/cell_builder.rb +17 -0
- data/lib/lib/coopy/cell_info.rb +33 -0
- data/lib/lib/coopy/column_change.rb +16 -0
- data/lib/lib/coopy/combined_table.rb +127 -0
- data/lib/lib/coopy/combined_table_body.rb +151 -0
- data/lib/lib/coopy/combined_table_head.rb +103 -0
- data/lib/lib/coopy/compare_flags.rb +127 -0
- data/lib/lib/coopy/compare_table.rb +688 -0
- data/lib/lib/coopy/conflict_info.rb +23 -0
- data/lib/lib/coopy/coopy.rb +1065 -0
- data/lib/lib/coopy/cross_match.rb +17 -0
- data/lib/lib/coopy/csv.rb +290 -0
- data/lib/lib/coopy/diff_render.rb +339 -0
- data/lib/lib/coopy/diff_summary.rb +28 -0
- data/lib/lib/coopy/flat_cell_builder.rb +75 -0
- data/lib/lib/coopy/highlight_patch.rb +977 -0
- data/lib/lib/coopy/highlight_patch_unit.rb +38 -0
- data/lib/lib/coopy/index.rb +131 -0
- data/lib/lib/coopy/index_item.rb +37 -0
- data/lib/lib/coopy/index_pair.rb +96 -0
- data/lib/lib/coopy/json_table.rb +165 -0
- data/lib/lib/coopy/json_tables.rb +129 -0
- data/lib/lib/coopy/merger.rb +197 -0
- data/lib/lib/coopy/meta.rb +20 -0
- data/lib/lib/coopy/mover.rb +197 -0
- data/lib/lib/coopy/ndjson.rb +134 -0
- data/lib/lib/coopy/nested_cell_builder.rb +74 -0
- data/lib/lib/coopy/ordering.rb +54 -0
- data/lib/lib/coopy/property_change.rb +16 -0
- data/lib/lib/coopy/row.rb +11 -0
- data/lib/lib/coopy/row_change.rb +42 -0
- data/lib/lib/coopy/row_stream.rb +11 -0
- data/lib/lib/coopy/simple_meta.rb +314 -0
- data/lib/lib/coopy/simple_table.rb +345 -0
- data/lib/lib/coopy/simple_view.rb +70 -0
- data/lib/lib/coopy/sparse_sheet.rb +51 -0
- data/lib/lib/coopy/sql_column.rb +47 -0
- data/lib/lib/coopy/sql_compare.rb +605 -0
- data/lib/lib/coopy/sql_database.rb +21 -0
- data/lib/lib/coopy/sql_helper.rb +17 -0
- data/lib/lib/coopy/sql_table.rb +335 -0
- data/lib/lib/coopy/sql_table_name.rb +23 -0
- data/lib/lib/coopy/sql_tables.rb +128 -0
- data/lib/lib/coopy/sqlite_helper.rb +316 -0
- data/lib/lib/coopy/table.rb +24 -0
- data/lib/lib/coopy/table_comparison_state.rb +50 -0
- data/lib/lib/coopy/table_diff.rb +1185 -0
- data/lib/lib/coopy/table_io.rb +72 -0
- data/lib/lib/coopy/table_modifier.rb +40 -0
- data/lib/lib/coopy/table_stream.rb +102 -0
- data/lib/lib/coopy/table_view.rb +148 -0
- data/lib/lib/coopy/tables.rb +52 -0
- data/lib/lib/coopy/terminal_diff_render.rb +213 -0
- data/lib/lib/coopy/unit.rb +93 -0
- data/lib/lib/coopy/view.rb +20 -0
- data/lib/lib/coopy/viterbi.rb +177 -0
- data/lib/lib/haxe/ds/int_map.rb +19 -0
- data/lib/lib/haxe/ds/string_map.rb +19 -0
- data/lib/lib/haxe/format/json_parser.rb +265 -0
- data/lib/lib/haxe/format/json_printer.rb +240 -0
- data/lib/lib/haxe/imap.rb +10 -0
- data/lib/lib/haxe/io/bytes.rb +34 -0
- data/lib/lib/haxe/io/eof.rb +18 -0
- data/lib/lib/haxe/io/error.rb +22 -0
- data/lib/lib/haxe/io/output.rb +41 -0
- data/lib/lib/hx_overrides.rb +19 -0
- data/lib/lib/hx_sys.rb +74 -0
- data/lib/lib/lambda.rb +37 -0
- data/lib/lib/list.rb +36 -0
- data/lib/lib/math.rb +5 -0
- data/lib/lib/rb/boot.rb +39 -0
- data/lib/lib/rb/ruby_iterator.rb +50 -0
- data/lib/lib/reflect.rb +41 -0
- data/lib/lib/std.rb +12 -0
- data/lib/lib/string_buf.rb +19 -0
- data/lib/lib/sys/io/file_handle.rb +18 -0
- data/lib/lib/sys/io/file_output.rb +36 -0
- data/lib/lib/sys/io/hx_file.rb +20 -0
- data/lib/lib/type.rb +37 -0
- data/lib/lib/value_type.rb +23 -0
- data/lib/lib/x_list/list_iterator.rb +32 -0
- metadata +235 -0
@@ -0,0 +1,127 @@
|
|
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
|
+
@ids = nil
|
18
|
+
@columns_to_ignore = nil
|
19
|
+
@allow_nested_cells = false
|
20
|
+
@warnings = nil
|
21
|
+
@diff_strategy = nil
|
22
|
+
@show_meta = true
|
23
|
+
@show_unchanged_meta = false
|
24
|
+
@tables = nil
|
25
|
+
@parent = nil
|
26
|
+
@count_like_a_spreadsheet = true
|
27
|
+
@ignore_whitespace = false
|
28
|
+
@ignore_case = false
|
29
|
+
@terminal_format = nil
|
30
|
+
@use_glyphs = true
|
31
|
+
end
|
32
|
+
|
33
|
+
attr_accessor :ordered
|
34
|
+
attr_accessor :show_unchanged
|
35
|
+
attr_accessor :unchanged_context
|
36
|
+
attr_accessor :always_show_order
|
37
|
+
attr_accessor :never_show_order
|
38
|
+
attr_accessor :show_unchanged_columns
|
39
|
+
attr_accessor :unchanged_column_context
|
40
|
+
attr_accessor :always_show_header
|
41
|
+
attr_accessor :acts
|
42
|
+
attr_accessor :ids
|
43
|
+
attr_accessor :columns_to_ignore
|
44
|
+
attr_accessor :tables
|
45
|
+
attr_accessor :allow_nested_cells
|
46
|
+
attr_accessor :warnings
|
47
|
+
attr_accessor :diff_strategy
|
48
|
+
attr_accessor :padding_strategy
|
49
|
+
attr_accessor :show_meta
|
50
|
+
attr_accessor :show_unchanged_meta
|
51
|
+
attr_accessor :parent
|
52
|
+
attr_accessor :count_like_a_spreadsheet
|
53
|
+
attr_accessor :ignore_whitespace
|
54
|
+
attr_accessor :ignore_case
|
55
|
+
attr_accessor :terminal_format
|
56
|
+
attr_accessor :use_glyphs
|
57
|
+
|
58
|
+
def filter(act,allow)
|
59
|
+
if @acts == nil
|
60
|
+
@acts = {}
|
61
|
+
@acts["update"] = !allow
|
62
|
+
@acts["insert"] = !allow
|
63
|
+
@acts["delete"] = !allow
|
64
|
+
end
|
65
|
+
return false if !@acts.include?(act)
|
66
|
+
@acts[act] = allow
|
67
|
+
true
|
68
|
+
end
|
69
|
+
|
70
|
+
def allow_update
|
71
|
+
return true if @acts == nil
|
72
|
+
@acts.include?("update")
|
73
|
+
end
|
74
|
+
|
75
|
+
def allow_insert
|
76
|
+
return true if @acts == nil
|
77
|
+
@acts.include?("insert")
|
78
|
+
end
|
79
|
+
|
80
|
+
def allow_delete
|
81
|
+
return true if @acts == nil
|
82
|
+
@acts.include?("delete")
|
83
|
+
end
|
84
|
+
|
85
|
+
def get_ignored_columns
|
86
|
+
return nil if @columns_to_ignore == nil
|
87
|
+
ignore = {}
|
88
|
+
begin
|
89
|
+
_g1 = 0
|
90
|
+
_g = @columns_to_ignore.length
|
91
|
+
while(_g1 < _g)
|
92
|
+
i = _g1
|
93
|
+
_g1+=1
|
94
|
+
ignore[@columns_to_ignore[i]] = true
|
95
|
+
end
|
96
|
+
end
|
97
|
+
ignore
|
98
|
+
end
|
99
|
+
|
100
|
+
def add_primary_key(column)
|
101
|
+
@ids = Array.new if @ids == nil
|
102
|
+
@ids.push(column)
|
103
|
+
end
|
104
|
+
|
105
|
+
def ignore_column(column)
|
106
|
+
@columns_to_ignore = Array.new if @columns_to_ignore == nil
|
107
|
+
@columns_to_ignore.push(column)
|
108
|
+
end
|
109
|
+
|
110
|
+
def add_table(table)
|
111
|
+
@tables = Array.new if @tables == nil
|
112
|
+
@tables.push(table)
|
113
|
+
end
|
114
|
+
|
115
|
+
def add_warning(warn)
|
116
|
+
@warnings = Array.new if @warnings == nil
|
117
|
+
@warnings.push(warn)
|
118
|
+
end
|
119
|
+
|
120
|
+
def get_warning
|
121
|
+
@warnings.join("\n")
|
122
|
+
end
|
123
|
+
|
124
|
+
haxe_me ["coopy", "CompareFlags"]
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
@@ -0,0 +1,688 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
module Coopy
|
5
|
+
class CompareTable
|
6
|
+
|
7
|
+
def initialize(comp)
|
8
|
+
@comp = comp
|
9
|
+
if comp.compare_flags != nil
|
10
|
+
comp.p = comp.compare_flags.parent if comp.compare_flags.parent != nil
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
protected
|
15
|
+
|
16
|
+
attr_accessor :comp
|
17
|
+
attr_accessor :indexes
|
18
|
+
|
19
|
+
public
|
20
|
+
|
21
|
+
def run
|
22
|
+
if self.use_sql
|
23
|
+
@comp.completed = true
|
24
|
+
return false
|
25
|
+
end
|
26
|
+
more = self.compare_core
|
27
|
+
while(more && @comp.run_to_completion)
|
28
|
+
more = self.compare_core
|
29
|
+
end
|
30
|
+
!more
|
31
|
+
end
|
32
|
+
|
33
|
+
def align
|
34
|
+
while(!@comp.completed)
|
35
|
+
self.run
|
36
|
+
end
|
37
|
+
alignment = ::Coopy::Alignment.new
|
38
|
+
self.align_core(alignment)
|
39
|
+
alignment.comp = @comp
|
40
|
+
@comp.alignment = alignment
|
41
|
+
alignment
|
42
|
+
end
|
43
|
+
|
44
|
+
def get_comparison_state
|
45
|
+
@comp
|
46
|
+
end
|
47
|
+
|
48
|
+
protected
|
49
|
+
|
50
|
+
def align_core(align)
|
51
|
+
if self.use_sql
|
52
|
+
tab1 = nil
|
53
|
+
tab2 = nil
|
54
|
+
tab3 = nil
|
55
|
+
if @comp.p == nil
|
56
|
+
tab1 = @comp.a
|
57
|
+
tab2 = @comp.b
|
58
|
+
else
|
59
|
+
align.reference = ::Coopy::Alignment.new
|
60
|
+
tab1 = @comp.p
|
61
|
+
tab2 = @comp.b
|
62
|
+
tab3 = @comp.a
|
63
|
+
end
|
64
|
+
db = nil
|
65
|
+
db = tab1.get_database if tab1 != nil
|
66
|
+
db = tab2.get_database if db == nil && tab2 != nil
|
67
|
+
db = tab3.get_database if db == nil && tab3 != nil
|
68
|
+
sc = ::Coopy::SqlCompare.new(db,tab1,tab2,tab3,align)
|
69
|
+
sc.apply
|
70
|
+
align.meta.reference = align.reference.meta if @comp.p != nil
|
71
|
+
return
|
72
|
+
end
|
73
|
+
if @comp.p == nil
|
74
|
+
self.align_core2(align,@comp.a,@comp.b)
|
75
|
+
return
|
76
|
+
end
|
77
|
+
align.reference = ::Coopy::Alignment.new
|
78
|
+
self.align_core2(align,@comp.p,@comp.b)
|
79
|
+
self.align_core2(align.reference,@comp.p,@comp.a)
|
80
|
+
align.meta.reference = align.reference.meta
|
81
|
+
end
|
82
|
+
|
83
|
+
def align_core2(align,a,b)
|
84
|
+
align.meta = ::Coopy::Alignment.new if align.meta == nil
|
85
|
+
self.align_columns(align.meta,a,b)
|
86
|
+
column_order = align.meta.to_order
|
87
|
+
align.range(a.get_height,b.get_height)
|
88
|
+
align.tables(a,b)
|
89
|
+
align.set_rowlike(true)
|
90
|
+
w = a.get_width
|
91
|
+
ha = a.get_height
|
92
|
+
hb = b.get_height
|
93
|
+
av = a.get_cell_view
|
94
|
+
ids = nil
|
95
|
+
ignore = nil
|
96
|
+
if @comp.compare_flags != nil
|
97
|
+
ids = @comp.compare_flags.ids
|
98
|
+
ignore = @comp.compare_flags.get_ignored_columns
|
99
|
+
end
|
100
|
+
common_units = Array.new
|
101
|
+
ra_header = align.get_source_header
|
102
|
+
rb_header = align.get_source_header
|
103
|
+
begin
|
104
|
+
_g = 0
|
105
|
+
_g1 = column_order.get_list
|
106
|
+
while(_g < _g1.length)
|
107
|
+
unit = _g1[_g]
|
108
|
+
_g+=1
|
109
|
+
if unit.l >= 0 && unit.r >= 0 && unit.p != -1
|
110
|
+
if ignore != nil
|
111
|
+
if unit.l >= 0 && ra_header >= 0 && ra_header < a.get_height
|
112
|
+
name = av.to_s(a.get_cell(unit.l,ra_header))
|
113
|
+
next if ignore.include?(name)
|
114
|
+
end
|
115
|
+
if unit.r >= 0 && rb_header >= 0 && rb_header < b.get_height
|
116
|
+
name1 = av.to_s(b.get_cell(unit.r,rb_header))
|
117
|
+
next if ignore.include?(name1)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
common_units.push(unit)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
index_top = nil
|
125
|
+
pending_ct = ha
|
126
|
+
reverse_pending_ct = hb
|
127
|
+
used = {}
|
128
|
+
used_reverse = {}
|
129
|
+
if ids != nil
|
130
|
+
index_top = ::Coopy::IndexPair.new(@comp.compare_flags)
|
131
|
+
ids_as_map = {}
|
132
|
+
begin
|
133
|
+
_g2 = 0
|
134
|
+
while(_g2 < ids.length)
|
135
|
+
id = ids[_g2]
|
136
|
+
_g2+=1
|
137
|
+
begin
|
138
|
+
ids_as_map[id] = true
|
139
|
+
true
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
begin
|
144
|
+
_g3 = 0
|
145
|
+
while(_g3 < common_units.length)
|
146
|
+
unit1 = common_units[_g3]
|
147
|
+
_g3+=1
|
148
|
+
na = av.to_s(a.get_cell(unit1.l,0))
|
149
|
+
nb = av.to_s(b.get_cell(unit1.r,0))
|
150
|
+
if ids_as_map.include?(na) || ids_as_map.include?(nb)
|
151
|
+
index_top.add_columns(unit1.l,unit1.r)
|
152
|
+
align.add_index_columns(unit1)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
index_top.index_tables(a,b,1)
|
157
|
+
@indexes.push(index_top) if @indexes != nil
|
158
|
+
begin
|
159
|
+
_g4 = 0
|
160
|
+
while(_g4 < ha)
|
161
|
+
j = _g4
|
162
|
+
_g4+=1
|
163
|
+
cross = index_top.query_local(j)
|
164
|
+
spot_a = cross.spot_a
|
165
|
+
spot_b = cross.spot_b
|
166
|
+
next if spot_a != 1 || spot_b != 1
|
167
|
+
jb = cross.item_b.lst[0]
|
168
|
+
align.link(j,jb)
|
169
|
+
used[jb] = 1
|
170
|
+
reverse_pending_ct-=1 if !used_reverse.include?(j)
|
171
|
+
used_reverse[j] = 1
|
172
|
+
end
|
173
|
+
end
|
174
|
+
else
|
175
|
+
n = 5
|
176
|
+
columns = Array.new
|
177
|
+
if common_units.length > n
|
178
|
+
columns_eval = Array.new
|
179
|
+
begin
|
180
|
+
_g11 = 0
|
181
|
+
_g5 = common_units.length
|
182
|
+
while(_g11 < _g5)
|
183
|
+
i = _g11
|
184
|
+
_g11+=1
|
185
|
+
ct = 0
|
186
|
+
mem = {}
|
187
|
+
mem2 = {}
|
188
|
+
ca = common_units[i].l
|
189
|
+
cb = common_units[i].r
|
190
|
+
begin
|
191
|
+
_g21 = 0
|
192
|
+
while(_g21 < ha)
|
193
|
+
j1 = _g21
|
194
|
+
_g21+=1
|
195
|
+
key = av.to_s(a.get_cell(ca,j1))
|
196
|
+
if !mem.include?(key)
|
197
|
+
mem[key] = 1
|
198
|
+
ct+=1
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
begin
|
203
|
+
_g22 = 0
|
204
|
+
while(_g22 < hb)
|
205
|
+
j2 = _g22
|
206
|
+
_g22+=1
|
207
|
+
key1 = av.to_s(b.get_cell(cb,j2))
|
208
|
+
if !mem2.include?(key1)
|
209
|
+
mem2[key1] = 1
|
210
|
+
ct+=1
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
columns_eval.push([i,ct])
|
215
|
+
end
|
216
|
+
end
|
217
|
+
sorter = lambda {|a1,b1|
|
218
|
+
return 1 if a1[1] < b1[1]
|
219
|
+
return -1 if a1[1] > b1[1]
|
220
|
+
return 1 if a1[0] > b1[0]
|
221
|
+
return -1 if a1[0] < b1[0]
|
222
|
+
0
|
223
|
+
}
|
224
|
+
columns_eval.sort!{|a,b| sorter.call(a,b)}
|
225
|
+
columns = Lambda.array(Lambda.map(columns_eval,lambda {|v|
|
226
|
+
v[0]
|
227
|
+
}))
|
228
|
+
columns = columns.slice(0,n - 1)
|
229
|
+
else
|
230
|
+
_g12 = 0
|
231
|
+
_g6 = common_units.length
|
232
|
+
while(_g12 < _g6)
|
233
|
+
i1 = _g12
|
234
|
+
_g12+=1
|
235
|
+
columns.push(i1)
|
236
|
+
end
|
237
|
+
end
|
238
|
+
top = nil
|
239
|
+
begin
|
240
|
+
v1 = 2 ** columns.length
|
241
|
+
top = v1.round
|
242
|
+
end
|
243
|
+
pending = {}
|
244
|
+
begin
|
245
|
+
_g7 = 0
|
246
|
+
while(_g7 < ha)
|
247
|
+
j3 = _g7
|
248
|
+
_g7+=1
|
249
|
+
pending[j3] = j3
|
250
|
+
end
|
251
|
+
end
|
252
|
+
added_columns = {}
|
253
|
+
index_ct = 0
|
254
|
+
begin
|
255
|
+
_g8 = 0
|
256
|
+
while(_g8 < top)
|
257
|
+
k = _g8
|
258
|
+
_g8+=1
|
259
|
+
next if k == 0
|
260
|
+
break if pending_ct == 0
|
261
|
+
active_columns = Array.new
|
262
|
+
kk = k
|
263
|
+
at = 0
|
264
|
+
while(kk > 0)
|
265
|
+
active_columns.push(columns[at]) if kk.remainder(2) == 1
|
266
|
+
kk >>= 1
|
267
|
+
at+=1
|
268
|
+
end
|
269
|
+
index = ::Coopy::IndexPair.new(@comp.compare_flags)
|
270
|
+
begin
|
271
|
+
_g23 = 0
|
272
|
+
_g13 = active_columns.length
|
273
|
+
while(_g23 < _g13)
|
274
|
+
k1 = _g23
|
275
|
+
_g23+=1
|
276
|
+
col = active_columns[k1]
|
277
|
+
unit2 = common_units[col]
|
278
|
+
index.add_columns(unit2.l,unit2.r)
|
279
|
+
if !added_columns.include?(col)
|
280
|
+
align.add_index_columns(unit2)
|
281
|
+
added_columns[col] = true
|
282
|
+
end
|
283
|
+
end
|
284
|
+
end
|
285
|
+
index.index_tables(a,b,1)
|
286
|
+
index_top = index if k == top - 1
|
287
|
+
h = a.get_height
|
288
|
+
h = b.get_height if b.get_height > h
|
289
|
+
h = 1 if h < 1
|
290
|
+
wide_top_freq = index.get_top_freq
|
291
|
+
ratio = wide_top_freq
|
292
|
+
ratio /= h + 20
|
293
|
+
if ratio >= 0.1
|
294
|
+
next if index_ct > 0 || k < top - 1
|
295
|
+
end
|
296
|
+
index_ct+=1
|
297
|
+
@indexes.push(index) if @indexes != nil
|
298
|
+
fixed = Array.new
|
299
|
+
_it = ::Rb::RubyIterator.new(pending.keys)
|
300
|
+
while(_it.has_next) do
|
301
|
+
j4 = _it._next
|
302
|
+
cross1 = index.query_local(j4)
|
303
|
+
spot_a1 = cross1.spot_a
|
304
|
+
spot_b1 = cross1.spot_b
|
305
|
+
next if spot_a1 != 1 || spot_b1 != 1
|
306
|
+
val = cross1.item_b.lst[0]
|
307
|
+
if !used.include?(val)
|
308
|
+
fixed.push(j4)
|
309
|
+
align.link(j4,val)
|
310
|
+
used[val] = 1
|
311
|
+
reverse_pending_ct-=1 if !used_reverse.include?(j4)
|
312
|
+
used_reverse[j4] = 1
|
313
|
+
end
|
314
|
+
end
|
315
|
+
begin
|
316
|
+
_g24 = 0
|
317
|
+
_g14 = fixed.length
|
318
|
+
while(_g24 < _g14)
|
319
|
+
j5 = _g24
|
320
|
+
_g24+=1
|
321
|
+
pending.delete(fixed[j5])
|
322
|
+
pending_ct-=1
|
323
|
+
end
|
324
|
+
end
|
325
|
+
end
|
326
|
+
end
|
327
|
+
end
|
328
|
+
if index_top != nil
|
329
|
+
offset = 0
|
330
|
+
scale = 1
|
331
|
+
begin
|
332
|
+
_g9 = 0
|
333
|
+
while(_g9 < 2)
|
334
|
+
sgn = _g9
|
335
|
+
_g9+=1
|
336
|
+
if pending_ct > 0
|
337
|
+
xb = nil
|
338
|
+
xb = hb - 1 if scale == -1 && hb > 0
|
339
|
+
begin
|
340
|
+
_g15 = 0
|
341
|
+
while(_g15 < ha)
|
342
|
+
xa0 = _g15
|
343
|
+
_g15+=1
|
344
|
+
xa = xa0 * scale + offset
|
345
|
+
xb2 = align.a2b(xa)
|
346
|
+
if xb2 != nil
|
347
|
+
xb = xb2 + scale
|
348
|
+
break if xb >= hb || xb < 0
|
349
|
+
next
|
350
|
+
end
|
351
|
+
next if xb == nil
|
352
|
+
ka = index_top.local_key(xa)
|
353
|
+
kb = index_top.remote_key(xb)
|
354
|
+
next if ka != kb
|
355
|
+
next if used.include?(xb)
|
356
|
+
align.link(xa,xb)
|
357
|
+
used[xb] = 1
|
358
|
+
used_reverse[xa] = 1
|
359
|
+
pending_ct-=1
|
360
|
+
xb += scale
|
361
|
+
break if xb >= hb || xb < 0
|
362
|
+
break if pending_ct == 0
|
363
|
+
end
|
364
|
+
end
|
365
|
+
end
|
366
|
+
offset = ha - 1
|
367
|
+
scale = -1
|
368
|
+
end
|
369
|
+
end
|
370
|
+
offset = 0
|
371
|
+
scale = 1
|
372
|
+
begin
|
373
|
+
_g10 = 0
|
374
|
+
while(_g10 < 2)
|
375
|
+
sgn1 = _g10
|
376
|
+
_g10+=1
|
377
|
+
if reverse_pending_ct > 0
|
378
|
+
xa1 = nil
|
379
|
+
xa1 = ha - 1 if scale == -1 && ha > 0
|
380
|
+
begin
|
381
|
+
_g16 = 0
|
382
|
+
while(_g16 < hb)
|
383
|
+
xb0 = _g16
|
384
|
+
_g16+=1
|
385
|
+
xb1 = xb0 * scale + offset
|
386
|
+
xa2 = align.b2a(xb1)
|
387
|
+
if xa2 != nil
|
388
|
+
xa1 = xa2 + scale
|
389
|
+
break if xa1 >= ha || xa1 < 0
|
390
|
+
next
|
391
|
+
end
|
392
|
+
next if xa1 == nil
|
393
|
+
ka1 = index_top.local_key(xa1)
|
394
|
+
kb1 = index_top.remote_key(xb1)
|
395
|
+
next if ka1 != kb1
|
396
|
+
next if used_reverse.include?(xa1)
|
397
|
+
align.link(xa1,xb1)
|
398
|
+
used[xb1] = 1
|
399
|
+
used_reverse[xa1] = 1
|
400
|
+
reverse_pending_ct-=1
|
401
|
+
xa1 += scale
|
402
|
+
break if xa1 >= ha || xa1 < 0
|
403
|
+
break if reverse_pending_ct == 0
|
404
|
+
end
|
405
|
+
end
|
406
|
+
end
|
407
|
+
offset = hb - 1
|
408
|
+
scale = -1
|
409
|
+
end
|
410
|
+
end
|
411
|
+
end
|
412
|
+
begin
|
413
|
+
_g17 = 1
|
414
|
+
while(_g17 < ha)
|
415
|
+
i2 = _g17
|
416
|
+
_g17+=1
|
417
|
+
align.link(i2,-1) if !used_reverse.include?(i2)
|
418
|
+
end
|
419
|
+
end
|
420
|
+
begin
|
421
|
+
_g18 = 1
|
422
|
+
while(_g18 < hb)
|
423
|
+
i3 = _g18
|
424
|
+
_g18+=1
|
425
|
+
align.link(-1,i3) if !used.include?(i3)
|
426
|
+
end
|
427
|
+
end
|
428
|
+
if ha > 0 && hb > 0
|
429
|
+
align.link(0,0)
|
430
|
+
align.headers(0,0)
|
431
|
+
end
|
432
|
+
end
|
433
|
+
|
434
|
+
def align_columns(align,a,b)
|
435
|
+
align.range(a.get_width,b.get_width)
|
436
|
+
align.tables(a,b)
|
437
|
+
align.set_rowlike(false)
|
438
|
+
slop = 5
|
439
|
+
va = a.get_cell_view
|
440
|
+
vb = b.get_cell_view
|
441
|
+
ra_best = 0
|
442
|
+
rb_best = 0
|
443
|
+
ct_best = -1
|
444
|
+
ma_best = nil
|
445
|
+
mb_best = nil
|
446
|
+
ra_header = 0
|
447
|
+
rb_header = 0
|
448
|
+
ra_uniques = 0
|
449
|
+
rb_uniques = 0
|
450
|
+
begin
|
451
|
+
_g = 0
|
452
|
+
while(_g < slop)
|
453
|
+
ra = _g
|
454
|
+
_g+=1
|
455
|
+
begin
|
456
|
+
_g1 = 0
|
457
|
+
while(_g1 < slop)
|
458
|
+
rb1 = _g1
|
459
|
+
_g1+=1
|
460
|
+
ma = {}
|
461
|
+
mb = {}
|
462
|
+
ct = 0
|
463
|
+
uniques = 0
|
464
|
+
if ra < a.get_height
|
465
|
+
begin
|
466
|
+
_g3 = 0
|
467
|
+
_g2 = a.get_width
|
468
|
+
while(_g3 < _g2)
|
469
|
+
ca = _g3
|
470
|
+
_g3+=1
|
471
|
+
key = va.to_s(a.get_cell(ca,ra))
|
472
|
+
if ma.include?(key)
|
473
|
+
ma[key] = -1
|
474
|
+
uniques-=1
|
475
|
+
else
|
476
|
+
ma[key] = ca
|
477
|
+
uniques+=1
|
478
|
+
end
|
479
|
+
end
|
480
|
+
end
|
481
|
+
if uniques > ra_uniques
|
482
|
+
ra_header = ra
|
483
|
+
ra_uniques = uniques
|
484
|
+
end
|
485
|
+
end
|
486
|
+
uniques = 0
|
487
|
+
if rb1 < b.get_height
|
488
|
+
begin
|
489
|
+
_g31 = 0
|
490
|
+
_g21 = b.get_width
|
491
|
+
while(_g31 < _g21)
|
492
|
+
cb = _g31
|
493
|
+
_g31+=1
|
494
|
+
key1 = vb.to_s(b.get_cell(cb,rb1))
|
495
|
+
if mb.include?(key1)
|
496
|
+
mb[key1] = -1
|
497
|
+
uniques-=1
|
498
|
+
else
|
499
|
+
mb[key1] = cb
|
500
|
+
uniques+=1
|
501
|
+
end
|
502
|
+
end
|
503
|
+
end
|
504
|
+
if uniques > rb_uniques
|
505
|
+
rb_header = rb1
|
506
|
+
rb_uniques = uniques
|
507
|
+
end
|
508
|
+
end
|
509
|
+
_it = ::Rb::RubyIterator.new(ma.keys)
|
510
|
+
while(_it.has_next) do
|
511
|
+
key2 = _it._next
|
512
|
+
i0 = ma[key2]
|
513
|
+
i1 = mb[key2]
|
514
|
+
if i1 != nil
|
515
|
+
ct+=1 if i1 >= 0 && i0 >= 0
|
516
|
+
end
|
517
|
+
end
|
518
|
+
if ct > ct_best
|
519
|
+
ct_best = ct
|
520
|
+
ma_best = ma
|
521
|
+
mb_best = mb
|
522
|
+
ra_best = ra
|
523
|
+
rb_best = rb1
|
524
|
+
end
|
525
|
+
end
|
526
|
+
end
|
527
|
+
end
|
528
|
+
end
|
529
|
+
if ma_best == nil
|
530
|
+
if a.get_height > 0 && b.get_height == 0
|
531
|
+
align.headers(0,-1)
|
532
|
+
elsif a.get_height == 0 && b.get_height > 0
|
533
|
+
align.headers(-1,0)
|
534
|
+
end
|
535
|
+
return
|
536
|
+
end
|
537
|
+
_it2 = ::Rb::RubyIterator.new(ma_best.keys)
|
538
|
+
while(_it2.has_next) do
|
539
|
+
key3 = _it2._next
|
540
|
+
i01 = ma_best[key3]
|
541
|
+
i11 = mb_best[key3]
|
542
|
+
if i01 != nil && i11 != nil
|
543
|
+
align.link(i01,i11)
|
544
|
+
elsif i01 != nil
|
545
|
+
align.link(i01,-1)
|
546
|
+
elsif i11 != nil
|
547
|
+
align.link(-1,i11)
|
548
|
+
end
|
549
|
+
end
|
550
|
+
_it3 = ::Rb::RubyIterator.new(mb_best.keys)
|
551
|
+
while(_it3.has_next) do
|
552
|
+
key4 = _it3._next
|
553
|
+
i02 = ma_best[key4]
|
554
|
+
i12 = mb_best[key4]
|
555
|
+
align.link(-1,i12) if i02 == nil && i12 != nil
|
556
|
+
end
|
557
|
+
align.headers(ra_header,rb_header)
|
558
|
+
end
|
559
|
+
|
560
|
+
def test_has_same_columns
|
561
|
+
p = @comp.p
|
562
|
+
a = @comp.a
|
563
|
+
b = @comp.b
|
564
|
+
eq = self.has_same_columns2(a,b)
|
565
|
+
eq = self.has_same_columns2(p,a) if eq && p != nil
|
566
|
+
@comp.has_same_columns = eq
|
567
|
+
@comp.has_same_columns_known = true
|
568
|
+
true
|
569
|
+
end
|
570
|
+
|
571
|
+
def has_same_columns2(a,b)
|
572
|
+
return false if a.get_width != b.get_width
|
573
|
+
return true if a.get_height == 0 || b.get_height == 0
|
574
|
+
av = a.get_cell_view
|
575
|
+
begin
|
576
|
+
_g1 = 0
|
577
|
+
_g = a.get_width
|
578
|
+
while(_g1 < _g)
|
579
|
+
i = _g1
|
580
|
+
_g1+=1
|
581
|
+
begin
|
582
|
+
_g3 = i + 1
|
583
|
+
_g2 = a.get_width
|
584
|
+
while(_g3 < _g2)
|
585
|
+
j = _g3
|
586
|
+
_g3+=1
|
587
|
+
return false if av.equals(a.get_cell(i,0),a.get_cell(j,0))
|
588
|
+
end
|
589
|
+
end
|
590
|
+
return false if !av.equals(a.get_cell(i,0),b.get_cell(i,0))
|
591
|
+
end
|
592
|
+
end
|
593
|
+
true
|
594
|
+
end
|
595
|
+
|
596
|
+
def test_is_equal
|
597
|
+
p = @comp.p
|
598
|
+
a = @comp.a
|
599
|
+
b = @comp.b
|
600
|
+
@comp.get_meta
|
601
|
+
nested = false
|
602
|
+
if @comp.p_meta != nil
|
603
|
+
nested = true if @comp.p_meta.is_nested
|
604
|
+
end
|
605
|
+
if @comp.a_meta != nil
|
606
|
+
nested = true if @comp.a_meta.is_nested
|
607
|
+
end
|
608
|
+
if @comp.b_meta != nil
|
609
|
+
nested = true if @comp.b_meta.is_nested
|
610
|
+
end
|
611
|
+
if nested
|
612
|
+
@comp.is_equal = false
|
613
|
+
@comp.is_equal_known = true
|
614
|
+
return true
|
615
|
+
end
|
616
|
+
eq = self.is_equal2(a,b)
|
617
|
+
eq = self.is_equal2(p,a) if eq && p != nil
|
618
|
+
@comp.is_equal = eq
|
619
|
+
@comp.is_equal_known = true
|
620
|
+
true
|
621
|
+
end
|
622
|
+
|
623
|
+
def is_equal2(a,b)
|
624
|
+
return false if a.get_width != b.get_width || a.get_height != b.get_height
|
625
|
+
av = a.get_cell_view
|
626
|
+
begin
|
627
|
+
_g1 = 0
|
628
|
+
_g = a.get_height
|
629
|
+
while(_g1 < _g)
|
630
|
+
i = _g1
|
631
|
+
_g1+=1
|
632
|
+
begin
|
633
|
+
_g3 = 0
|
634
|
+
_g2 = a.get_width
|
635
|
+
while(_g3 < _g2)
|
636
|
+
j = _g3
|
637
|
+
_g3+=1
|
638
|
+
return false if !av.equals(a.get_cell(j,i),b.get_cell(j,i))
|
639
|
+
end
|
640
|
+
end
|
641
|
+
end
|
642
|
+
end
|
643
|
+
true
|
644
|
+
end
|
645
|
+
|
646
|
+
def compare_core
|
647
|
+
return false if @comp.completed
|
648
|
+
return self.test_is_equal if !@comp.is_equal_known
|
649
|
+
return self.test_has_same_columns if !@comp.has_same_columns_known
|
650
|
+
@comp.completed = true
|
651
|
+
false
|
652
|
+
end
|
653
|
+
|
654
|
+
public
|
655
|
+
|
656
|
+
def store_indexes
|
657
|
+
@indexes = Array.new
|
658
|
+
end
|
659
|
+
|
660
|
+
def get_indexes
|
661
|
+
@indexes
|
662
|
+
end
|
663
|
+
|
664
|
+
protected
|
665
|
+
|
666
|
+
def use_sql
|
667
|
+
return false if @comp.compare_flags == nil
|
668
|
+
@comp.get_meta
|
669
|
+
sql = true
|
670
|
+
if @comp.p_meta != nil
|
671
|
+
sql = false if !@comp.p_meta.is_sql
|
672
|
+
end
|
673
|
+
if @comp.a_meta != nil
|
674
|
+
sql = false if !@comp.a_meta.is_sql
|
675
|
+
end
|
676
|
+
if @comp.b_meta != nil
|
677
|
+
sql = false if !@comp.b_meta.is_sql
|
678
|
+
end
|
679
|
+
sql = false if @comp.p != nil && @comp.p_meta == nil
|
680
|
+
sql = false if @comp.a != nil && @comp.a_meta == nil
|
681
|
+
sql = false if @comp.b != nil && @comp.b_meta == nil
|
682
|
+
sql
|
683
|
+
end
|
684
|
+
|
685
|
+
haxe_me ["coopy", "CompareTable"]
|
686
|
+
end
|
687
|
+
|
688
|
+
end
|