Skip to content

Commit

Permalink
bugfix creating wrong index size array
Browse files Browse the repository at this point in the history
  • Loading branch information
sgratzl committed Dec 25, 2018
1 parent 76de7e1 commit 60143fd
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/internal/math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -626,11 +626,11 @@ export function createIndexArray(length: number, dataSize = length) {
/**
* @internal
*/
export function toIndexArray(arr: ISequence<number> | IndicesArray): UIntTypedArray {
export function toIndexArray(arr: ISequence<number> | IndicesArray, maxDataIndex?: number): UIntTypedArray {
if (arr instanceof Uint8Array || arr instanceof Uint16Array || arr instanceof Uint32Array) {
return arr.slice();
}
const l = arr.length;
const l = maxDataIndex != null ? maxDataIndex : arr.length;
if (l <= 255) {
return Uint8Array.from(arr);
}
Expand Down
8 changes: 4 additions & 4 deletions src/provider/DirectRenderTasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {CompareLookup} from './sort';
/**
* @internal
*/
export function sortDirect(indices: IndicesArray, lookups?: CompareLookup) {
const order = toIndexArray(indices);
export function sortDirect(indices: IndicesArray, maxDataIndex: number, lookups?: CompareLookup) {
const order = toIndexArray(indices, maxDataIndex);
if (lookups) {
sortComplex(order, lookups.sortOrders);
}
Expand Down Expand Up @@ -79,8 +79,8 @@ export class DirectRenderTasks extends ARenderTasks implements IRenderTaskExectu
}
}

sort(_ranking: Ranking, _group: IGroup, indices: IndicesArray, _singleCall: boolean, lookups?: CompareLookup) {
return Promise.resolve(sortDirect(indices, lookups));
sort(_ranking: Ranking, _group: IGroup, indices: IndicesArray, _singleCall: boolean, maxDataIndex: number, lookups?: CompareLookup) {
return Promise.resolve(sortDirect(indices, maxDataIndex, lookups));
}

groupCompare(ranking: Ranking, group: IGroup, rows: IndicesArray) {
Expand Down
15 changes: 8 additions & 7 deletions src/provider/LocalDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,14 @@ export default class LocalDataProvider extends ACommonDataProvider {
private noSorting(ranking: Ranking) {
// initial no sorting required just index mapping
const l = this._data.length;
const order = createIndexArray(l);
const order = createIndexArray(l, l - 1);
const index2pos = order.slice();
for (let i = 0; i < l; ++i) {
order[i] = i;
index2pos[i] = i + 1; // shift since default is 0
}

this.tasks.preCompute(ranking, [{rows: order, group: defaultGroup}]);
this.tasks.preCompute(ranking, [{rows: order, group: defaultGroup}], l - 1);
return {groups: [Object.assign({order}, defaultGroup)], index2pos};
}

Expand Down Expand Up @@ -361,10 +361,10 @@ export default class LocalDataProvider extends ACommonDataProvider {
return {maxDataIndex, lookups, groupOrder};
}

private sortGroup(g: ISortHelper, i: number, ranking: Ranking, lookups: CompareLookup | undefined, groupLookup: CompareLookup | undefined, singleGroup: boolean): Promise<IOrderedGroup> {
private sortGroup(g: ISortHelper, i: number, ranking: Ranking, lookups: CompareLookup | undefined, groupLookup: CompareLookup | undefined, singleGroup: boolean, maxDataIndex: number): Promise<IOrderedGroup> {
const group = g.group;

const sortTask = this.tasks.sort(ranking, group, g.rows, singleGroup, lookups);
const sortTask = this.tasks.sort(ranking, group, g.rows, singleGroup, maxDataIndex, lookups);

// compute sort group value as task
const groupSortTask = groupLookup ? this.tasks.groupCompare(ranking, group, g.rows).then((r) => r) : <ICompareValue[]>[];
Expand All @@ -391,7 +391,8 @@ export default class LocalDataProvider extends ACommonDataProvider {
}

private index2pos(groups: IOrderedGroup[], maxDataIndex: number) {
const index2pos = createIndexArray(maxDataIndex + 1);
const total = groups.reduce((a, b) => a + b.order.length, 1);
const index2pos = createIndexArray(maxDataIndex + 1, total);
let offset = 1;
for (const g of groups) {
// tslint:disable-next-line
Expand Down Expand Up @@ -452,7 +453,7 @@ export default class LocalDataProvider extends ACommonDataProvider {
const g = groupOrder[0]!;

// not required if: group sort criteria changed -> lookups will be none
return this.sortGroup(g, 0, ranking, lookups, undefined, true).then((group) => {
return this.sortGroup(g, 0, ranking, lookups, undefined, true, maxDataIndex).then((group) => {
return this.index2pos([group], maxDataIndex);
});
}
Expand All @@ -461,7 +462,7 @@ export default class LocalDataProvider extends ACommonDataProvider {

return Promise.all(groupOrder.map((g, i) => {
// not required if: group sort criteria changed -> lookups will be none
return this.sortGroup(g, i, ranking, lookups, groupLookup, false);
return this.sortGroup(g, i, ranking, lookups, groupLookup, false, maxDataIndex);
})).then((groups) => {
// not required if: sort criteria changed -> groupLookup will be none
const sortedGroups = this.sortGroups(groups, groupLookup);
Expand Down
6 changes: 3 additions & 3 deletions src/provider/ScheduledTasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,14 +488,14 @@ export class ScheduleRenderTasks extends ARenderTasks implements IRenderTaskExec
return this.cached(`${col.id}:c:data`, false, this.dateStatsBuilder<IDateStatistics>(null, col));
}

sort(ranking: Ranking, group: IGroup, indices: IndicesArray, singleCall: boolean, lookups?: CompareLookup) {
sort(ranking: Ranking, group: IGroup, indices: IndicesArray, singleCall: boolean, maxDataIndex: number, lookups?: CompareLookup) {
if (!lookups || indices.length < 1000) {
// no thread needed
const order = sortDirect(indices, lookups);
const order = sortDirect(indices, maxDataIndex, lookups);
return Promise.resolve(order);
}

const indexArray = toIndexArray(indices);
const indexArray = toIndexArray(indices, maxDataIndex);
const toTransfer = [indexArray.buffer];

if (singleCall) {
Expand Down
2 changes: 1 addition & 1 deletion src/provider/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export interface IRenderTaskExectutor extends IRenderTasks {
copyData2Summary(ranking: Ranking): void;
copyCache(col: Column, from: Column): void;

sort(ranking: Ranking, group: IGroup, indices: IndicesArray, singleCall: boolean, lookups?: CompareLookup): Promise<IndicesArray>;
sort(ranking: Ranking, group: IGroup, indices: IndicesArray, singleCall: boolean, maxDataIndex: number, lookups?: CompareLookup): Promise<IndicesArray>;

terminate(): void;

Expand Down

0 comments on commit 60143fd

Please sign in to comment.