Skip to content

Instantly share code, notes, and snippets.

@LikeLakers2
Last active April 15, 2020 01:02
Show Gist options
  • Save LikeLakers2/a2cc695d56c84835aa7f24b5415406f4 to your computer and use it in GitHub Desktop.
Save LikeLakers2/a2cc695d56c84835aa7f24b5415406f4 to your computer and use it in GitHub Desktop.
bitsetlike
// We can move `layer0`, `layer1`, `layer2`, `layer3` here, or just remove them entirely
// Remove `add()`, `remove()`, `clear()` (replaced with `set()`, `unset()`, `clear()` from BitSetLike)
// The number of layers -- useful for get_from_layer()
fn layer_count() -> u32;
// CHECK: Good idea?
// Gets a layer as a slice
fn get_layer_as_slice(&self, layer: u32) -> &[usize];
// Returns a arbitrary index usize from a arbitrary index layer
fn get_from_layer(&self, layer: u32, idx: u32) -> usize;
// Checks if a bit is set
// idx is an index of the bottom-most layer
// NOTE: We may be able to include a default implementation using get_from_layer() and layer_count()
fn contains(&self, idx: u32) -> bool;
// CHECK: Should we do `contains_set()` here? Should it require both BitSets to be the same class?
// Sets a bit. Returns true if the bit was already set
// idx is an index of the bottom-most layer
fn set(&mut self, idx: u32) -> bool;
// Unsets a bit. Returns true if the bit was already unset
// idx is an index of the bottom-most layer
fn unset(&mut self, idx: u32) -> bool;
// Clears the bitset, setting it to 0
// NOTE: If we include a default implementation, it probably won't be very efficient
fn clear(&mut self);
// We can keep `is_empty()`, `iter()`, and `par_iter()`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment