-
Notifications
You must be signed in to change notification settings - Fork 186
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 BitArray
and replace trie.Key
#2322
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2322 +/- ##
==========================================
- Coverage 74.71% 74.68% -0.04%
==========================================
Files 110 111 +1
Lines 12105 12524 +419
==========================================
+ Hits 9044 9353 +309
- Misses 2364 2478 +114
+ Partials 697 693 -4 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some comments. Let. me know what you think. Thanks for detailing the implementation!
ad6a3ba
to
41fc99c
Compare
c7fd009
to
2692494
Compare
7ba050a
to
7f479c1
Compare
6e68d5f
to
b67ff0a
Compare
core/trie/bitarray.go
Outdated
func (b *BitArray) SetBytes(length uint8, data []byte) *BitArray { | ||
b.setBytes32(data) | ||
b.len = length | ||
b.truncateToLength() | ||
return b | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This panics if data isn't at least 32 bytes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, sounds right, added the new changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That new SetBytes
function is wild lol :) Guess it's more performant than handling in a loop or something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah hahahah
minor minor fix
This reverts commit 5b6558b.
6a2ad59
to
7c4aeb3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice work!!
This PR implements a new data structure
BitArray
to replacetrie.Key
. The reasons being:Misleading representation
trie.Key
doesn't actually just represent a Trie key in our use case. But rather, it’s a special data type that we use to just represent a fixed size of bit array with the number of bits used specified.Inefficient operations
The current implementation of the bitwise operations is scattered all around the place. We implement ourselves for some, and for others, we rely on conversion.
BitArray
implements everything from scratch without unnecessary conversion.Regarding
BitArray
:trie.Key
Credits: some implementation details are inspired by
https://github.com/holiman/uint256