Skip to content

Commit

Permalink
refactor(vectors): update mem mapped type handling
Browse files Browse the repository at this point in the history
BREAKING CHANGE: buffer mapping fns use new type string consts

- part of umbrella-wide changes to thi.ng/api Type aliases (see a333d41)
  • Loading branch information
postspectacular committed Feb 2, 2021
1 parent 0ebd889 commit 4a6e9b1
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions packages/vectors/src/buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
Type,
typedArray,
TypedArrayTypeMap,
TYPEDARRAY_CTORS,
} from "@thi.ng/api";
import type { ReadonlyVec, Vec, VecOpSV, VectorConstructor } from "./api";

Expand All @@ -15,11 +14,11 @@ import type { ReadonlyVec, Vec, VecOpSV, VectorConstructor } from "./api";
* and `byteStride` the number of bytes between resulting vectors
* (defaults to `size * SIZEOF[type]`). It's user's responsibility to
* ensure these two values are compatible with the chosen array type
* (i.e. for `Type.F32`, these MUST be multiples of 4).
* (i.e. for `"f32"`, these MUST be multiples of 4).
*
* @example
* ```ts
* mapBuffer(Type.F32, new ArrayBuffer(32), 4, 2)
* mapBuffer("f32", new ArrayBuffer(32), 4, 2)
* // [
* // Float32Array [ 0, 0 ],
* // Float32Array [ 0, 0 ],
Expand All @@ -44,9 +43,8 @@ export const mapBuffer = <T extends Type>(
byteStride = size * SIZEOF[type]
) => {
const res: TypedArrayTypeMap[T][] = [];
const ctor = TYPEDARRAY_CTORS[type];
for (; --num >= 0; byteOffset += byteStride) {
res.push(<any>new ctor(buf, byteOffset, size));
res.push(typedArray(type, buf, byteOffset, size));
}
return res;
};
Expand Down

0 comments on commit 4a6e9b1

Please sign in to comment.