mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-15 16:01:30 +00:00
Use macro style for more internal helpers; Update dist files
This commit is contained in:
@ -1,4 +1,7 @@
|
||||
import { AL_MASK, MAX_SIZE_32 } from "./allocator";
|
||||
import {
|
||||
AL_MASK,
|
||||
MAX_SIZE_32
|
||||
} from "./allocator";
|
||||
|
||||
/** Size of an ArrayBuffer header. */
|
||||
export const HEADER_SIZE: usize = (offsetof<ArrayBuffer>() + AL_MASK) & ~AL_MASK;
|
||||
|
@ -1,10 +1,10 @@
|
||||
import {
|
||||
HEADER_SIZE as STRING_HEADER_SIZE
|
||||
HEADER_SIZE
|
||||
} from "./string";
|
||||
|
||||
/** Computes the 32-bit hash of a value of any type. */
|
||||
@inline
|
||||
export function hash<T>(key: T): u32 {
|
||||
export function HASH<T>(key: T): u32 {
|
||||
// branch-level tree-shaking makes this a `(return (call ...))`
|
||||
if (isString(key)) {
|
||||
return hashStr(key);
|
||||
@ -66,7 +66,7 @@ function hash64(key: u64): u32 {
|
||||
function hashStr(key: string): u32 {
|
||||
var v = FNV_OFFSET;
|
||||
for (let i: usize = 0, k: usize = key.length << 1; i < k; ++i) {
|
||||
v = (v ^ <u32>load<u8>(changetype<usize>(key) + i, STRING_HEADER_SIZE)) * FNV_PRIME;
|
||||
v = (v ^ <u32>load<u8>(changetype<usize>(key) + i, HEADER_SIZE)) * FNV_PRIME;
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
@ -4,12 +4,12 @@ import {
|
||||
} from "./arraybuffer";
|
||||
|
||||
import {
|
||||
compareUnsafe,
|
||||
compareUnsafe
|
||||
} from "./string";
|
||||
|
||||
/** Obtains the default comparator for the specified type. */
|
||||
/** Obtains the default comparator for the specified value type. */
|
||||
@inline
|
||||
export function defaultComparator<T>(): (a: T, b: T) => i32 {
|
||||
export function COMPARATOR<T>(): (a: T, b: T) => i32 {
|
||||
if (isInteger<T>()) {
|
||||
if (isSigned<T>() && sizeof<T>() <= 4) {
|
||||
return (a: T, b: T): i32 => (<i32>(a - b));
|
||||
@ -44,8 +44,27 @@ export function defaultComparator<T>(): (a: T, b: T) => i32 {
|
||||
}
|
||||
}
|
||||
|
||||
@inline
|
||||
export function SORT<T>(
|
||||
buffer: ArrayBuffer,
|
||||
byteOffset: i32,
|
||||
length: i32,
|
||||
comparator: (a: T, b: T) => i32
|
||||
): void {
|
||||
if (isReference<T>()) {
|
||||
// TODO replace this to faster stable sort (TimSort) when it implemented
|
||||
insertionSort<T>(buffer, byteOffset, length, comparator);
|
||||
} else {
|
||||
if (length < 256) {
|
||||
insertionSort<T>(buffer, byteOffset, length, comparator);
|
||||
} else {
|
||||
weakHeapSort<T>(buffer, byteOffset, length, comparator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Sorts an Array with the 'Insertion Sort' algorithm. */
|
||||
export function insertionSort<T>(
|
||||
function insertionSort<T>(
|
||||
buffer: ArrayBuffer,
|
||||
byteOffset: i32,
|
||||
length: i32,
|
||||
@ -65,7 +84,7 @@ export function insertionSort<T>(
|
||||
}
|
||||
|
||||
/** Sorts an Array with the 'Weak Heap Sort' algorithm. */
|
||||
export function weakHeapSort<T>(
|
||||
function weakHeapSort<T>(
|
||||
buffer: ArrayBuffer,
|
||||
byteOffset: i32,
|
||||
length: i32,
|
@ -7,9 +7,8 @@ import {
|
||||
} from "./arraybuffer";
|
||||
|
||||
import {
|
||||
insertionSort,
|
||||
weakHeapSort
|
||||
} from "./array";
|
||||
SORT as SORT_IMPL
|
||||
} from "./sort";
|
||||
|
||||
/** Typed array base class. Not a global object. */
|
||||
export abstract class TypedArray<T> {
|
||||
@ -106,18 +105,8 @@ export function SORT<TArray extends TypedArray<T>, T>(
|
||||
}
|
||||
return array;
|
||||
}
|
||||
if (isReference<T>()) {
|
||||
// TODO replace this to faster stable sort (TimSort) when it implemented
|
||||
insertionSort<T>(buffer, byteOffset, length, comparator);
|
||||
return array;
|
||||
} else {
|
||||
if (length < 256) {
|
||||
insertionSort<T>(buffer, byteOffset, length, comparator);
|
||||
} else {
|
||||
weakHeapSort<T>(buffer, byteOffset, length, comparator);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
SORT_IMPL<T>(buffer, byteOffset, length, comparator);
|
||||
return array;
|
||||
}
|
||||
|
||||
@inline
|
||||
|
Reference in New Issue
Block a user