import { DataTypeFieldConfig, Maybe, SortOrder, ReadonlyDataTypeFields } from '@terascope/types'; import { ReadableData, WritableData } from '../core/index.js'; import { DataBuckets, SerializeOptions, VectorType } from './interfaces.js'; /** * An immutable typed Array class with a constrained API. */ export declare abstract class Vector { /** * Make an instance of a Vector from a config */ static make(data: DataBuckets, options: VectorOptions): Vector; /** * Sort the values in a Vector and return * an array with the updated indices. */ static getSortedIndices(sortBy: { vector: Vector; direction: SortOrder; }[]): number[]; /** * The name of field, if specified this will just be used for metadata */ readonly name?: string; /** * The type of Vector, this should only be set the specific Vector type classes. */ readonly type: VectorType; /** * The field type configuration */ readonly config: Readonly; /** * When Vector is an object type, this will be the data type fields * for the object */ readonly childConfig?: ReadonlyDataTypeFields; /** * A data type agnostic in-memory representation of the data * for a Vector and potential indices/unique values. Currently * there one ore more data buckets can be used. * * @note DO NOT MUTATE THESE IT WILL BREAK THE GUARANTEES OF * IMMUTABILITY AND WILL CREATE SIDE EFFECTS BETWEEN * DATA FRAMES * * @internal */ readonly data: readonly ReadableData[]; /** * If set to false, the Vector is not sortable */ sortable: boolean; /** * The cached size of the vector */ private __size; /** * The cached consistent size of the vector */ private __consistentSize; constructor( /** * This will be set automatically by specific Vector classes */ type: VectorType, data: DataBuckets, options: VectorOptions); /** * A function for converting an in-memory representation of * a value to an JSON spec compatible format. */ abstract toJSONCompatibleValue?(value: T, options?: SerializeOptions): any; /** * A function for converting an in-memory representation of * a value to an JSON spec compatible format. */ abstract getComparableValue?(value: T): any; /** * Returns the number items in the Vector */ get size(): number; /** * Sometimes when appending data buckets the size * is consistent, when that happens we can be * much smarter about find the data bucket for a * given row, which speeds up some operations */ private get _consistentSize(); private _setSizeAndConsistentSize; [Symbol.iterator](): IterableIterator>; /** * Check to see there are any nil values stored in the Vector */ hasNilValues(): boolean; /** * Get the number of non-nil values in the Vector */ countValues(): number; /** * Returns true if there are no non-nil values */ isEmpty(): boolean; /** * Iterate over the values and skip the nil ones, * returns tuples a with index and value */ values(): IterableIterator<[index: number, value: T]>; /** * Get the count of distinct values. * * @note this is O(1) for non-object types and O(n) + extra hashing logic for larger objects */ countUnique(): number; /** * Get the unique values with the index in a tuple form. * This is useful for reconstructing an Vector * with only the unique values */ unique(): Iterable<[index: number, value: T]>; /** * Get the unique values, excluding nil values. * Useful for getting a list of unique values. */ uniqueValues(): Iterable; /** * Add ReadableData to a end of the data buckets */ append(data: (ReadableData[]) | (readonly ReadableData[]) | ReadableData): Vector; /** * Add ReadableData to a beginning of the data buckets */ prepend(data: ReadableData[] | readonly ReadableData[] | ReadableData): Vector; /** * Get value by index */ get(index: number, json?: boolean, options?: SerializeOptions): Maybe; /** * Returns true if the value for that index is not nil */ has(index: number): boolean; /** * Find the Data bucket that holds the value for that * bucket * @returns the data found and the index of the relative index of value */ findDataWithIndex(index: number): [data: ReadableData, actualIndex: number] | undefined; /** * When data buckets all of have the same size we * can use an O(1) optimization to find the correct * bucket. This helps when there are 1000s of buckets */ private _findConsistentDataIndex; /** * Find the Data bucket that holds the value for that * bucket */ private _forwardFindDataWithIndex; /** * Find the Data bucket that holds the value for that * bucket this works the in the reverse direction, this * will perform better when there are lots of buckets */ private _reverseFindDataWithIndex; /** * Create a new Vector with the same metadata but with different data */ fork(_data: ReadableData[] | readonly ReadableData[]): this; /** * Create a new Vector with the range of values */ slice(start?: number, end?: number): Vector; /** * Compare two different values on the Vector type. * This can be used for equality or sorted. */ compare(a: Maybe, b: Maybe): -1 | 0 | 1; private _getComparableValue; /** * Convert the Vector an array of values (the output is JSON compatible) */ toJSON(options?: SerializeOptions): Maybe[]; /** * Convert the Vector to array of values (the in-memory representation of the data) * @note may not be JSON spec compatible */ toArray(): Maybe[]; /** * Fork the Data object with specific length. * * @param size optionally change the size of the Data */ toWritable(size?: number): WritableData; } /** * Returns true if the input is a Vector */ export declare function isVector(input: unknown): input is Vector; /** * A list of Vector Options */ export interface VectorOptions { /** * The field config */ config: DataTypeFieldConfig | Readonly; /** * The type config for any nested fields (currently only works for objects) */ childConfig?: ReadonlyDataTypeFields; /** * The name of field, if specified this will just be used for metadata */ name?: string; } //# sourceMappingURL=Vector.d.ts.map