@@ -60,42 +60,38 @@ export type kUnknownNullCount = -1;
60
60
export const kUnknownNullCount = - 1 ;
61
61
62
62
export class BaseData < T extends DataType = DataType > implements VectorLike {
63
- protected _type : T ;
64
- protected _length : number ;
65
- protected _offset : number ;
63
+ public type : T ;
64
+ public length : number ;
65
+ public offset : number ;
66
66
// @ts -ignore
67
- protected _childData : Data < any > [ ] ;
67
+ public childData : Data < any > [ ] ;
68
68
protected _nullCount : number | kUnknownNullCount ;
69
69
protected /* [VectorType.OFFSET]:*/ 0 ?: Int32Array ;
70
70
protected /* [VectorType.DATA]:*/ 1 ?: T [ 'TArray' ] ;
71
71
protected /*[VectorType.VALIDITY]:*/ 2 ?: Uint8Array ;
72
72
protected /* [VectorType.TYPE]:*/ 3 ?: Int8Array ;
73
73
constructor ( type : T , length : number , offset ?: number , nullCount ?: number ) {
74
- this . _type = type ;
75
- this . _length = Math . floor ( Math . max ( length || 0 , 0 ) ) ;
76
- this . _offset = Math . floor ( Math . max ( offset || 0 , 0 ) ) ;
74
+ this . type = type ;
75
+ this . length = Math . floor ( Math . max ( length || 0 , 0 ) ) ;
76
+ this . offset = Math . floor ( Math . max ( offset || 0 , 0 ) ) ;
77
77
this . _nullCount = Math . floor ( Math . max ( nullCount || 0 , - 1 ) ) ;
78
78
}
79
- public get type ( ) { return this . _type ; }
80
- public get length ( ) { return this . _length ; }
81
- public get offset ( ) { return this . _offset ; }
82
- public get typeId ( ) { return this . _type . TType ; }
83
- public get childData ( ) { return this . _childData ; }
79
+ public get typeId ( ) { return this . type . TType ; }
84
80
public get nullBitmap ( ) { return this [ VectorType . VALIDITY ] ; }
85
81
public get nullCount ( ) {
86
82
let nullCount = this . _nullCount ;
87
83
let nullBitmap : Uint8Array | undefined ;
88
84
if ( nullCount === - 1 && ( nullBitmap = this [ VectorType . VALIDITY ] ) ) {
89
- this . _nullCount = nullCount = this . _length - popcnt_bit_range ( nullBitmap , this . _offset , this . _offset + this . _length ) ;
85
+ this . _nullCount = nullCount = this . length - popcnt_bit_range ( nullBitmap , this . offset , this . offset + this . length ) ;
90
86
}
91
87
return nullCount ;
92
88
}
93
- public clone < R extends T > ( type : R , length = this . _length , offset = this . _offset , nullCount = this . _nullCount ) {
89
+ public clone < R extends T > ( type : R , length = this . length , offset = this . offset , nullCount = this . _nullCount ) {
94
90
return new BaseData ( type , length , offset , nullCount ) ;
95
91
}
96
92
public slice ( offset : number , length : number ) {
97
93
return length <= 0 ? this : this . sliceInternal ( this . clone (
98
- this . _type , length , this . _offset + offset , + ( this . _nullCount === 0 ) - 1
94
+ this . type , length , this . offset + offset , + ( this . _nullCount === 0 ) - 1
99
95
) as any , offset , length ) ;
100
96
}
101
97
protected sliceInternal ( clone : this, offset : number , length : number ) {
@@ -125,8 +121,8 @@ export class FlatData<T extends FlatType> extends BaseData<T> {
125
121
this [ VectorType . DATA ] = toTypedArray ( this . ArrayType , data ) ;
126
122
this [ VectorType . VALIDITY ] = toTypedArray ( Uint8Array , nullBitmap ) ;
127
123
}
128
- public get ArrayType ( ) : T [ 'ArrayType' ] { return this . _type . ArrayType ; }
129
- public clone < R extends T > ( type : R , length = this . _length , offset = this . _offset , nullCount = this . _nullCount ) {
124
+ public get ArrayType ( ) : T [ 'ArrayType' ] { return this . type . ArrayType ; }
125
+ public clone < R extends T > ( type : R , length = this . length , offset = this . offset , nullCount = this . _nullCount ) {
130
126
return new ( this . constructor as any ) ( type , length , this [ VectorType . VALIDITY ] , this [ VectorType . DATA ] , offset , nullCount ) as FlatData < R > ;
131
127
}
132
128
}
@@ -145,7 +141,7 @@ export class FlatListData<T extends FlatListType> extends FlatData<T> {
145
141
super ( type , length , nullBitmap , data , offset , nullCount ) ;
146
142
this [ VectorType . OFFSET ] = toTypedArray ( Int32Array , valueOffsets ) ;
147
143
}
148
- public clone < R extends T > ( type : R , length = this . _length , offset = this . _offset , nullCount = this . _nullCount ) {
144
+ public clone < R extends T > ( type : R , length = this . length , offset = this . offset , nullCount = this . _nullCount ) {
149
145
return new FlatListData ( type , length , this [ VectorType . VALIDITY ] , this [ VectorType . OFFSET ] , this [ VectorType . DATA ] , offset , nullCount ) ;
150
146
}
151
147
}
@@ -159,19 +155,19 @@ export class DictionaryData<T extends DataType> extends BaseData<Dictionary<T>>
159
155
super ( type , indicies . length , ( indicies as any ) . _nullCount ) ;
160
156
this . _indicies = indicies ;
161
157
this . _dictionary = dictionary ;
158
+ this . length = this . _indicies . length ;
162
159
}
163
- public get length ( ) { return this . _indicies . length ; }
164
160
public get nullCount ( ) { return this . _indicies . nullCount ; }
165
- public clone < R extends Dictionary < T > > ( type : R , length = this . _length , offset = this . _offset ) {
161
+ public clone < R extends Dictionary < T > > ( type : R , length = this . length , offset = this . offset ) {
166
162
const data = this . _dictionary . data . clone ( type . dictionary as any ) ;
167
163
return new DictionaryData < R > (
168
- this . _type as any ,
164
+ this . type as any ,
169
165
this . _dictionary . clone ( data ) as any ,
170
- this . _indicies . slice ( offset - this . _offset , length )
166
+ this . _indicies . slice ( offset - this . offset , length )
171
167
) as any ;
172
168
}
173
169
protected sliceInternal ( clone : this, _offset : number , _length : number ) {
174
- clone . _length = clone . _indicies . length ;
170
+ clone . length = clone . _indicies . length ;
175
171
clone . _nullCount = ( clone . _indicies as any ) . _nullCount ;
176
172
return clone ;
177
173
}
@@ -181,15 +177,15 @@ export class NestedData<T extends NestedType = NestedType> extends BaseData<T> {
181
177
public /*[VectorType.VALIDITY]:*/ 2 : Uint8Array ;
182
178
constructor ( type : T , length : number , nullBitmap : Uint8Array | null | undefined , childData : Data < any > [ ] , offset ?: number , nullCount ?: number ) {
183
179
super ( type , length , offset , nullCount ) ;
184
- this . _childData = childData ;
180
+ this . childData = childData ;
185
181
this [ VectorType . VALIDITY ] = toTypedArray ( Uint8Array , nullBitmap ) ;
186
182
}
187
- public clone < R extends T > ( type : R , length = this . _length , offset = this . _offset , nullCount = this . _nullCount ) {
188
- return new NestedData < R > ( type , length , this [ VectorType . VALIDITY ] , this . _childData , offset , nullCount ) ;
183
+ public clone < R extends T > ( type : R , length = this . length , offset = this . offset , nullCount = this . _nullCount ) {
184
+ return new NestedData < R > ( type , length , this [ VectorType . VALIDITY ] , this . childData , offset , nullCount ) ;
189
185
}
190
186
protected sliceInternal ( clone : this, offset : number , length : number ) {
191
187
if ( ! this [ VectorType . OFFSET ] ) {
192
- clone . _childData = this . _childData . map ( ( child ) => child . slice ( offset , length ) ) ;
188
+ clone . childData = this . childData . map ( ( child ) => child . slice ( offset , length ) ) ;
193
189
}
194
190
return super . sliceInternal ( clone , offset , length ) ;
195
191
}
@@ -212,7 +208,7 @@ export class ListData<T extends ListType> extends SingleNestedData<T> {
212
208
super ( type , length , nullBitmap , valueChildData , offset , nullCount ) ;
213
209
this [ VectorType . OFFSET ] = toTypedArray ( Int32Array , valueOffsets ) ;
214
210
}
215
- public clone < R extends T > ( type : R , length = this . _length , offset = this . _offset , nullCount = this . _nullCount ) {
211
+ public clone < R extends T > ( type : R , length = this . length , offset = this . offset , nullCount = this . _nullCount ) {
216
212
return new ListData < R > ( type , length , this [ VectorType . VALIDITY ] , this [ VectorType . OFFSET ] , this . _valuesData as any , offset , nullCount ) ;
217
213
}
218
214
}
@@ -224,22 +220,22 @@ export class UnionData<T extends (DenseUnion | SparseUnion) = any> extends Neste
224
220
super ( type , length , nullBitmap , childData , offset , nullCount ) ;
225
221
this [ VectorType . TYPE ] = toTypedArray ( Int8Array , typeIds ) ;
226
222
}
227
- public clone < R extends T > ( type : R , length = this . _length , offset = this . _offset , nullCount = this . _nullCount ) {
228
- return new UnionData < R > ( type , length , this [ VectorType . VALIDITY ] , this [ VectorType . TYPE ] , this . _childData , offset , nullCount ) ;
223
+ public clone < R extends T > ( type : R , length = this . length , offset = this . offset , nullCount = this . _nullCount ) {
224
+ return new UnionData < R > ( type , length , this [ VectorType . VALIDITY ] , this [ VectorType . TYPE ] , this . childData , offset , nullCount ) ;
229
225
}
230
226
}
231
227
232
228
export class SparseUnionData extends UnionData < SparseUnion > {
233
229
constructor ( type : SparseUnion , length : number , nullBitmap : Uint8Array | null | undefined , typeIds : Iterable < number > , childData : Data < any > [ ] , offset ?: number , nullCount ?: number ) {
234
230
super ( type , length , nullBitmap , typeIds , childData , offset , nullCount ) ;
235
231
}
236
- public clone < R extends SparseUnion > ( type : R , length = this . _length , offset = this . _offset , nullCount = this . _nullCount ) {
232
+ public clone < R extends SparseUnion > ( type : R , length = this . length , offset = this . offset , nullCount = this . _nullCount ) {
237
233
return new SparseUnionData (
238
234
type ,
239
235
length ,
240
236
this [ VectorType . VALIDITY ] ,
241
237
this [ VectorType . TYPE ] ,
242
- this . _childData ,
238
+ this . childData ,
243
239
offset , nullCount
244
240
) as any as UnionData < R > ;
245
241
}
@@ -252,50 +248,52 @@ export class DenseUnionData extends UnionData<DenseUnion> {
252
248
super ( type , length , nullBitmap , typeIds , childData , offset , nullCount ) ;
253
249
this [ VectorType . OFFSET ] = toTypedArray ( Int32Array , valueOffsets ) ;
254
250
}
255
- public clone < R extends DenseUnion > ( type : R , length = this . _length , offset = this . _offset , nullCount = this . _nullCount ) {
251
+ public clone < R extends DenseUnion > ( type : R , length = this . length , offset = this . offset , nullCount = this . _nullCount ) {
256
252
return new DenseUnionData (
257
253
type ,
258
254
length ,
259
255
this [ VectorType . VALIDITY ] ,
260
256
this [ VectorType . TYPE ] ,
261
257
this [ VectorType . OFFSET ] ,
262
- this . _childData ,
258
+ this . childData ,
263
259
offset , nullCount
264
260
) as any as UnionData < R > ;
265
261
}
266
262
}
267
263
268
264
export class ChunkedData < T extends DataType > extends BaseData < T > {
269
- protected _childVectors : Vector < T > [ ] ;
270
- protected _childOffsets : Uint32Array ;
271
- public get childVectors ( ) { return this . _childVectors ; }
272
- public get childOffsets ( ) { return this . _childOffsets ; }
273
- public get childData ( ) {
274
- return this . _childData || (
275
- this . _childData = this . _childVectors . map ( ( { data } ) => data ) ) ;
276
- }
277
- constructor ( type : T , length : number , childVectors : Vector < T > [ ] , offset ?: number , nullCount ?: number , childOffsets ?: Uint32Array ) {
265
+ // @ts -ignore
266
+ protected _chunkData : Data < T > [ ] ;
267
+ protected _chunkVectors : Vector < T > [ ] ;
268
+ protected _chunkOffsets : Uint32Array ;
269
+ public get chunkVectors ( ) { return this . _chunkVectors ; }
270
+ public get chunkOffsets ( ) { return this . _chunkOffsets ; }
271
+ public get chunkData ( ) {
272
+ return this . _chunkData || (
273
+ this . _chunkData = this . _chunkVectors . map ( ( { data } ) => data ) ) ;
274
+ }
275
+ constructor ( type : T , length : number , chunkVectors : Vector < T > [ ] , offset ?: number , nullCount ?: number , chunkOffsets ?: Uint32Array ) {
278
276
super ( type , length , offset , nullCount ) ;
279
- this . _childVectors = childVectors ;
280
- this . _childOffsets = childOffsets || ChunkedData . computeOffsets ( childVectors ) ;
277
+ this . _chunkVectors = chunkVectors ;
278
+ this . _chunkOffsets = chunkOffsets || ChunkedData . computeOffsets ( chunkVectors ) ;
281
279
}
282
280
public get nullCount ( ) {
283
281
let nullCount = this . _nullCount ;
284
282
if ( nullCount === - 1 ) {
285
- this . _nullCount = nullCount = this . _childVectors . reduce ( ( x , c ) => x + c . nullCount , 0 ) ;
283
+ this . _nullCount = nullCount = this . _chunkVectors . reduce ( ( x , c ) => x + c . nullCount , 0 ) ;
286
284
}
287
285
return nullCount ;
288
286
}
289
- public clone < R extends T > ( type : R , length = this . _length , offset = this . _offset , nullCount = this . _nullCount ) {
287
+ public clone < R extends T > ( type : R , length = this . length , offset = this . offset , nullCount = this . _nullCount ) {
290
288
return new ChunkedData < R > (
291
289
type , length ,
292
- this . _childVectors . map ( ( vec ) => vec . clone ( vec . data . clone ( type ) ) ) as any ,
293
- offset , nullCount , this . _childOffsets
290
+ this . _chunkVectors . map ( ( vec ) => vec . clone ( vec . data . clone ( type ) ) ) as any ,
291
+ offset , nullCount , this . _chunkOffsets
294
292
) ;
295
293
}
296
294
protected sliceInternal ( clone : this, offset : number , length : number ) {
297
- const chunks = this . _childVectors ;
298
- const offsets = this . _childOffsets ;
295
+ const chunks = this . _chunkVectors ;
296
+ const offsets = this . _chunkOffsets ;
299
297
const chunkSlices : Vector < T > [ ] = [ ] ;
300
298
for ( let childIndex = - 1 , numChildren = chunks . length ; ++ childIndex < numChildren ; ) {
301
299
const child = chunks [ childIndex ] ;
@@ -315,8 +313,8 @@ export class ChunkedData<T extends DataType> extends BaseData<T> {
315
313
const end = begin + Math . min ( childLength - begin , ( offset + length ) - childOffset ) ;
316
314
chunkSlices . push ( child . slice ( begin , end ) ) ;
317
315
}
318
- clone . _childVectors = chunkSlices ;
319
- clone . _childOffsets = ChunkedData . computeOffsets ( chunkSlices ) ;
316
+ clone . _chunkVectors = chunkSlices ;
317
+ clone . _chunkOffsets = ChunkedData . computeOffsets ( chunkSlices ) ;
320
318
return clone ;
321
319
}
322
320
static computeOffsets < T extends DataType > ( childVectors : Vector < T > [ ] ) {
0 commit comments