structurae
Advanced tools
Comparing version
@@ -6,2 +6,8 @@ # Changelog | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
## [3.0.6] - 2020-04-28 | ||
### Changed | ||
- Use custom UTF8 encoding for StringView | ||
as a workaround to solve performance issues in V8 | ||
## [3.0.5] - 2020-04-07 | ||
@@ -8,0 +14,0 @@ ### Fixed |
846
index.d.ts
@@ -5,8 +5,23 @@ // Type definitions for structurae | ||
type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | | ||
Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array; | ||
type TypedArray = | ||
| Int8Array | ||
| Uint8Array | ||
| Uint8ClampedArray | ||
| Int16Array | ||
| Uint16Array | ||
| Int32Array | ||
| Uint32Array | ||
| Float32Array | ||
| Float64Array; | ||
type TypedArrayConstructor = Int8ArrayConstructor | Uint8ArrayConstructor | ||
| Uint8ClampedArrayConstructor | Int16Array | Uint16ArrayConstructor | Int32ArrayConstructor | ||
| Uint32ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor; | ||
type TypedArrayConstructor = | ||
| Int8ArrayConstructor | ||
| Uint8ArrayConstructor | ||
| Uint8ClampedArrayConstructor | ||
| Int16Array | ||
| Uint16ArrayConstructor | ||
| Int32ArrayConstructor | ||
| Uint32ArrayConstructor | ||
| Float32ArrayConstructor | ||
| Float64ArrayConstructor; | ||
@@ -18,39 +33,41 @@ type Collection = any[] | TypedArray; | ||
interface Constructor<T> { | ||
new (...args): T; | ||
new (...args): T; | ||
} | ||
interface GridOptions { | ||
rows: number; | ||
columns: number; | ||
pad?: any; | ||
rows: number; | ||
columns: number; | ||
pad?: any; | ||
} | ||
interface Coordinates { | ||
row: number; | ||
column: number; | ||
row: number; | ||
column: number; | ||
} | ||
declare class Grid { | ||
columns: number; | ||
rows: number; | ||
offset: number; | ||
pad: any; | ||
lastCoordinates: Coordinates; | ||
columns: number; | ||
rows: number; | ||
offset: number; | ||
pad: any; | ||
lastCoordinates: Coordinates; | ||
constructor(options?: GridOptions, ...args: any); | ||
get(row: number, column: number): any; | ||
set(row: number|ArrayLike<number>, column?: number, value?: any): this; | ||
setArray(array: Collection, offset: number): void; | ||
getCoordinates(index: number): Coordinates; | ||
toArrays(withPadding?: boolean): any[][]; | ||
static getOffset(columns: number): number; | ||
static getLength(rows: number, columns: number): number; | ||
static fromArrays(arrays: any[][], pad: any): Grid; | ||
constructor(options?: GridOptions, ...args: any); | ||
get(row: number, column: number): any; | ||
set(row: number | ArrayLike<number>, column?: number, value?: any): this; | ||
setArray(array: Collection, offset: number): void; | ||
getCoordinates(index: number): Coordinates; | ||
toArrays(withPadding?: boolean): any[][]; | ||
static getOffset(columns: number): number; | ||
static getLength(rows: number, columns: number): number; | ||
static fromArrays(arrays: any[][], pad: any): Grid; | ||
} | ||
export declare function GridMixin<T extends Collection>(Base?: Constructor<T>): Constructor<T & Grid> | ||
export declare function GridMixin<T extends Collection>( | ||
Base?: Constructor<T>, | ||
): Constructor<T & Grid>; | ||
interface BitPosition { | ||
bucket: number; | ||
position: number; | ||
bucket: number; | ||
position: number; | ||
} | ||
@@ -61,73 +78,74 @@ | ||
interface BinaryGridOptions { | ||
rows: number; | ||
columns: number; | ||
rows: number; | ||
columns: number; | ||
} | ||
export declare class BinaryGrid extends Uint16Array { | ||
offset: number; | ||
columns: number; | ||
rows: number; | ||
lastPosition: BitPosition; | ||
offset: number; | ||
columns: number; | ||
rows: number; | ||
lastPosition: BitPosition; | ||
constructor(options: BinaryGridOptions, ...args: any); | ||
get(row: number, column: number): Bit; | ||
set(row: number|ArrayLike<number>, column?: number, value?: Bit): this; | ||
private getBitPosition(row: number, column: number): BitPosition; | ||
static getLength(rows: number, columns: number): number; | ||
static getOffset(columns: number): number; | ||
constructor(options: BinaryGridOptions, ...args: any); | ||
get(row: number, column: number): Bit; | ||
set(row: number | ArrayLike<number>, column?: number, value?: Bit): this; | ||
private getBitPosition(row: number, column: number): BitPosition; | ||
static getLength(rows: number, columns: number): number; | ||
static getOffset(columns: number): number; | ||
} | ||
declare class SymmetricGrid { | ||
rows: number; | ||
columns: number; | ||
pad: any; | ||
lastCoordinates: Coordinates; | ||
rows: number; | ||
columns: number; | ||
pad: any; | ||
lastCoordinates: Coordinates; | ||
constructor(options?: GridOptions, ...args: any); | ||
get(row: number, column: number): any; | ||
set(row: number|ArrayLike<number>, column?: number, value?: any): this; | ||
setArray(array: Collection, offset: number): void; | ||
getCoordinates(index: number): Coordinates; | ||
toArrays(withPadding?: boolean): any[][]; | ||
static getLength(rows: number, columns: number): number; | ||
static fromArrays(arrays: any[][], pad: any): SymmetricGrid; | ||
constructor(options?: GridOptions, ...args: any); | ||
get(row: number, column: number): any; | ||
set(row: number | ArrayLike<number>, column?: number, value?: any): this; | ||
setArray(array: Collection, offset: number): void; | ||
getCoordinates(index: number): Coordinates; | ||
toArrays(withPadding?: boolean): any[][]; | ||
static getLength(rows: number, columns: number): number; | ||
static fromArrays(arrays: any[][], pad: any): SymmetricGrid; | ||
} | ||
export declare function SymmetricGridMixin<T extends Collection>(Base?: Constructor<T>): Constructor<T & SymmetricGrid> | ||
export declare function SymmetricGridMixin<T extends Collection>( | ||
Base?: Constructor<T>, | ||
): Constructor<T & SymmetricGrid>; | ||
type GridStructure = Grid | BinaryGrid | SymmetricGrid; | ||
type Matcher = [number, number]; | ||
interface NumberMap { | ||
[propName: string]: number; | ||
[propName: string]: number; | ||
} | ||
export declare class BitField { | ||
value: number; | ||
static schema: NumberMap; | ||
static size: number; | ||
static isInitialized: boolean; | ||
private static fields: string[]; | ||
private static masks: NumberMap; | ||
private static offsets: NumberMap; | ||
private static mask: number; | ||
value: number; | ||
static schema: NumberMap; | ||
static size: number; | ||
static isInitialized: boolean; | ||
private static fields: string[]; | ||
private static masks: NumberMap; | ||
private static offsets: NumberMap; | ||
private static mask: number; | ||
constructor(data?: number|BitField|number[]|NumberMap); | ||
get(field: string): number; | ||
set(field: string, value: number); | ||
has(...fields: string[]): boolean; | ||
match(matcher: Matcher|NumberMap): boolean; | ||
toJSON(): number; | ||
toObject(): NumberMap; | ||
toString(): string; | ||
valueOf(): number; | ||
static initialize(): void; | ||
static encode(data: number[]|NumberMap): number; | ||
static decode(data: number): NumberMap; | ||
static isValid(data: NumberMap): boolean; | ||
static getMinSize(number: number): number; | ||
static getMatcher(matcher: NumberMap): Matcher; | ||
static match(value: number, matcher: Matcher): boolean; | ||
constructor(data?: number | BitField | number[] | NumberMap); | ||
get(field: string): number; | ||
set(field: string, value: number); | ||
has(...fields: string[]): boolean; | ||
match(matcher: Matcher | NumberMap): boolean; | ||
toJSON(): number; | ||
toObject(): NumberMap; | ||
toString(): string; | ||
valueOf(): number; | ||
static initialize(): void; | ||
static encode(data: number[] | NumberMap): number; | ||
static decode(data: number): NumberMap; | ||
static isValid(data: NumberMap): boolean; | ||
static getMinSize(number: number): number; | ||
static getMatcher(matcher: NumberMap): Matcher; | ||
static match(value: number, matcher: Matcher): boolean; | ||
} | ||
@@ -138,34 +156,37 @@ | ||
interface BigIntMap { | ||
[propName: string]: bigint; | ||
[propName: string]: bigint; | ||
} | ||
export declare class BigBitField { | ||
value: bigint; | ||
static schema: BigIntMap; | ||
static size: bigint; | ||
static isInitialized: boolean; | ||
private static fields: string[]; | ||
private static masks: BigIntMap; | ||
private static offsets: BigIntMap; | ||
private static mask: bigint; | ||
value: bigint; | ||
static schema: BigIntMap; | ||
static size: bigint; | ||
static isInitialized: boolean; | ||
private static fields: string[]; | ||
private static masks: BigIntMap; | ||
private static offsets: BigIntMap; | ||
private static mask: bigint; | ||
constructor(data?: bigint|BigBitField|number[]|NumberMap); | ||
get(field: string): number; | ||
set(field: string, value: number); | ||
has(...fields: string[]): boolean; | ||
match(matcher: BigIntMatcher|NumberMap): boolean; | ||
toJSON(): bigint; | ||
toObject(): NumberMap; | ||
toString(): string; | ||
valueOf(): bigint; | ||
static initialize(): void; | ||
static encode(data: number[]|NumberMap): number; | ||
static decode(data: number): NumberMap; | ||
static isValid(data: NumberMap): boolean; | ||
static getMinSize(number: number): number; | ||
static getMatcher(matcher: NumberMap): BigIntMatcher; | ||
static match(value: bigint, matcher: BigIntMatcher): boolean; | ||
constructor(data?: bigint | BigBitField | number[] | NumberMap); | ||
get(field: string): number; | ||
set(field: string, value: number); | ||
has(...fields: string[]): boolean; | ||
match(matcher: BigIntMatcher | NumberMap): boolean; | ||
toJSON(): bigint; | ||
toObject(): NumberMap; | ||
toString(): string; | ||
valueOf(): bigint; | ||
static initialize(): void; | ||
static encode(data: number[] | NumberMap): number; | ||
static decode(data: number): NumberMap; | ||
static isValid(data: NumberMap): boolean; | ||
static getMinSize(number: number): number; | ||
static getMatcher(matcher: NumberMap): BigIntMatcher; | ||
static match(value: bigint, matcher: BigIntMatcher): boolean; | ||
} | ||
export declare function BitFieldMixin(schema: string[]|NumberMap, BitFieldClass?: typeof BitField | typeof BigBitField): typeof BitField | typeof BitFieldClass; | ||
export declare function BitFieldMixin( | ||
schema: string[] | NumberMap, | ||
BitFieldClass?: typeof BitField | typeof BigBitField, | ||
): typeof BitField | typeof BitFieldClass; | ||
@@ -175,33 +196,83 @@ type CompareResult = 1 | -1 | 0; | ||
interface Comparator { | ||
(a: any, b: any): CompareResult | ||
(a: any, b: any): CompareResult; | ||
} | ||
declare class SortedCollection { | ||
isSorted(): boolean; | ||
isUnique(): boolean; | ||
range(start: number, end: number, subarray?: boolean): SortedCollection; | ||
rank(element: any): number; | ||
static compare(a: any, b: any): CompareResult; | ||
static getDifference<T extends Collection>(a: Collection, b: Collection, symmetric?: boolean, comparator?: Comparator, container?: T): T; | ||
static getDifferenceScore(a: Collection, b: Collection, symmetric?: boolean, comparator?: Comparator): number; | ||
static getIndex(arr: Collection, target: any, comparator?: Comparator, rank?: boolean, start?: number, end?: number): number; | ||
static getIntersection<T extends Collection>(a: Collection, b: Collection, comparator?: Comparator, container?: T): T; | ||
static getIntersectionScore(a: Collection, b: Collection, comparator?: Comparator): number; | ||
static getRange<T extends Collection>(arr: T, start?: number, end?: number, comparator?: Comparator, subarray?: boolean): T; | ||
static getUnion<T extends Collection>(a: Collection, b: Collection, unique?: boolean, comparator?: Comparator, container?: T): T; | ||
static getUnique<T extends Collection>(arr: Collection, comparator?: Comparator, container?: T): T; | ||
static isSorted(arr: Collection, comparator?: Comparator): boolean; | ||
static isUnique(arr: Collection, comparator?: Comparator): boolean; | ||
isSorted(): boolean; | ||
isUnique(): boolean; | ||
range(start: number, end: number, subarray?: boolean): SortedCollection; | ||
rank(element: any): number; | ||
static compare(a: any, b: any): CompareResult; | ||
static getDifference<T extends Collection>( | ||
a: Collection, | ||
b: Collection, | ||
symmetric?: boolean, | ||
comparator?: Comparator, | ||
container?: T, | ||
): T; | ||
static getDifferenceScore( | ||
a: Collection, | ||
b: Collection, | ||
symmetric?: boolean, | ||
comparator?: Comparator, | ||
): number; | ||
static getIndex( | ||
arr: Collection, | ||
target: any, | ||
comparator?: Comparator, | ||
rank?: boolean, | ||
start?: number, | ||
end?: number, | ||
): number; | ||
static getIntersection<T extends Collection>( | ||
a: Collection, | ||
b: Collection, | ||
comparator?: Comparator, | ||
container?: T, | ||
): T; | ||
static getIntersectionScore(a: Collection, b: Collection, comparator?: Comparator): number; | ||
static getRange<T extends Collection>( | ||
arr: T, | ||
start?: number, | ||
end?: number, | ||
comparator?: Comparator, | ||
subarray?: boolean, | ||
): T; | ||
static getUnion<T extends Collection>( | ||
a: Collection, | ||
b: Collection, | ||
unique?: boolean, | ||
comparator?: Comparator, | ||
container?: T, | ||
): T; | ||
static getUnique<T extends Collection>( | ||
arr: Collection, | ||
comparator?: Comparator, | ||
container?: T, | ||
): T; | ||
static isSorted(arr: Collection, comparator?: Comparator): boolean; | ||
static isUnique(arr: Collection, comparator?: Comparator): boolean; | ||
} | ||
export declare function SortedMixin<T extends Collection>(Base?: Constructor<T>): Constructor<T & SortedCollection> | ||
export declare function SortedMixin<T extends Collection>( | ||
Base?: Constructor<T>, | ||
): Constructor<T & SortedCollection>; | ||
export class SortedArray extends SortedMixin(Array) { | ||
unique: boolean; | ||
set(arr: Collection): this; | ||
uniquify(): this; | ||
unique: boolean; | ||
set(arr: Collection): this; | ||
uniquify(): this; | ||
} | ||
type PrimitiveFieldType = 'int8' | 'uint8' | 'int16' | 'uint16' | ||
| 'int32' | 'uint32' | 'float32' | 'float64' | 'bigint64' | 'biguint64'; | ||
type PrimitiveFieldType = | ||
| 'int8' | ||
| 'uint8' | ||
| 'int16' | ||
| 'uint16' | ||
| 'int32' | ||
| 'uint32' | ||
| 'float32' | ||
| 'float64' | ||
| 'bigint64' | ||
| 'biguint64'; | ||
@@ -213,335 +284,382 @@ type ViewType = typeof ArrayView | typeof ObjectView | typeof StringView | typeof TypeView; | ||
export declare class TypeView extends DataView { | ||
static offset: number; | ||
static littleEndian: true; | ||
static objectLength: number; | ||
static Views: Map<string, typeof TypeView>; | ||
static ArrayClass: typeof ArrayView; | ||
static offset: number; | ||
static littleEndian: true; | ||
static objectLength: number; | ||
static Views: Map<string, typeof TypeView>; | ||
static ArrayClass: typeof ArrayView; | ||
get(): number; | ||
set(value: number): this; | ||
toJSON(): number; | ||
static getLength(): number; | ||
static from(value: any, view?: View, start?: number): View; | ||
static toJSON(view: View, start?: number): any; | ||
static of(): TypeView; | ||
get(): number; | ||
set(value: number): this; | ||
toJSON(): number; | ||
static getLength(): number; | ||
static from(value: any, view?: View, start?: number): View; | ||
static toJSON(view: View, start?: number): any; | ||
static of(): TypeView; | ||
} | ||
export declare class BooleanView extends TypeView { | ||
static from(value: number|boolean, view?: View, start?: number): View; | ||
static toJSON(view: View, start?: number): boolean; | ||
static from(value: number | boolean, view?: View, start?: number): View; | ||
static toJSON(view: View, start?: number): boolean; | ||
} | ||
export declare function TypeViewMixin(type: PrimitiveFieldType, littleEndian?: boolean, | ||
TypeViewClass?: typeof TypeView): typeof TypeView; | ||
export declare function TypeViewMixin( | ||
type: PrimitiveFieldType, | ||
littleEndian?: boolean, | ||
TypeViewClass?: typeof TypeView, | ||
): typeof TypeView; | ||
export declare class ArrayView extends DataView { | ||
size: number; | ||
static itemLength: number; | ||
static View: ViewType; | ||
static ArrayClass: typeof ArrayView; | ||
size: number; | ||
static itemLength: number; | ||
static View: ViewType; | ||
static ArrayClass: typeof ArrayView; | ||
get(index: number): any; | ||
getView(index: number): View; | ||
set(index: number, value: any): this; | ||
setView(index: number, value: View): this; | ||
toJSON(): any[]; | ||
[Symbol.iterator](): IterableIterator<View | number>; | ||
static from(value: ArrayLike<any>, array?: View, start?: number, length?: number): View; | ||
static toJSON(view: View, start: number, length: number): any[]; | ||
static of(size?: number): ArrayView; | ||
static getLength(size: number): number; | ||
static getSize(length: number): number; | ||
get(index: number): any; | ||
getView(index: number): View; | ||
set(index: number, value: any): this; | ||
setView(index: number, value: View): this; | ||
toJSON(): any[]; | ||
[Symbol.iterator](): IterableIterator<View | number>; | ||
static from(value: ArrayLike<any>, array?: View, start?: number, length?: number): View; | ||
static toJSON(view: View, start: number, length: number): any[]; | ||
static of(size?: number): ArrayView; | ||
static getLength(size: number): number; | ||
static getSize(length: number): number; | ||
} | ||
export declare class TypedArrayView extends ArrayView { | ||
static View: typeof TypeView; | ||
static View: typeof TypeView; | ||
get(index: number): number; | ||
set(index: number, value: number): this; | ||
toJSON(): Array<number>; | ||
[Symbol.iterator](): IterableIterator<number>; | ||
static from(value: ArrayLike<number>, array?: View, start?: number, length?: number): View; | ||
static toJSON(view: View, start: number, length: number): number[]; | ||
static of(size?: number): TypedArrayView; | ||
get(index: number): number; | ||
set(index: number, value: number): this; | ||
toJSON(): Array<number>; | ||
[Symbol.iterator](): IterableIterator<number>; | ||
static from(value: ArrayLike<number>, array?: View, start?: number, length?: number): View; | ||
static toJSON(view: View, start: number, length: number): number[]; | ||
static of(size?: number): TypedArrayView; | ||
} | ||
export declare function ArrayViewMixin(ObjectViewClass: ViewType | PrimitiveFieldType, | ||
itemLength?: number | boolean): typeof ArrayView; | ||
export declare function ArrayViewMixin( | ||
ObjectViewClass: ViewType | PrimitiveFieldType, | ||
itemLength?: number | boolean, | ||
): typeof ArrayView; | ||
interface ViewLayoutField { | ||
View: ViewType; | ||
start?: number; | ||
length?: number; | ||
default?: any; | ||
View: ViewType; | ||
start?: number; | ||
length?: number; | ||
default?: any; | ||
} | ||
interface ViewLayout { | ||
[propName: string]: ViewLayoutField; | ||
[propName: string]: ViewLayoutField; | ||
} | ||
interface ViewTypes { | ||
[propName: string]: ViewType; | ||
[propName: string]: ViewType; | ||
} | ||
interface ObjectViewTypeDefs { | ||
[propName: string]: (field: ViewLayoutField) => void; | ||
[propName: string]: (field: ViewLayoutField) => void; | ||
} | ||
export declare class ObjectView extends DataView { | ||
static schema: object; | ||
static layout: ViewLayout; | ||
static fields: string[]; | ||
static Views: ViewTypes; | ||
static ArrayClass: typeof ArrayView; | ||
static types: ObjectViewTypeDefs; | ||
static objectLength: number; | ||
private static defaultBuffer: ArrayBuffer; | ||
static schema: object; | ||
static layout: ViewLayout; | ||
static fields: string[]; | ||
static Views: ViewTypes; | ||
static ArrayClass: typeof ArrayView; | ||
static types: ObjectViewTypeDefs; | ||
static objectLength: number; | ||
private static defaultBuffer: ArrayBuffer; | ||
get(field: string): any; | ||
getView(field: string): View; | ||
set(field: string, value: any): this; | ||
setView(field: string, value: View): this; | ||
toJSON(): object; | ||
static from(object: object, view?: View, start?: number, length?: number): View; | ||
static toJSON(view: View, start?: number): object; | ||
static getLength(): number; | ||
static initialize(): void; | ||
private static setDefaultBuffer(): void; | ||
static getSchemaOrdering(schema: object): object[]; | ||
static getLayoutFromSchema(schema: object): [ViewLayout, number, string[]]; | ||
static getViewFromSchema(schema: object): ViewType; | ||
get(field: string): any; | ||
getView(field: string): View; | ||
set(field: string, value: any): this; | ||
setView(field: string, value: View): this; | ||
toJSON(): object; | ||
static from(object: object, view?: View, start?: number, length?: number): View; | ||
static toJSON(view: View, start?: number): object; | ||
static getLength(): number; | ||
static initialize(): void; | ||
private static setDefaultBuffer(): void; | ||
static getSchemaOrdering(schema: object): object[]; | ||
static getLayoutFromSchema(schema: object): [ViewLayout, number, string[]]; | ||
static getViewFromSchema(schema: object): ViewType; | ||
} | ||
export declare function ObjectViewMixin(schema: object, ObjectViewClass?: typeof ObjectView): typeof ObjectView; | ||
export declare function ObjectViewMixin( | ||
schema: object, | ||
ObjectViewClass?: typeof ObjectView, | ||
): typeof ObjectView; | ||
export declare class StringView extends Uint8Array { | ||
size: number; | ||
static masks: Int8Array; | ||
static encoder: TextEncoder; | ||
static decoder: TextDecoder; | ||
static ArrayClass: typeof ArrayView; | ||
size: number; | ||
static masks: Int8Array; | ||
static encoder: TextEncoder; | ||
static decoder: TextDecoder; | ||
static ArrayClass: typeof ArrayView; | ||
characters(): Iterable<string>; | ||
charAt(index?: number): string; | ||
private getCharEnd(index: number): number; | ||
private getCharStart(index: number, startCharIndex?: number, startIndex?: number): number; | ||
replace(pattern: Collection, replacement: Collection): this; | ||
reverse(): this; | ||
search(searchValue: Collection, fromIndex?: number): number; | ||
private searchNaive(searchValue: Collection, fromIndex?: number): number; | ||
private searchShiftOr(searchValue: Collection, fromIndex?: number): number; | ||
substring(indexStart: number, indexEnd?: number): string; | ||
private toChar(index: number): string; | ||
toString(): string; | ||
toJSON(): string; | ||
trim(): StringView; | ||
static from(arrayLike: ArrayLike<number>|string, mapFn?: Function | View, thisArg?: any, length?: number): View; | ||
static toJSON(view: View, start?: number, length?: number): string; | ||
static getByteSize(string: string): number; | ||
characters(): Iterable<string>; | ||
charAt(index?: number): string; | ||
private getCharEnd(index: number): number; | ||
private getCharStart(index: number, startCharIndex?: number, startIndex?: number): number; | ||
replace(pattern: Collection, replacement: Collection): this; | ||
reverse(): this; | ||
search(searchValue: Collection, fromIndex?: number): number; | ||
private searchNaive(searchValue: Collection, fromIndex?: number): number; | ||
private searchShiftOr(searchValue: Collection, fromIndex?: number): number; | ||
substring(indexStart: number, indexEnd?: number): string; | ||
private toChar(index: number): string; | ||
toString(): string; | ||
toJSON(): string; | ||
trim(): StringView; | ||
static from( | ||
arrayLike: ArrayLike<number> | string, | ||
mapFn?: Function | View, | ||
thisArg?: any, | ||
length?: number, | ||
): View; | ||
static toJSON(view: View, start?: number, length?: number): string; | ||
static getByteSize(string: string): number; | ||
} | ||
export declare class MapView extends DataView { | ||
static schema: object; | ||
static layout: ViewLayout; | ||
static fields: string[]; | ||
static ObjectViewClass: typeof ObjectView; | ||
static Views: ViewTypes; | ||
static schema: object; | ||
static layout: ViewLayout; | ||
static fields: string[]; | ||
static ObjectViewClass: typeof ObjectView; | ||
static Views: ViewTypes; | ||
get(field: string): any; | ||
getView(field: string): View; | ||
private getLayout(field: string): [ViewType, number, number]; | ||
set(field: string, value: any): this; | ||
setView(field: string, value: View): this; | ||
toJSON(): object; | ||
static from(value: object): MapView; | ||
static toJSON(view: View, start?: number): object; | ||
static getLength(value: any, getOffsets?: boolean): number | [number, number[]]; | ||
static initialize(): void; | ||
get(field: string): any; | ||
getView(field: string): View; | ||
private getLayout(field: string): [ViewType, number, number]; | ||
set(field: string, value: any): this; | ||
setView(field: string, value: View): this; | ||
toJSON(): object; | ||
static from(value: object): MapView; | ||
static toJSON(view: View, start?: number): object; | ||
static getLength(value: any, getOffsets?: boolean): number | [number, number[]]; | ||
static initialize(): void; | ||
} | ||
export declare function MapViewMixin(schema: object, MapViewClass?: typeof MapView, ObjectViewClass?: typeof ObjectView): typeof MapView; | ||
export declare function MapViewMixin( | ||
schema: object, | ||
MapViewClass?: typeof MapView, | ||
ObjectViewClass?: typeof ObjectView, | ||
): typeof MapView; | ||
interface BinaryProtocolSchema { | ||
[propName: number]: typeof ObjectView; | ||
[propName: number]: typeof ObjectView; | ||
} | ||
export declare class BinaryProtocol { | ||
Views: BinaryProtocolSchema; | ||
private tagName: string; | ||
private tagType: PrimitiveFieldType; | ||
Views: BinaryProtocolSchema; | ||
private tagName: string; | ||
private tagType: PrimitiveFieldType; | ||
constructor(views: object, tagName?: string, tagType?: string); | ||
view(buffer: ArrayBuffer, offset?: number): ObjectView; | ||
encode(object: object, arrayBuffer?: ArrayBuffer, offset?: number): ObjectView; | ||
decode(buffer: ArrayBuffer, offset?: number): object; | ||
constructor(views: object, tagName?: string, tagType?: string); | ||
view(buffer: ArrayBuffer, offset?: number): ObjectView; | ||
encode(object: object, arrayBuffer?: ArrayBuffer, offset?: number): ObjectView; | ||
decode(buffer: ArrayBuffer, offset?: number): object; | ||
} | ||
export declare class BitArray extends Uint32Array { | ||
size: number; | ||
private lastPosition: BitPosition; | ||
size: number; | ||
private lastPosition: BitPosition; | ||
constructor(size: number|ArrayLike<number>|ArrayBuffer, ...args: any); | ||
getBit(index: number): Bit; | ||
setBit(index: number, value: Bit): this; | ||
protected getBitPosition(index: number): void; | ||
static getLength(size: number): number; | ||
constructor(size: number | ArrayLike<number> | ArrayBuffer, ...args: any); | ||
getBit(index: number): Bit; | ||
setBit(index: number, value: Bit): this; | ||
protected getBitPosition(index: number): void; | ||
static getLength(size: number): number; | ||
} | ||
export declare class Pool extends BitArray { | ||
get(): number; | ||
free(index: number): void; | ||
static getLength(size: number): number; | ||
get(): number; | ||
free(index: number): void; | ||
static getLength(size: number): number; | ||
} | ||
export declare class RankedBitArray extends BitArray { | ||
setBit(index: number, value: Bit): this; | ||
rank(index: number): number; | ||
select(index: number): number; | ||
static getLength(size: number): number; | ||
setBit(index: number, value: Bit): this; | ||
rank(index: number): number; | ||
select(index: number): number; | ||
static getLength(size: number): number; | ||
} | ||
export declare class BinaryHeap extends Array { | ||
heapify(): this; | ||
isHeap(): boolean; | ||
left(index: number): any; | ||
parent(index: number): any; | ||
replace(item: any): any; | ||
right(index: number): any; | ||
update(index: number): void; | ||
private has(index: number): boolean; | ||
private siftDown(start: number): void; | ||
private siftUp(start: number): void; | ||
static compare(a: any, b: any): boolean; | ||
private static getLeftIndex(index: number): number; | ||
private static getParentIndex(index: number): number; | ||
private static getRightIndex(index: number): number; | ||
static isHeap(heap: Collection): boolean; | ||
heapify(): this; | ||
isHeap(): boolean; | ||
left(index: number): any; | ||
parent(index: number): any; | ||
replace(item: any): any; | ||
right(index: number): any; | ||
update(index: number): void; | ||
private has(index: number): boolean; | ||
private siftDown(start: number): void; | ||
private siftUp(start: number): void; | ||
static compare(a: any, b: any): boolean; | ||
private static getLeftIndex(index: number): number; | ||
private static getParentIndex(index: number): number; | ||
private static getRightIndex(index: number): number; | ||
static isHeap(heap: Collection): boolean; | ||
} | ||
interface AdjacencyListOptions { | ||
vertices: number; | ||
edges: number; | ||
vertices: number; | ||
edges: number; | ||
} | ||
export declare class UnweightedAdjacencyList extends Uint32Array { | ||
vertices: number; | ||
edges: number; | ||
static undirected: boolean; | ||
static weighted: false; | ||
vertices: number; | ||
edges: number; | ||
static undirected: boolean; | ||
static weighted: false; | ||
constructor(options?: AdjacencyListOptions, ...args: any); | ||
addEdge(x: number, y: number): this; | ||
removeEdge(x: number, y: number): this; | ||
hasEdge(x: number, y: number): boolean; | ||
getEdge(x: number, y: number): Bit; | ||
private setEdge(x: number, y: number): this; | ||
private unsetEdge(x: number, y: number): this; | ||
outEdges(x: number): IterableIterator<number>; | ||
inEdges(x: number): IterableIterator<number>; | ||
private setOffsets(): void; | ||
isFull(): boolean; | ||
grow(vertices?: number, edges?: number): UnweightedAdjacencyList; | ||
static getLength(vertices: number, edges: number): number; | ||
static getVertexCount(array: Collection): number; | ||
static fromGrid(grid: Grid): UnweightedAdjacencyList; | ||
constructor(options?: AdjacencyListOptions, ...args: any); | ||
addEdge(x: number, y: number): this; | ||
removeEdge(x: number, y: number): this; | ||
hasEdge(x: number, y: number): boolean; | ||
getEdge(x: number, y: number): Bit; | ||
private setEdge(x: number, y: number): this; | ||
private unsetEdge(x: number, y: number): this; | ||
outEdges(x: number): IterableIterator<number>; | ||
inEdges(x: number): IterableIterator<number>; | ||
private setOffsets(): void; | ||
isFull(): boolean; | ||
grow(vertices?: number, edges?: number): UnweightedAdjacencyList; | ||
static getLength(vertices: number, edges: number): number; | ||
static getVertexCount(array: Collection): number; | ||
static fromGrid(grid: Grid): UnweightedAdjacencyList; | ||
} | ||
declare class WeightedAdjacencyList { | ||
vertices: number; | ||
edges: number; | ||
static undirected: boolean; | ||
static weighted: true; | ||
vertices: number; | ||
edges: number; | ||
static undirected: boolean; | ||
static weighted: true; | ||
constructor(options?: AdjacencyListOptions, ...args: any); | ||
addEdge(x: number, y: number, weight: number): this; | ||
removeEdge(x: number, y: number): this; | ||
hasEdge(x: number, y: number): boolean; | ||
getEdge(x: number, y: number): number; | ||
private setEdge(x: number, y: number, weight: number): this; | ||
private unsetEdge(x: number, y: number): this; | ||
outEdges(x: number): IterableIterator<number>; | ||
inEdges(x: number): IterableIterator<number>; | ||
private setOffsets(): void; | ||
isFull(): boolean; | ||
grow(vertices?: number, edges?: number): UnweightedAdjacencyList; | ||
static getLength(vertices: number, edges: number): number; | ||
static getVertexCount(array: Collection): number; | ||
static fromGrid(grid: Grid): WeightedAdjacencyList; | ||
constructor(options?: AdjacencyListOptions, ...args: any); | ||
addEdge(x: number, y: number, weight: number): this; | ||
removeEdge(x: number, y: number): this; | ||
hasEdge(x: number, y: number): boolean; | ||
getEdge(x: number, y: number): number; | ||
private setEdge(x: number, y: number, weight: number): this; | ||
private unsetEdge(x: number, y: number): this; | ||
outEdges(x: number): IterableIterator<number>; | ||
inEdges(x: number): IterableIterator<number>; | ||
private setOffsets(): void; | ||
isFull(): boolean; | ||
grow(vertices?: number, edges?: number): UnweightedAdjacencyList; | ||
static getLength(vertices: number, edges: number): number; | ||
static getVertexCount(array: Collection): number; | ||
static fromGrid(grid: Grid): WeightedAdjacencyList; | ||
} | ||
export declare function WeightedAdjacencyListMixin<T extends Collection>(Base?: Constructor<T>): Constructor<T & WeightedAdjacencyList> | ||
export declare function WeightedAdjacencyListMixin<T extends Collection>( | ||
Base?: Constructor<T>, | ||
): Constructor<T & WeightedAdjacencyList>; | ||
interface UnweightedMatrixOptions { | ||
vertices: number; | ||
vertices: number; | ||
} | ||
export declare class UnweightedAdjacencyMatrix extends BinaryGrid { | ||
vertices: number; | ||
static undirected: boolean; | ||
static weighted: false; | ||
vertices: number; | ||
static undirected: boolean; | ||
static weighted: false; | ||
constructor(options?: UnweightedMatrixOptions, ...args: any); | ||
addEdge(x: number, y: number): this; | ||
removeEdge(x: number, y: number): this; | ||
hasEdge(x: number, y: number): boolean; | ||
getEdge(x: number, y: number): number; | ||
outEdges(x: number): IterableIterator<number>; | ||
inEdges(x: number): IterableIterator<number>; | ||
static getLength(size: number): number; | ||
static fromList(list: UnweightedAdjacencyList): UnweightedAdjacencyMatrix; | ||
constructor(options?: UnweightedMatrixOptions, ...args: any); | ||
addEdge(x: number, y: number): this; | ||
removeEdge(x: number, y: number): this; | ||
hasEdge(x: number, y: number): boolean; | ||
getEdge(x: number, y: number): number; | ||
outEdges(x: number): IterableIterator<number>; | ||
inEdges(x: number): IterableIterator<number>; | ||
static getLength(size: number): number; | ||
static fromList(list: UnweightedAdjacencyList): UnweightedAdjacencyMatrix; | ||
} | ||
interface WeightedMatrixOptions { | ||
vertices: number; | ||
pad?: any; | ||
vertices: number; | ||
pad?: any; | ||
} | ||
declare class WeightedAdjacencyMatrix { | ||
vertices: number; | ||
static undirected: boolean; | ||
static weighted: true; | ||
vertices: number; | ||
static undirected: boolean; | ||
static weighted: true; | ||
constructor(options?: WeightedMatrixOptions, ...args: any); | ||
addEdge(x: number, y: number): this; | ||
removeEdge(x: number, y: number): this; | ||
hasEdge(x: number, y: number): boolean; | ||
getEdge(x: number, y: number): number; | ||
outEdges(x: number): IterableIterator<number>; | ||
inEdges(x: number): IterableIterator<number>; | ||
static getLength(size: number): number; | ||
static fromList(list: WeightedAdjacencyList, pad: number): WeightedAdjacencyMatrix; | ||
constructor(options?: WeightedMatrixOptions, ...args: any); | ||
addEdge(x: number, y: number): this; | ||
removeEdge(x: number, y: number): this; | ||
hasEdge(x: number, y: number): boolean; | ||
getEdge(x: number, y: number): number; | ||
outEdges(x: number): IterableIterator<number>; | ||
inEdges(x: number): IterableIterator<number>; | ||
static getLength(size: number): number; | ||
static fromList(list: WeightedAdjacencyList, pad: number): WeightedAdjacencyMatrix; | ||
} | ||
export declare function WeightedAdjacencyMatrixMixin<T extends GridStructure>(Base: CollectionConstructor, undirected?: boolean): Constructor<T & WeightedAdjacencyMatrix> | ||
export declare function WeightedAdjacencyMatrixMixin<T extends GridStructure>( | ||
Base: CollectionConstructor, | ||
undirected?: boolean, | ||
): Constructor<T & WeightedAdjacencyMatrix>; | ||
type AdjacencyStructure = UnweightedAdjacencyList | UnweightedAdjacencyMatrix | ||
| WeightedAdjacencyList | WeightedAdjacencyMatrix; | ||
type AdjacencyStructure = | ||
| UnweightedAdjacencyList | ||
| UnweightedAdjacencyMatrix | ||
| WeightedAdjacencyList | ||
| WeightedAdjacencyMatrix; | ||
interface GraphOptions { | ||
vertices: number; | ||
edges?: number; | ||
pad?: number; | ||
vertices: number; | ||
edges?: number; | ||
pad?: number; | ||
} | ||
declare class Graph { | ||
colors: BinaryGrid; | ||
colors: BinaryGrid; | ||
constructor(options: GraphOptions, ...args: any); | ||
isGray(x: number): boolean; | ||
setGray(x: number): this; | ||
isBlack(x: number): boolean; | ||
setBlack(x: number): this; | ||
traverse(isDFS?: boolean, start?: number, gray?: boolean, white?: boolean, black?: boolean): IterableIterator<number>; | ||
path(start: number, end: number, isAcyclic?: boolean, isPositive?: boolean): number[]; | ||
tree(start?: number): number[]; | ||
isAcyclic(): boolean; | ||
topologicalSort(): number[]; | ||
private searchUnweighted(start: number, end: number, predecessors: number[]): boolean; | ||
private searchTopological(start: number, end: number, distances: number[], predecessors: number[]): boolean; | ||
private searchDijkstra(start: number, end: number, distances: number[], predecessors: number[]): boolean; | ||
private searchBellmanFord(start: number, end: number, distances: number[], predecessors: number[]): boolean; | ||
constructor(options: GraphOptions, ...args: any); | ||
isGray(x: number): boolean; | ||
setGray(x: number): this; | ||
isBlack(x: number): boolean; | ||
setBlack(x: number): this; | ||
traverse( | ||
isDFS?: boolean, | ||
start?: number, | ||
gray?: boolean, | ||
white?: boolean, | ||
black?: boolean, | ||
): IterableIterator<number>; | ||
path(start: number, end: number, isAcyclic?: boolean, isPositive?: boolean): number[]; | ||
tree(start?: number): number[]; | ||
isAcyclic(): boolean; | ||
topologicalSort(): number[]; | ||
private searchUnweighted(start: number, end: number, predecessors: number[]): boolean; | ||
private searchTopological( | ||
start: number, | ||
end: number, | ||
distances: number[], | ||
predecessors: number[], | ||
): boolean; | ||
private searchDijkstra( | ||
start: number, | ||
end: number, | ||
distances: number[], | ||
predecessors: number[], | ||
): boolean; | ||
private searchBellmanFord( | ||
start: number, | ||
end: number, | ||
distances: number[], | ||
predecessors: number[], | ||
): boolean; | ||
} | ||
export declare function GraphMixin<T extends AdjacencyStructure>(Base: Constructor<T>, undirected?: boolean): Constructor<T & Graph> | ||
export declare function GraphMixin<T extends AdjacencyStructure>( | ||
Base: Constructor<T>, | ||
undirected?: boolean, | ||
): Constructor<T & Graph>; |
@@ -56,4 +56,5 @@ /** | ||
const offset = this.constructor.getLength(index); | ||
new Uint8Array(this.buffer, this.byteOffset + offset, itemLength) | ||
.set(new Uint8Array(value.buffer, value.byteOffset, value.byteLength)); | ||
new Uint8Array(this.buffer, this.byteOffset + offset, itemLength).set( | ||
new Uint8Array(value.buffer, value.byteOffset, value.byteLength), | ||
); | ||
return this; | ||
@@ -71,3 +72,2 @@ } | ||
/** | ||
@@ -78,3 +78,3 @@ * Allows iterating over object views stored in the array. | ||
*/ | ||
* [Symbol.iterator]() { | ||
*[Symbol.iterator]() { | ||
const { size } = this; | ||
@@ -109,3 +109,3 @@ for (let i = 0; i < size; i++) { | ||
const size = this.getSize(length); | ||
const max = (size < value.length ? size : value.length); | ||
const max = size < value.length ? size : value.length; | ||
for (let i = 0; i < max; i++) { | ||
@@ -112,0 +112,0 @@ const offset = this.getLength(i); |
@@ -7,3 +7,3 @@ const { getBitSize } = require('./utilities'); | ||
*/ | ||
const BigInt = (global || window).BigInt || Number; | ||
const BigInt = globalThis.BigInt || Number; | ||
@@ -10,0 +10,0 @@ /** |
@@ -98,3 +98,4 @@ /** | ||
*/ | ||
shift() { // extract min/max | ||
shift() { | ||
// extract min/max | ||
if (this.length < 2) return this.pop(); | ||
@@ -101,0 +102,0 @@ const item = this[0]; |
@@ -44,3 +44,3 @@ const { ObjectView, ObjectViewMixin } = require('./object-view'); | ||
const View = ObjectView.Views[schema]; | ||
if (!View) throw Error(`View "${schema}" is not found.`); | ||
if (!View) throw TypeError(`View "${schema}" is not found.`); | ||
const defaultTag = View.layout[tagName]; | ||
@@ -106,3 +106,2 @@ if (!defaultTag || defaultTag.default !== tag) { | ||
/** | ||
@@ -109,0 +108,0 @@ * Decodes a given ArrayBuffer into an object according to the tag information. |
@@ -13,4 +13,8 @@ const BitField = require('./bit-field'); | ||
const schemaMap = Array.isArray(schema) | ||
? schema.reduce((a, i) => { a[i] = 1; return a; }, {}) : schema; | ||
const totalSize = Object.keys(schemaMap).reduce((result, field) => (result + schema[field]), 0); | ||
? schema.reduce((a, i) => { | ||
a[i] = 1; | ||
return a; | ||
}, {}) | ||
: schema; | ||
const totalSize = Object.keys(schemaMap).reduce((result, field) => result + schema[field], 0); | ||
const isBigInt = totalSize > 31; | ||
@@ -17,0 +21,0 @@ const ExtendClass = BitFieldClass || (isBigInt ? BigBitField : BitField); |
@@ -54,4 +54,8 @@ const { getBitSize } = require('./utilities'); | ||
constructor(data = 0) { | ||
this.value = typeof data === 'number' ? data | ||
: data instanceof BitField ? data.valueOf() : this.constructor.encode(data); | ||
this.value = | ||
typeof data === 'number' | ||
? data | ||
: data instanceof BitField | ||
? data.valueOf() | ||
: this.constructor.encode(data); | ||
} | ||
@@ -154,4 +158,6 @@ | ||
match(matcher) { | ||
return this.constructor.match(this.value, Array.isArray(matcher) | ||
? matcher : this.constructor.getMatcher(matcher)); | ||
return this.constructor.match( | ||
this.value, | ||
Array.isArray(matcher) ? matcher : this.constructor.getMatcher(matcher), | ||
); | ||
} | ||
@@ -213,3 +219,3 @@ | ||
const { fields, schema } = this; | ||
const array = Array.isArray(data) ? data : fields.map((name) => (data[name] || 0)); | ||
const array = Array.isArray(data) ? data : fields.map((name) => data[name] || 0); | ||
let result = 0; | ||
@@ -273,3 +279,3 @@ for (let i = fields.length - 1; i >= 0; i--) { | ||
const value = data[field]; | ||
if (((value & SIGN_BIT) !== value) || value > masks[field]) return false; | ||
if ((value & SIGN_BIT) !== value || value > masks[field]) return false; | ||
} | ||
@@ -314,3 +320,3 @@ return true; | ||
const size = schema[field]; | ||
masks[field] = (2 << size - 1) - 1; | ||
masks[field] = (2 << (size - 1)) - 1; | ||
offsets[field] = lastOffset; | ||
@@ -327,3 +333,3 @@ lastOffset += size; | ||
this.size = lastOffset; | ||
this.mask = 2 << lastOffset - 1; | ||
this.mask = 2 << (lastOffset - 1); | ||
this.masks = masks; | ||
@@ -378,3 +384,3 @@ this.offsets = offsets; | ||
*/ | ||
* [Symbol.iterator]() { | ||
*[Symbol.iterator]() { | ||
const { fields } = this.constructor; | ||
@@ -381,0 +387,0 @@ for (let i = 0; i < fields.length; i++) { |
@@ -113,3 +113,3 @@ const BinaryGrid = require('./binary-grid'); | ||
*/ | ||
* traverse(isDFS, start = 0, gray = true, white, black) { | ||
*traverse(isDFS, start = 0, gray = true, white, black) { | ||
this.resetColors(); | ||
@@ -168,6 +168,9 @@ const processing = [start]; | ||
const distances = new Array(vertices).fill(Infinity); | ||
const isFound = !weighted ? this.searchUnweighted(start, end, predecessors) | ||
: isAcyclic ? this.searchTopological(start, end, distances, predecessors) | ||
: isNonNegative ? this.searchDijkstra(start, end, distances, predecessors) | ||
: this.searchBellmanFord(start, end, distances, predecessors); | ||
const isFound = !weighted | ||
? this.searchUnweighted(start, end, predecessors) | ||
: isAcyclic | ||
? this.searchTopological(start, end, distances, predecessors) | ||
: isNonNegative | ||
? this.searchDijkstra(start, end, distances, predecessors) | ||
: this.searchBellmanFord(start, end, distances, predecessors); | ||
if (!isFound) return []; | ||
@@ -174,0 +177,0 @@ const path = []; |
@@ -72,7 +72,6 @@ const { ObjectView, ObjectViewMixin } = require('./object-view'); | ||
if (start !== end) { | ||
new Uint8Array(this.buffer, this.byteOffset, this.byteLength) | ||
.set( | ||
new Uint8Array(value.buffer, value.byteOffset, value.byteLength), | ||
start, | ||
); | ||
new Uint8Array(this.buffer, this.byteOffset, this.byteLength).set( | ||
new Uint8Array(value.buffer, value.byteOffset, value.byteLength), | ||
start, | ||
); | ||
} | ||
@@ -133,4 +132,6 @@ return this; | ||
const fieldValue = value[field]; | ||
length += typeof fieldValue === 'string' ? StringView.getByteSize(fieldValue) | ||
: View.getLength(fieldValue.length || 1); | ||
length += | ||
typeof fieldValue === 'string' | ||
? StringView.getByteSize(fieldValue) | ||
: View.getLength(fieldValue.length || 1); | ||
} | ||
@@ -137,0 +138,0 @@ offsets[fieldCount] = length; |
@@ -74,7 +74,6 @@ const StringView = require('./string-view'); | ||
const { start } = this.constructor.layout[field]; | ||
new Uint8Array(this.buffer, this.byteOffset, this.byteLength) | ||
.set( | ||
new Uint8Array(value.buffer, value.byteOffset, value.byteLength), | ||
start, | ||
); | ||
new Uint8Array(this.buffer, this.byteOffset, this.byteLength).set( | ||
new Uint8Array(value.buffer, value.byteOffset, value.byteLength), | ||
start, | ||
); | ||
return this; | ||
@@ -235,3 +234,3 @@ } | ||
if (visited !== Object.keys(objects).length) { | ||
throw Error('The schema has recursive references.'); | ||
throw TypeError('The schema has recursive references.'); | ||
} | ||
@@ -297,3 +296,3 @@ return order; | ||
} | ||
throw Error(`Type "${type}" is not supported.`); | ||
throw TypeError(`Type "${type}" is not supported.`); | ||
} | ||
@@ -300,0 +299,0 @@ } |
@@ -68,3 +68,4 @@ const BitArray = require('./bit-array'); | ||
right = bucketRankId - 1; | ||
} else if (index === this[bucketRankId - 1]) { // preceded by a duplicate | ||
} else if (index === this[bucketRankId - 1]) { | ||
// preceded by a duplicate | ||
right = bucketRankId - 1; | ||
@@ -90,2 +91,3 @@ } else { | ||
} | ||
return -1; | ||
} | ||
@@ -92,0 +94,0 @@ |
@@ -20,3 +20,7 @@ const SortedMixin = require('./sorted-collection'); | ||
result = this.constructor.getUnion( | ||
result, arrays[i], this.unique, this.constructor.compare, new this.constructor(), | ||
result, | ||
arrays[i], | ||
this.unique, | ||
this.constructor.compare, | ||
new this.constructor(), | ||
); | ||
@@ -112,4 +116,5 @@ } | ||
uniquify() { | ||
return this.set(this.constructor.getUnique(this, this.constructor.compare, | ||
new this.constructor())); | ||
return this.set( | ||
this.constructor.getUnique(this, this.constructor.compare, new this.constructor()), | ||
); | ||
} | ||
@@ -116,0 +121,0 @@ |
@@ -218,3 +218,3 @@ /** | ||
const score = this.getIntersectionScore(a, b, comparator); | ||
return symmetric ? (a.length + b.length) - (2 * score) : a.length - score; | ||
return symmetric ? a.length + b.length - 2 * score : a.length - score; | ||
} | ||
@@ -238,4 +238,8 @@ | ||
static getIndex( | ||
arr, target, comparator = this.compare, | ||
rank = false, start = 0, end = arr.length - 1, | ||
arr, | ||
target, | ||
comparator = this.compare, | ||
rank = false, | ||
start = 0, | ||
end = arr.length - 1, | ||
) { | ||
@@ -346,4 +350,4 @@ let left = start; | ||
const startIndex = start === undefined ? 0 : this.getIndex(arr, start, comparator, true); | ||
const endIndex = end === undefined ? arr.length | ||
: this.getIndex(arr, end, comparator, true, startIndex) + 1; | ||
const endIndex = | ||
end === undefined ? arr.length : this.getIndex(arr, end, comparator, true, startIndex) + 1; | ||
const method = subarray ? 'subarray' : 'slice'; | ||
@@ -404,3 +408,2 @@ return arr[method](startIndex, endIndex); | ||
/** | ||
@@ -419,3 +422,3 @@ * Returns an array of unique elements from a sorted array. | ||
static getUnique(arr, comparator = this.compare, container = []) { | ||
container[0] = arr[0]; | ||
[container[0]] = arr; | ||
for (let i = 1; i < arr.length; i++) { | ||
@@ -422,0 +425,0 @@ if (comparator(arr[i - 1], arr[i]) !== 0) { |
const ArrayView = require('./array-view'); | ||
const { UTF8ToString, stringToUTF8 } = require('./utilities'); | ||
@@ -23,3 +24,3 @@ /** | ||
*/ | ||
* characters() { | ||
*characters() { | ||
for (let i = 0; i < this.length; i++) { | ||
@@ -57,8 +58,12 @@ if (this[i] >> 6 !== 2) { | ||
if (point < 0x80) return index; | ||
switch ((point & 0xF0) >> 4) { | ||
case 0xF: return index + 3; | ||
case 0xE: return index + 2; | ||
case 0xD: | ||
case 0xC: return index + 1; | ||
default: return -1; | ||
switch ((point & 0xf0) >> 4) { | ||
case 0xf: | ||
return index + 3; | ||
case 0xe: | ||
return index + 2; | ||
case 0xd: | ||
case 0xc: | ||
return index + 1; | ||
default: | ||
return -1; | ||
} | ||
@@ -124,4 +129,4 @@ } | ||
while (--j > 0) { | ||
switch ((this[j] & 0xF0) >> 4) { | ||
case 0xF: | ||
switch ((this[j] & 0xf0) >> 4) { | ||
case 0xf: | ||
[this[j], this[j - 3]] = [this[j - 3], this[j]]; | ||
@@ -131,8 +136,8 @@ [this[j - 1], this[j - 2]] = [this[j - 2], this[j - 1]]; | ||
break; | ||
case 0xE: | ||
case 0xe: | ||
[this[j], this[j - 2]] = [this[j - 2], this[j]]; | ||
j -= 2; | ||
break; | ||
case 0xC: | ||
case 0xD: | ||
case 0xc: | ||
case 0xd: | ||
[this[j], this[j - 1]] = [this[j - 1], this[j]]; | ||
@@ -208,3 +213,3 @@ j--; | ||
if ((r & m1) === 0) { | ||
return (i - m) + 1; | ||
return i - m + 1; | ||
} | ||
@@ -229,3 +234,3 @@ } | ||
for (let i = 0; i < this.length; i++) { | ||
if ((this[i] >> 6) !== 2) size++; | ||
if (this[i] >> 6 !== 2) size++; | ||
} | ||
@@ -264,14 +269,19 @@ return size; | ||
if (point < 0x80) return String.fromCodePoint(point); | ||
switch ((point & 0xF0) >> 4) { | ||
case 0xF: return String.fromCodePoint(((point & 0x07) << 18) | ||
| ((this[index + 1] & 0x3F) << 12) | ||
| ((this[index + 2] & 0x3F) << 6) | ||
| ((this[index + 3] & 0x3F))); | ||
case 0xE: return String.fromCodePoint(((point & 0x0F) << 12) | ||
| ((this[index + 1] & 0x3F) << 6) | ||
| ((this[index + 2] & 0x3F))); | ||
case 0xD: | ||
case 0xC: return String.fromCodePoint(((point & 0x1F) << 6) | ||
| ((this[index + 1] & 0x3F))); | ||
default: return ''; | ||
switch ((point & 0xf0) >> 4) { | ||
case 0xf: | ||
return String.fromCodePoint( | ||
((point & 0x07) << 18) | | ||
((this[index + 1] & 0x3f) << 12) | | ||
((this[index + 2] & 0x3f) << 6) | | ||
(this[index + 3] & 0x3f), | ||
); | ||
case 0xe: | ||
return String.fromCodePoint( | ||
((point & 0x0f) << 12) | ((this[index + 1] & 0x3f) << 6) | (this[index + 2] & 0x3f), | ||
); | ||
case 0xd: | ||
case 0xc: | ||
return String.fromCodePoint(((point & 0x1f) << 6) | (this[index + 1] & 0x3f)); | ||
default: | ||
return ''; | ||
} | ||
@@ -292,3 +302,3 @@ } | ||
toString() { | ||
const decoded = this.constructor.decoder.decode(this); | ||
const decoded = UTF8ToString(this); | ||
const end = decoded.indexOf(ZERO_CHAR); | ||
@@ -318,3 +328,3 @@ return ~end ? decoded.slice(0, end) : decoded; | ||
const end = this.indexOf(0); | ||
return (~end) ? this.subarray(0, end) : this; | ||
return ~end ? this.subarray(0, end) : this; | ||
} | ||
@@ -335,8 +345,11 @@ | ||
// no view is supplied | ||
if (!mapFn) return new this(this.encoder.encode(arrayLike).buffer); | ||
const array = new Uint8Array(mapFn.buffer, | ||
mapFn.byteOffset + thisArg, length || mapFn.byteLength); | ||
if (!mapFn) return new this(stringToUTF8(arrayLike)); | ||
const array = new Uint8Array( | ||
mapFn.buffer, | ||
mapFn.byteOffset + thisArg, | ||
length || mapFn.byteLength, | ||
); | ||
array.fill(0); | ||
// fix for Node.js 12.11, todo remove when encodeInto fixed in Node.js | ||
if (arrayLike) this.encoder.encodeInto(arrayLike, array); | ||
if (arrayLike) stringToUTF8(arrayLike, array); | ||
return mapFn; | ||
@@ -370,6 +383,10 @@ } | ||
const code = string.codePointAt(i); | ||
if (code < 0x0080) size += 1; // 1-byte | ||
else if (code < 0x0800) size += 2; // 2-byte | ||
else if (code < 0x10000) size += 3; // 3-byte | ||
else { // 4-byte | ||
if (code < 0x0080) size += 1; | ||
// 1-byte | ||
else if (code < 0x0800) size += 2; | ||
// 2-byte | ||
else if (code < 0x10000) size += 3; | ||
// 3-byte | ||
else { | ||
// 4-byte | ||
size += 4; | ||
@@ -404,19 +421,2 @@ i++; | ||
/* istanbul ignore next */ | ||
if (!StringView.encoder.encodeInto) { | ||
/** | ||
* Polyfill for TextEncoder#encodeInto | ||
* @param {string} source | ||
* @param {Uint8Array} destination | ||
* @returns {Uint8Array} | ||
*/ | ||
StringView.encoder.encodeInto = (source, destination) => { | ||
const encoded = StringView.encoder.encode(source); | ||
const trimmed = encoded.length > destination.length | ||
? encoded.subarray(0, destination.length) : encoded; | ||
destination.set(trimmed); | ||
return destination; | ||
}; | ||
} | ||
module.exports = StringView; |
@@ -26,3 +26,3 @@ const ArrayView = require('./array-view'); | ||
*/ | ||
* [Symbol.iterator]() { | ||
*[Symbol.iterator]() { | ||
const { size } = this; | ||
@@ -29,0 +29,0 @@ for (let i = 0; i < size; i++) { |
@@ -24,3 +24,3 @@ /** | ||
edges = edges || 2; | ||
super((vertices + edges) + 1); | ||
super(vertices + edges + 1); | ||
} | ||
@@ -159,3 +159,3 @@ Object.defineProperties(this, { | ||
*/ | ||
* outEdges(vertex) { | ||
*outEdges(vertex) { | ||
const offset = this[vertex]; | ||
@@ -177,3 +177,3 @@ const nextOffset = this[vertex + 1]; | ||
*/ | ||
* inEdges(vertex) { | ||
*inEdges(vertex) { | ||
const { vertices } = this; | ||
@@ -180,0 +180,0 @@ let edge = 0; |
@@ -79,3 +79,3 @@ const BinaryGrid = require('./binary-grid'); | ||
*/ | ||
* outEdges(vertex) { | ||
*outEdges(vertex) { | ||
const { columns, offset } = this; | ||
@@ -99,3 +99,3 @@ const start = vertex << offset; | ||
*/ | ||
* inEdges(vertex) { | ||
*inEdges(vertex) { | ||
const { rows, offset } = this; | ||
@@ -102,0 +102,0 @@ for (let i = 0; i < rows; i++) { |
@@ -1,2 +0,2 @@ | ||
const BigInt = (global || window).BigInt || Number; | ||
const BigInt = globalThis.BigInt || Number; | ||
@@ -47,3 +47,3 @@ const log2 = { | ||
const b = (a & 0x33333333) + ((a >> 2) & 0x33333333); | ||
return ((b + (b >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; | ||
return (((b + (b >> 4)) & 0xf0f0f0f) * 0x1010101) >> 24; | ||
} | ||
@@ -126,3 +126,80 @@ | ||
/** | ||
* Converts a JS string into a UTF8 byte array. | ||
* Shamelessly stolen from Google Closure: | ||
* https://github.com/google/closure-library/blob/master/closure/goog/crypt/crypt.js | ||
* | ||
* TODO: use TextEncoder#encode/encodeInto when the following issues are resolved: | ||
* - https://bugs.chromium.org/p/v8/issues/detail?id=4383 | ||
* - https://bugs.webkit.org/show_bug.cgi?id=193274 | ||
* | ||
* @param {string} string | ||
* @param {Uint8Array} [bytes] | ||
* @returns {Uint8Array} | ||
*/ | ||
function stringToUTF8(string, bytes) { | ||
const out = bytes || []; | ||
let p = 0; | ||
for (let i = 0; i < string.length; i++) { | ||
let c = string.charCodeAt(i); | ||
if (c < 128) { | ||
out[p++] = c; | ||
} else if (c < 2048) { | ||
out[p++] = (c >> 6) | 192; | ||
out[p++] = (c & 63) | 128; | ||
} else if ( | ||
(c & 0xfc00) === 0xd800 && | ||
i + 1 < string.length && | ||
(string.charCodeAt(i + 1) & 0xfc00) === 0xdc00 | ||
) { | ||
// Surrogate Pair | ||
c = 0x10000 + ((c & 0x03ff) << 10) + (string.charCodeAt(++i) & 0x03ff); | ||
out[p++] = (c >> 18) | 240; | ||
out[p++] = ((c >> 12) & 63) | 128; | ||
out[p++] = ((c >> 6) & 63) | 128; | ||
out[p++] = (c & 63) | 128; | ||
} else { | ||
out[p++] = (c >> 12) | 224; | ||
out[p++] = ((c >> 6) & 63) | 128; | ||
out[p++] = (c & 63) | 128; | ||
} | ||
} | ||
return out; | ||
} | ||
/** | ||
* Converts a UTF8 byte array into a JS string. | ||
* | ||
* @param {Uint8Array} bytes | ||
* @returns {string} | ||
*/ | ||
function UTF8ToString(bytes) { | ||
const out = []; | ||
let pos = 0; | ||
let c = 0; | ||
while (pos < bytes.length) { | ||
const c1 = bytes[pos++]; | ||
if (c1 < 128) { | ||
out[c++] = String.fromCharCode(c1); | ||
} else if (c1 > 191 && c1 < 224) { | ||
out[c++] = String.fromCharCode(((c1 & 31) << 6) | (bytes[pos++] & 63)); | ||
} else if (c1 > 239 && c1 < 365) { | ||
// Surrogate Pair | ||
const u = | ||
(((c1 & 7) << 18) | | ||
((bytes[pos++] & 63) << 12) | | ||
((bytes[pos++] & 63) << 6) | | ||
(bytes[pos++] & 63)) - | ||
0x10000; | ||
out[c++] = String.fromCharCode(0xd800 + (u >> 10)); | ||
out[c++] = String.fromCharCode(0xdc00 + (u & 1023)); | ||
} else { | ||
out[c++] = String.fromCharCode( | ||
((c1 & 15) << 12) | ((bytes[pos++] & 63) << 6) | (bytes[pos++] & 63), | ||
); | ||
} | ||
} | ||
return out.join(''); | ||
} | ||
module.exports = { | ||
@@ -136,2 +213,4 @@ log2, | ||
typeOffsets, | ||
stringToUTF8, | ||
UTF8ToString, | ||
}; |
@@ -31,3 +31,3 @@ /** | ||
edges = edges || 4; | ||
super((vertices + (edges << 1)) + 1); | ||
super(vertices + (edges << 1) + 1); | ||
} | ||
@@ -86,3 +86,2 @@ Object.defineProperties(this, { | ||
/** | ||
@@ -119,3 +118,8 @@ * Returns the weight of the edge between given vertices | ||
for (let i = this[vertices]; i > this[x]; i -= 2) { | ||
[this[i], this[i + 1], this[i - 1], this[i - 2]] = [this[i - 2], this[i - 1], this[i], this[i + 1]]; | ||
[this[i], this[i + 1], this[i - 1], this[i - 2]] = [ | ||
this[i - 2], | ||
this[i - 1], | ||
this[i], | ||
this[i + 1], | ||
]; | ||
} | ||
@@ -174,3 +178,3 @@ // set edge | ||
*/ | ||
* outEdges(vertex) { | ||
*outEdges(vertex) { | ||
const offset = this[vertex]; | ||
@@ -192,3 +196,3 @@ const nextOffset = this[vertex + 1]; | ||
*/ | ||
* inEdges(vertex) { | ||
*inEdges(vertex) { | ||
const { vertices } = this; | ||
@@ -330,3 +334,2 @@ let edge = 0; | ||
module.exports = WeightedAdjacencyListMixin; |
@@ -88,3 +88,3 @@ const GridMixin = require('./grid'); | ||
*/ | ||
* outEdges(vertex) { | ||
*outEdges(vertex) { | ||
const { vertices } = this; | ||
@@ -103,3 +103,3 @@ for (let i = 0; i < vertices; i++) { | ||
*/ | ||
* inEdges(vertex) { | ||
*inEdges(vertex) { | ||
const { vertices } = this; | ||
@@ -158,3 +158,2 @@ for (let i = 0; i < vertices; i++) { | ||
module.exports = WeightedAdjacencyMatrixMixin; |
{ | ||
"name": "structurae", | ||
"version": "3.0.5", | ||
"version": "3.0.6", | ||
"description": "Data structures for performance-sensitive modern JavaScript applications.", | ||
@@ -52,2 +52,3 @@ "main": "index.js", | ||
"eslint-config-airbnb-base": "^14.1.0", | ||
"eslint-config-prettier": "^6.10.1", | ||
"eslint-plugin-import": "^2.20.2", | ||
@@ -81,3 +82,46 @@ "jest": "^25.2.7", | ||
"node": ">=11.0.0" | ||
}, | ||
"prettier": { | ||
"printWidth": 100, | ||
"singleQuote": true, | ||
"trailingComma": "all" | ||
}, | ||
"eslintConfig": { | ||
"extends": [ | ||
"airbnb-base", | ||
"prettier" | ||
], | ||
"env": { | ||
"node": true, | ||
"jest": true | ||
}, | ||
"globals": { | ||
"globalThis": false | ||
}, | ||
"rules": { | ||
"max-classes-per-file": 1, | ||
"no-bitwise": 0, | ||
"no-plusplus": 0, | ||
"no-continue": 0, | ||
"no-restricted-syntax": 1, | ||
"no-nested-ternary": 1, | ||
"no-labels": 1, | ||
"no-param-reassign": [ | ||
2, | ||
{ | ||
"props": false | ||
} | ||
], | ||
"valid-jsdoc": [ | ||
2, | ||
{ | ||
"prefer": { | ||
"return": "returns" | ||
}, | ||
"requireReturnDescription": false, | ||
"requireParamDescription": false | ||
} | ||
] | ||
} | ||
} | ||
} |
219678
1.28%6040
3.99%9
12.5%