202131 patch by dwitte@stanford.edu r=mvl@exedo.nl sr=darin BubbleSort is too slow

This commit is contained in:
cbiesinger%web.de 2003-04-18 17:34:02 +00:00
parent dbd672f841
commit bdfabf0708
3 changed files with 57 additions and 66 deletions

View File

@ -123,7 +123,25 @@ function SortTree(tree, view, table, column, lastSortColumn, lastSortAscending)
var ascending = (column == lastSortColumn) ? !lastSortAscending : true;
// do the sort
BubbleSort(column, ascending, table);
var compareFunc;
if (ascending) {
compareFunc = function compare(first, second) {
if (first[column] < second[column])
return 1;
if (first[column] > second[column])
return -1;
return 0;
}
} else {
compareFunc = function compare(first, second) {
if (first[column] < second[column])
return -1;
if (first[column] > second[column])
return 1;
return 0;
}
}
table.sort(compareFunc);
// restore the selection
var selectedRow = -1;
@ -148,24 +166,3 @@ function SortTree(tree, view, table, column, lastSortColumn, lastSortAscending)
return ascending;
}
function BubbleSort(columnName, ascending, table) {
var len = table.length, len_1 = len - 1;
for (var i = 0; i < len_1; i++) {
var key = table[i][columnName];
var winner = -1;
for (var j = i + 1; j < len; j++) {
var nextKey = table[j][columnName];
if (ascending ? key > nextKey : key < nextKey) {
key = nextKey;
winner = j;
}
}
if (winner != -1){
var temp = table[i];
table[i] = table[winner];
table[winner] = temp;
}
}
}

View File

@ -123,7 +123,25 @@ function SortTree(tree, view, table, column, lastSortColumn, lastSortAscending)
var ascending = (column == lastSortColumn) ? !lastSortAscending : true;
// do the sort
BubbleSort(column, ascending, table);
var compareFunc;
if (ascending) {
compareFunc = function compare(first, second) {
if (first[column] < second[column])
return 1;
if (first[column] > second[column])
return -1;
return 0;
}
} else {
compareFunc = function compare(first, second) {
if (first[column] < second[column])
return -1;
if (first[column] > second[column])
return 1;
return 0;
}
}
table.sort(compareFunc);
// restore the selection
var selectedRow = -1;
@ -148,24 +166,3 @@ function SortTree(tree, view, table, column, lastSortColumn, lastSortAscending)
return ascending;
}
function BubbleSort(columnName, ascending, table) {
var len = table.length, len_1 = len - 1;
for (var i = 0; i < len_1; i++) {
var key = table[i][columnName];
var winner = -1;
for (var j = i + 1; j < len; j++) {
var nextKey = table[j][columnName];
if (ascending ? key > nextKey : key < nextKey) {
key = nextKey;
winner = j;
}
}
if (winner != -1){
var temp = table[i];
table[i] = table[winner];
table[winner] = temp;
}
}
}

View File

@ -123,7 +123,25 @@ function SortTree(tree, view, table, column, lastSortColumn, lastSortAscending)
var ascending = (column == lastSortColumn) ? !lastSortAscending : true;
// do the sort
BubbleSort(column, ascending, table);
var compareFunc;
if (ascending) {
compareFunc = function compare(first, second) {
if (first[column] < second[column])
return 1;
if (first[column] > second[column])
return -1;
return 0;
}
} else {
compareFunc = function compare(first, second) {
if (first[column] < second[column])
return -1;
if (first[column] > second[column])
return 1;
return 0;
}
}
table.sort(compareFunc);
// restore the selection
var selectedRow = -1;
@ -148,24 +166,3 @@ function SortTree(tree, view, table, column, lastSortColumn, lastSortAscending)
return ascending;
}
function BubbleSort(columnName, ascending, table) {
var len = table.length, len_1 = len - 1;
for (var i = 0; i < len_1; i++) {
var key = table[i][columnName];
var winner = -1;
for (var j = i + 1; j < len; j++) {
var nextKey = table[j][columnName];
if (ascending ? key > nextKey : key < nextKey) {
key = nextKey;
winner = j;
}
}
if (winner != -1){
var temp = table[i];
table[i] = table[winner];
table[winner] = temp;
}
}
}