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

Useful methods that can be used in combination with Buffer.Slice(). #5

Open
tunabay opened this issue Sep 20, 2021 · 1 comment
Open
Labels
enhancement New feature or request

Comments

@tunabay
Copy link
Owner

tunabay commented Sep 20, 2021

With the introduction of the Buffer.Slice() method, the expected usage of this package has changed. For example, it's more natural to replace .XxxAt() methods with .Slice().Xxx() combination.

Based on this change, it would be nice to add some useful methods that can be used in combination with the Buffer.Slice() method.

@tunabay tunabay added the enhancement New feature or request label Sep 20, 2021
@tunabay tunabay mentioned this issue Oct 2, 2021
@tunabay
Copy link
Owner Author

tunabay commented Oct 2, 2021

Draft plan

Add:

  • func (buf *Buffer) And(x *Buffer)
  • func (buf *Buffer) Or(x *Buffer)
  • func (buf *Buffer) Xor(x *Buffer)
  • func (buf *Buffer) ToggleBits()

May deprecate:

  • func (buf *Buffer) AndAt(off int, x BitArrayer).Slice().And()
  • func (buf *Buffer) OrAt(off int, x BitArrayer).Slice().Or()
  • func (buf *Buffer) XorAt(off int, x BitArrayer).Slice().Xor()
  • func (buf *Buffer) ToggleBitsAt(off, nBits int).Slice().ToggleBits()
  • func (buf *Buffer) BitArrayAt(off, nBits int) *BitArray.Slice().BitArray()
  • func (buf *Buffer) FillBitsAt(off, nBits int, bit byte).Slice().FillBits()

To be considered:

  • And/Or/Xor arguments should be *Buffer type instead of BitArrayer type to minimize bit-shifts and copies. BitArrayer type arguments increase bit-shifting.
  • But it is also better to be able to accept BitArrayer type.
  • An option to branch processing by a type switch or type assertion. with concerns about performance.
  • Another option is to have another methods like AndBitArray().

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

No branches or pull requests

1 participant