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

Implement storage::BitVec #10

Closed
Robbepop opened this issue Jan 1, 2019 · 3 comments
Closed

Implement storage::BitVec #10

Robbepop opened this issue Jan 1, 2019 · 3 comments
Labels
A-ink_storage [ink_storage] Work Item B-design Designing a new component, interface or functionality.

Comments

@Robbepop
Copy link
Collaborator

Robbepop commented Jan 1, 2019

Storage Bitset

The pdsl_core is currently missing an efficient and elegant way to handle bit sets.
Using a storage::Vec<bool> is very inefficient, since it would require storing every single bit in a different storage cell and using storage::Vec<[u8; 32]> (or similar) would require implementation effort from the user.

The storage::Bitset should provide the most basic functionality for sets of bits and should be very efficient in the way that it reduces contract storage access to a minimum while keeping up with overall performance.

Bits stored in the storage::Bitset should be bundled - for example as [u8; 32]. This allows efficient contract storage access and lots of cache efficiency on the memory side.

A storage::Bitset should allow iteration and the following APIs:

  • symmetric_difference(&mut self, other: &Bitset) *
  • difference(&mut self, other: &Bitset) *
  • union(&mut self, other: &Bitset) *
  • intersection(&mut self, other: &Bitset) *

(*) Means that this API is not final.

  • is_disjoint(&self, other: &Bitset) -> bool
  • is_subset(&self, other: &Bitset) -> bool
  • is_superset(&self, other: &Bitset) -> bool
  • len(&self) -> u32
  • is_empty(&self) -> bool
  • contains(&self, n: i32) -> bool

Depending on the concrete bit set implementation we could either have one of the following APIs:

  • storage::Bitset based on storage::Vec
    • push
    • pop
  • storage::Bitset based on storage::HashMap
    • insert
    • remove

We can also think about implementing both of the above versions.

@Robbepop Robbepop added B-design Designing a new component, interface or functionality. A-ink_storage [ink_storage] Work Item D-medium labels Jan 1, 2019
@Robbepop Robbepop changed the title Implement storage::Bitset Implement storage::BitVec Feb 20, 2019
@Robbepop
Copy link
Collaborator Author

Commit ff1421c implements an initial version of a BitVec that is more similar to a vector than to a set of bits. However, this is the first step taken and could also potentially be used for many use bases.

@Robbepop
Copy link
Collaborator Author

Commit 7155c9b fixes a bug that first_set_position returned Some bit if the last set bit was just popped right before.

@Robbepop
Copy link
Collaborator Author

Robbepop commented Mar 4, 2019

Closing this since its fundamentals are implemented.

@Robbepop Robbepop closed this as completed Mar 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ink_storage [ink_storage] Work Item B-design Designing a new component, interface or functionality.
Projects
None yet
Development

No branches or pull requests

1 participant