Skip to content

Commit

Permalink
slice the flat data values before returning an iterator of them
Browse files Browse the repository at this point in the history
  • Loading branch information
trxcllnt committed Jan 24, 2018
1 parent e537789 commit fe31ee0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
2 changes: 1 addition & 1 deletion js/src/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class BaseData<T extends DataType = DataType> implements VectorLike {
let nullCount = this._nullCount;
let nullBitmap: Uint8Array | undefined;
if (nullCount === -1 && (nullBitmap = this[VectorType.VALIDITY])) {
this._nullCount = nullCount = popcnt_bit_range(nullBitmap, this._offset, this._offset + this._length);
this._nullCount = nullCount = this._length - popcnt_bit_range(nullBitmap, this._offset, this._offset + this._length);
}
return nullCount;
}
Expand Down
22 changes: 16 additions & 6 deletions js/src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ export abstract class DataType<TType extends Type = any> implements Partial<Visi

export interface Null extends DataType<Type.Null> { TArray: void; TValue: null; }
export class Null extends DataType<Type.Null> {
constructor() { super(Type.Null); }
constructor() {
super(Type.Null);
}
public toString() { return `Null`; }
public acceptTypeVisitor(visitor: TypeVisitor): any {
return visitor.visitNull(this);
Expand Down Expand Up @@ -269,7 +271,9 @@ export class Float64 extends Float<Float64Array> { constructor() { super(Precisi

export interface Binary extends DataType<Type.Binary> { TArray: Uint8Array; TValue: Uint8Array; }
export class Binary extends DataType<Type.Binary> {
constructor() { super(Type.Binary); }
constructor() {
super(Type.Binary);
}
public toString() { return `Binary`; }
public acceptTypeVisitor(visitor: TypeVisitor): any {
return visitor.visitBinary(this);
Expand All @@ -282,7 +286,9 @@ export class Binary extends DataType<Type.Binary> {

export interface Utf8 extends DataType<Type.Utf8> { TArray: Uint8Array; TValue: string; }
export class Utf8 extends DataType<Type.Utf8> {
constructor() { super(Type.Utf8); }
constructor() {
super(Type.Utf8);
}
public toString() { return `Utf8`; }
public acceptTypeVisitor(visitor: TypeVisitor): any {
return visitor.visitUtf8(this);
Expand All @@ -295,7 +301,9 @@ export class Utf8 extends DataType<Type.Utf8> {

export interface Bool extends DataType<Type.Bool> { TArray: Uint8Array; TValue: boolean; }
export class Bool extends DataType<Type.Bool> {
constructor() { super(Type.Bool); }
constructor() {
super(Type.Bool);
}
public toString() { return `Bool`; }
public acceptTypeVisitor(visitor: TypeVisitor): any {
return visitor.visitBool(this);
Expand Down Expand Up @@ -325,7 +333,9 @@ export class Decimal extends DataType<Type.Decimal> {
/* tslint:disable:class-name */
export interface Date_ extends DataType<Type.Date> { TArray: Int32Array; TValue: Date; }
export class Date_ extends DataType<Type.Date> {
constructor(public readonly unit: DateUnit) { super(Type.Date); }
constructor(public readonly unit: DateUnit) {
super(Type.Date);
}
public toString() { return `Date${(this.unit + 1) * 32}<${DateUnit[this.unit]}>`; }
public acceptTypeVisitor(visitor: TypeVisitor): any {
return visitor.visitDate(this);
Expand Down Expand Up @@ -485,7 +495,7 @@ export class Map_ extends DataType<Type.Map> {
public toString() { return `Map<${this.children.join(`, `)}>`; }
public acceptTypeVisitor(visitor: TypeVisitor): any { return visitor.visitMap(this); }
protected static [Symbol.toStringTag] = ((proto: Map_) => {
return proto[Symbol.toStringTag] = 'Map';
return proto[Symbol.toStringTag] = 'Map_';
})(Map_.prototype);
}

Expand Down
8 changes: 5 additions & 3 deletions js/src/vector/flat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ export class FlatView<T extends FlatType> implements View<T> {
return this.values[index] = value;
}
public toArray(): IterableArrayLike<T['TValue']> {
return this.values;
return this.values.subarray(0, this.length);
}
public [Symbol.iterator](): IterableIterator<T['TValue']> {
return this.values[Symbol.iterator]() as IterableIterator<T['TValue']>;
return this.values.subarray(0, this.length)[Symbol.iterator]() as IterableIterator<T['TValue']>;
}
}

Expand Down Expand Up @@ -152,7 +152,9 @@ export class PrimitiveView<T extends PrimitiveType> extends FlatView<T> {
return this.setValue(this.values, index, this.size, value);
}
public toArray(): IterableArrayLike<T['TValue']> {
return this.size === 1 ? this.values : new this.ArrayType(this);
return this.size > 1 ?
new this.ArrayType(this) :
this.values.subarray(0, this.length);
}
public *[Symbol.iterator](): IterableIterator<T['TValue']> {
const get = this.getValue;
Expand Down
2 changes: 1 addition & 1 deletion js/src/vector/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export abstract class ListViewBase<T extends (ListType | FlatListType | FixedSiz

export abstract class VariableListViewBase<T extends (ListType | FlatListType)> extends ListViewBase<T> {
constructor(data: Data<T>) {
super(data)
super(data);
this.length = data.length;
this.valueOffsets = data.valueOffsets;
}
Expand Down

0 comments on commit fe31ee0

Please sign in to comment.