Skip to content

Commit

Permalink
Minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Hulette committed Jan 12, 2018
1 parent 2e118ab commit 2f4a349
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
17 changes: 10 additions & 7 deletions js/src/predicate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ export abstract class Value<T> {
}
}

class Literal<T= any> extends Value<T> {
export class Literal<T= any> extends Value<T> {
constructor(public v: T) { super(); }
}

class Col<T= any> extends Value<T> {
export class Col<T= any> extends Value<T> {
vector: Vector<T>;
colidx: number;

Expand Down Expand Up @@ -55,7 +55,7 @@ export abstract class Predicate {
ands(): Predicate[] { return [this]; }
}

abstract class ComparisonPredicate<T= any> extends Predicate {
export abstract class ComparisonPredicate<T= any> extends Predicate {
constructor(public readonly left: Value<T>, public readonly right: Value<T>) {
super();
}
Expand Down Expand Up @@ -105,7 +105,7 @@ class Or extends CombinationPredicate {
}
}

class Equals extends ComparisonPredicate {
export class Equals extends ComparisonPredicate {
protected _bindLitLit(_: Vector<any>[], left: Literal, right: Literal): PredicateFunc {
const rtrn: boolean = left.v == right.v;
return () => rtrn;
Expand All @@ -121,6 +121,9 @@ class Equals extends ComparisonPredicate {
const col_func = col.bind(cols);
if (col.vector instanceof DictionaryVector) {
// Assume that there is only one key with the value `lit.v`
// TODO: add lazily-computed reverse dictionary lookups, associated
// with col.vector.data so that we only have to do this once per
// dictionary
let key = -1;
for (; ++key < col.vector.data.length;) {
if (col.vector.data.get(key) === lit.v) {
Expand All @@ -146,7 +149,7 @@ class Equals extends ComparisonPredicate {
}
}

class LTeq extends ComparisonPredicate {
export class LTeq extends ComparisonPredicate {
protected _bindLitLit(_: Vector<any>[], left: Literal, right: Literal): PredicateFunc {
const rtrn: boolean = left.v <= right.v;
return () => rtrn;
Expand All @@ -164,7 +167,7 @@ class LTeq extends ComparisonPredicate {
}
}

class GTeq extends ComparisonPredicate {
export class GTeq extends ComparisonPredicate {
protected _bindLitLit(_: Vector<any>[], left: Literal, right: Literal): PredicateFunc {
const rtrn: boolean = left.v >= right.v;
return () => rtrn;
Expand All @@ -183,4 +186,4 @@ class GTeq extends ComparisonPredicate {
}

export function lit(n: number): Value<any> { return new Literal(n); }
export function col(n: string): Value<any> { return new Col(n); }
export function col(n: string): Col<any> { return new Col(n); }
21 changes: 7 additions & 14 deletions js/src/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ export class TableRow {
}

export interface DataFrame {
readonly batches: Vector[][];
readonly lengths: Uint32Array;
filter(predicate: Predicate): DataFrame;
scan(next: NextFunc): void;
count(): number;
Expand Down Expand Up @@ -129,23 +127,18 @@ export class Table implements DataFrame {
}

class FilteredDataFrame implements DataFrame {
readonly lengths: Uint32Array;
readonly batches: Vector[][];
constructor (readonly parent: DataFrame, private predicate: Predicate) {
this.batches = parent.batches;
this.lengths = parent.lengths;
}
constructor (readonly parent: Table, private predicate: Predicate) {}

scan(next: NextFunc) {
// inlined version of this:
// this.parent.scan((idx, columns) => {
// if (this.predicate(idx, columns)) next(idx, columns);
// });
for (let batch = -1; ++batch < this.lengths.length;) {
const length = this.lengths[batch];
for (let batch = -1; ++batch < this.parent.lengths.length;) {
const length = this.parent.lengths[batch];

// load batches
const columns = this.batches[batch];
const columns = this.parent.batches[batch];
const predicate = this.predicate.bind(columns);

// yield all indices
Expand All @@ -163,11 +156,11 @@ class FilteredDataFrame implements DataFrame {
// });
// return sum;
let sum = 0;
for (let batch = -1; ++batch < this.lengths.length;) {
const length = this.lengths[batch];
for (let batch = -1; ++batch < this.parent.lengths.length;) {
const length = this.parent.lengths[batch];

// load batches
const columns = this.batches[batch];
const columns = this.parent.batches[batch];
const predicate = this.predicate.bind(columns);

// yield all indices
Expand Down

0 comments on commit 2f4a349

Please sign in to comment.