Skip to content

Cleanup #14

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

Merged
merged 2 commits into from
May 3, 2022
Merged

Cleanup #14

merged 2 commits into from
May 3, 2022

Conversation

yegct
Copy link
Contributor

@yegct yegct commented Apr 13, 2022

What

Minor cleanups. This PR clears the way for this future PR allowing dumping and loading contents to disk.

Specifically:

  • Remove unnecessary lib/bitarray-array.rb file
  • Move lib/bitarray.rb to lib/bitarray/bit_array.rb, add lib/bitarray.rb that just requires the file from the subdirectory. This makes it easy to add additional classes, later.
  • Add reverse_byte accessor
  • Make byte_position private
  • Move test/test_bitarray.rb to test/test_bit_array.rb

Tests

$ ruby test/test_bit_array.rb 
Run options: --seed 38456

# Running:

.............

Finished in 0.008990s, 1446.1240 runs/s, 468321.7074 assertions/s.

13 runs, 4210 assertions, 0 failures, 0 errors, 0 skips

Additionally, note there are almost no code changes here. Nevertheless, I tested it with my bitarray consisting of a little over 2 billion bits and the code worked identically to that in master.

@yegct yegct mentioned this pull request Apr 13, 2022
@@ -1,59 +1 @@
class BitArray
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to lib/bitarray/bit_array.rb.

@@ -0,0 +1,58 @@
class BitArray
attr_reader :field, :reverse_byte, :size
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added reverse_byte to the publicly accessible attributes.

@field.each_byte.inject(0) { |a, byte| (a += 1; byte &= byte - 1) while byte > 0 ; a }
end

private def byte_position(position)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Marked this method private.

@peterc peterc merged commit 71b401c into peterc:main May 3, 2022
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 this pull request may close these issues.

2 participants