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

Complete implementation of standard typed arrays #3

Open
21 of 43 tasks
swiing opened this issue Apr 28, 2022 · 4 comments
Open
21 of 43 tasks

Complete implementation of standard typed arrays #3

swiing opened this issue Apr 28, 2022 · 4 comments

Comments

@swiing
Copy link
Owner

swiing commented Apr 28, 2022

Current code only partially implements standard features of typed arrays. This issue provides a place to track progress and view it all in one shot.

PRs welcome!

Constructor

  • new TypedArray()
  • new TypedArray(length)
  • new TypedArray(typedArray)
  • new TypedArray(object)
  • new TypedArray(buffer): see here

Unrelevant (= won't implement)

  • new TypedArray(buffer, byteOffset): see here
  • new TypedArray(buffer, byteOffset, length): see here

Static properties

  • BYTES_PER_ELEMENT
  • name
  • get BitArray[@@species]

Static methods

  • from()
  • of()

Instance properties

  • buffer
  • byteLength
  • byteOffset
  • length

Instance methods

  • at(): see here for discussion
  • copyWithin()
  • entries()
  • every()
  • fill()
  • filter()
  • find()
  • findIndex()
  • forEach()
  • includes()
  • indexOf()
  • join()
  • keys()
  • lastIndexOf()
  • map()
  • reduce()
  • reduceRight()
  • reverse()
  • set()
  • slice()
  • some()
  • sort()
  • subarray()
  • values()
  • toString(): see here for note on implementation.
  • [@@iterator]()

Irrelevant (= won't implement)

  • toLocaleString(): there is no local variation to displaying 1s or 0s.
@rollie42
Copy link

rollie42 commented May 1, 2022

Fwiw, I got a hacky horrible inefficient version of "ArrayBuffer to BitArray" to work via the following

    const vals = []
    for(const b of new Uint8Array(buffer)) {
        for (let i = 0; i < 8; i++) {
            vals.push(!!(b & (1 << i)))
        }
    }
    let arr = BitArray.from(vals)

Obviously the correct version doesn't have so much unnecessary byte->string->byte conversion :)

@swiing
Copy link
Owner Author

swiing commented May 3, 2022

Indeed! :)

Tbh, I have not yet made my mind whether it makes sense to construct a BitArray by passing an array buffer to the constructor. FFS...

@rollie42
Copy link

rollie42 commented May 4, 2022

I actually have a use case! I have a settings object in my react app; it has a great number of boolean or near boolean enums. I want to store the user settings in a query param, so I load the settings into a bit array, and then turn that into base64 from that array buffer. This allows the settings to be shared or survive a page reload. To deserialize, I load the bas64 string back into array buffer, and then into the bitarray to reconstruct the settings.

@swiing
Copy link
Owner Author

swiing commented May 4, 2022

@rollie42, in order to not pollute this general-purpose issue, I have created a specific issue here.

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

No branches or pull requests

2 participants