Skip to content

Commit

Permalink
Broke out upper left and lower right map computations; simplified sor…
Browse files Browse the repository at this point in the history
…ting.
  • Loading branch information
emeryberger committed Aug 9, 2019
1 parent 0ac275a commit 6c1c691
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 48 deletions.
1 change: 1 addition & 0 deletions src/components/colorize.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ var Colorize = /** @class */ (function () {
};
Colorize.generate_proposed_fixes = function (groups) {
var t = new timer_1.Timer("generate_proposed_fixes");
t.split("about to find.");
var proposed_fixes_new = groupme_1.find_all_proposed_fixes(groups);
t.split("sorting fixes.");
proposed_fixes_new.sort(function (a, b) { return a[0] - b[0]; });
Expand Down
1 change: 1 addition & 0 deletions src/components/colorize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ export class Colorize {
public static generate_proposed_fixes(groups: { [val: string]: Array<[excelintVector, excelintVector]> }):
Array<[number, [excelintVector, excelintVector], [excelintVector, excelintVector]]> {
let t = new Timer("generate_proposed_fixes");
t.split("about to find.");
let proposed_fixes_new = find_all_proposed_fixes(groups);
t.split("sorting fixes.");
proposed_fixes_new.sort((a, b) => { return a[0] - b[0]; });
Expand Down
50 changes: 26 additions & 24 deletions src/components/groupme.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,24 @@ function sort_y_coord(a, b) {
}
}
function fix_grouped_formulas(g, newGnum) {
var newGstr = {};
for (var _i = 0, _a = Object.keys(g); _i < _a.length; _i++) {
var i = _a[_i];
// The below is maybe too inefficient; possibly revisit.
newGstr[i] = g[i].map(function (p, _1, _2) { return fix_pair(p); });
newGstr[i].sort(sort_x_coord);
newGnum[i] = newGstr[i].map(function (x, _1, _2) {
return [x[0].map(function (a, _1, _2) { return Number(a); }),
x[1].map(function (a, _1, _2) { return Number(a); })];
});
if (true) {
newGnum[i] = g[i].sort(sort_x_coord).map(function (x, _1, _2) {
return [x[0].map(function (a, _1, _2) { return Number(a); }),
x[1].map(function (a, _1, _2) { return Number(a); })];
});
}
else {
// The below is maybe too inefficient; possibly revisit.
var newGstr = {};
newGstr[i] = g[i].map(function (p, _1, _2) { return fix_pair(p); });
newGstr[i].sort(sort_x_coord);
newGnum[i] = newGstr[i].map(function (x, _1, _2) {
return [x[0].map(function (a, _1, _2) { return Number(a); }),
x[1].map(function (a, _1, _2) { return Number(a); })];
});
}
}
}
// Knuth-Fisher-Yates shuffle (not currently used).
Expand All @@ -74,17 +82,6 @@ function numComparator(a_val, b_val) {
}
}
return 0;
var a = JSON.stringify(fix_array(a_val));
var b = JSON.stringify(fix_array(b_val));
comparisons++;
// console.log("Comparing " + JSON.stringify(a) + " to " + JSON.stringify(b));
if (a === b) {
return 0;
}
if (a < b) {
return -1;
}
return 1;
}
function matching_rectangles(rect_ul, rect_lr, rect_uls, rect_lrs) {
// Assumes uls and lrs are already sorted and the same length.
Expand Down Expand Up @@ -145,7 +142,7 @@ function matching_rectangles(rect_ul, rect_lr, rect_uls, rect_lrs) {
return matches;
}
var rectangles_count = 0;
function find_all_matching_rectangles(thisKey, rect, grouped_formulas) {
function find_all_matching_rectangles(thisKey, rect, grouped_formulas, x_ul, x_lr) {
var base_ul = rect[0], base_lr = rect[1];
// console.log("Looking for matches of " + JSON.stringify(base_ul) + ", " + JSON.stringify(base_lr));
var match_list = [];
Expand All @@ -159,9 +156,7 @@ function find_all_matching_rectangles(thisKey, rect, grouped_formulas) {
// if (true) { // rectangles_count % 1000 === 0) {
console.log("find_all_matching_rectangles, iteration " + rectangles_count);
}
var x_ul = a[key].map(function (i, _1, _2) { var p1 = i[0], p2 = i[1]; return p1; });
var x_lr = a[key].map(function (i, _1, _2) { var p1 = i[0], p2 = i[1]; return p2; });
var matches = matching_rectangles(base_ul, base_lr, x_ul, x_lr);
var matches = matching_rectangles(base_ul, base_lr, x_ul[key], x_lr[key]);
if (matches.length > 0) {
// console.log("found matches for key "+key+" --> " + JSON.stringify(matches));
}
Expand All @@ -188,10 +183,17 @@ function find_all_proposed_fixes(grouped_formulas) {
rectangles_count = 0;
var aNum = {};
fix_grouped_formulas(grouped_formulas, aNum);
var x_ul = {};
var x_lr = {};
for (var _i = 0, _a = Object.keys(grouped_formulas); _i < _a.length; _i++) {
var key = _a[_i];
x_ul[key] = aNum[key].map(function (i, _1, _2) { var p1 = i[0], p2 = i[1]; return p1; });
x_lr[key] = aNum[key].map(function (i, _1, _2) { var p1 = i[0], p2 = i[1]; return p2; });
}
for (var _b = 0, _c = Object.keys(grouped_formulas); _b < _c.length; _b++) {
var key = _c[_b];
for (var i = 0; i < aNum[key].length; i++) {
var matches = find_all_matching_rectangles(key, aNum[key][i], aNum);
var matches = find_all_matching_rectangles(key, aNum[key][i], aNum, x_ul, x_lr);
all_matches = all_matches.concat(matches);
count++;
if (count % 1000 == 0) {
Expand Down
47 changes: 23 additions & 24 deletions src/components/groupme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,19 @@ function sort_y_coord(a,b) {
}

function fix_grouped_formulas(g, newGnum) {
let newGstr = {};
for (let i of Object.keys(g)) {
// The below is maybe too inefficient; possibly revisit.
newGstr[i] = g[i].map((p, _1, _2) => { return fix_pair(p); });
newGstr[i].sort(sort_x_coord);
newGnum[i] = newGstr[i].map((x,_1,_2) => { return [x[0].map((a,_1,_2) => Number(a)),
x[1].map((a,_1,_2) => Number(a))]; });
if (true) {
newGnum[i] = g[i].sort(sort_x_coord).map((x,_1,_2) =>
{ return [x[0].map((a,_1,_2) => Number(a)),
x[1].map((a,_1,_2) => Number(a))]; });
} else {
// The below is maybe too inefficient; possibly revisit.
let newGstr = {};
newGstr[i] = g[i].map((p, _1, _2) => { return fix_pair(p); });
newGstr[i].sort(sort_x_coord);
newGnum[i] = newGstr[i].map((x,_1,_2) => { return [x[0].map((a,_1,_2) => Number(a)),
x[1].map((a,_1,_2) => Number(a))]; });
}
}
}

Expand Down Expand Up @@ -81,19 +87,6 @@ function numComparator(a_val : excelintVector, b_val: excelintVector) {
}
}
return 0;


let a = JSON.stringify(fix_array(a_val));
let b = JSON.stringify(fix_array(b_val));
comparisons++;
// console.log("Comparing " + JSON.stringify(a) + " to " + JSON.stringify(b));
if (a === b) {
return 0;
}
if (a < b) {
return -1;
}
return 1;
}

function matching_rectangles(rect_ul: excelintVector,
Expand Down Expand Up @@ -166,7 +159,9 @@ let rectangles_count = 0;

function find_all_matching_rectangles(thisKey: string,
rect: [excelintVector, excelintVector],
grouped_formulas: { [val: string]: Array<[excelintVector, excelintVector]> }) : Array<[number, [excelintVector, excelintVector]]>
grouped_formulas: { [val: string]: Array<[excelintVector, excelintVector]> },
x_ul : { [val: string]: Array<excelintVector> },
x_lr : { [val: string]: Array<excelintVector> }) : Array<[number, [excelintVector, excelintVector]]>
{
const [base_ul, base_lr] = rect;
// console.log("Looking for matches of " + JSON.stringify(base_ul) + ", " + JSON.stringify(base_lr));
Expand All @@ -181,9 +176,7 @@ function find_all_matching_rectangles(thisKey: string,
// if (true) { // rectangles_count % 1000 === 0) {
console.log("find_all_matching_rectangles, iteration " + rectangles_count);
}
const x_ul = a[key].map((i,_1,_2) => { let [p1,p2] = i; return p1;});
const x_lr = a[key].map((i,_1,_2) => { let [p1,p2] = i; return p2;});
const matches = matching_rectangles(base_ul, base_lr, x_ul, x_lr);
const matches = matching_rectangles(base_ul, base_lr, x_ul[key], x_lr[key]);
if (matches.length > 0) {
// console.log("found matches for key "+key+" --> " + JSON.stringify(matches));
}
Expand All @@ -210,9 +203,15 @@ export function find_all_proposed_fixes(grouped_formulas : { [val: string]: Arra
rectangles_count = 0;
let aNum = {};
fix_grouped_formulas(grouped_formulas, aNum);
let x_ul = {};
let x_lr = {};
for (let key of Object.keys(grouped_formulas)) {
x_ul[key] = aNum[key].map((i,_1,_2) => { let [p1,p2] = i; return p1;});
x_lr[key] = aNum[key].map((i,_1,_2) => { let [p1,p2] = i; return p2;});
}
for (let key of Object.keys(grouped_formulas)) {
for (let i = 0; i < aNum[key].length; i++) {
const matches = find_all_matching_rectangles(key, aNum[key][i], aNum);
const matches = find_all_matching_rectangles(key, aNum[key][i], aNum, x_ul, x_lr);
all_matches = all_matches.concat(matches);
count++;
if (count % 1000 == 0) {
Expand Down

0 comments on commit 6c1c691

Please sign in to comment.