Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bit-TypedArray does not support bitOffset, length in constructor #1

Open
zipzapzanigan opened this issue Apr 23, 2022 · 1 comment
Open

Comments

@zipzapzanigan
Copy link

zipzapzanigan commented Apr 23, 2022

> import BitArray from "@bitarray/typedarray"
undefined
> let d = new BitArray([0,1,1], 0, 10)
<repl>.ts:5:31 - error TS2554: Expected 1 arguments, but got 3.

BitArray doesn't seem to support both buffer, byteOffset and length in the constructor, as other TypedArrays do:

new TypedArray(buffer, byteOffset, length)

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray#constructor

@swiing
Copy link
Owner

swiing commented Apr 24, 2022

Thanks for the comment.

I would suggest this requires careful thinking. For standards TypedArrays, it is always possible to match boundaries however one likes, with a proper combination of byteOffset and length. But, for bit arrays, it is not possible to match all bit boundaries.

Ideally, we should go for bitOffset rather than byteOffset (as suggested by you in the issue title). But this leads to other issues (this is not how array buffers work).

At this stage, I am not convinced byteOffset makes sense here, and has any practical use. I am rather inclined to allow calling the constructor with a buffer instance, but no other arguments (tbd). Are you with me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants