-
-
Notifications
You must be signed in to change notification settings - Fork 2
add: new logic for bitcode #4
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Jay <jaykumar20march@gmail.com>
pombredanne
left a comment
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.
Thanks here are some nitpickings for your consideration. Are you using this new code already in aboutcode-org/scancode-toolkit#3506
src/bitcode/bitcode.py
Outdated
| # Return a string of 0s and 1s representing the content in memory | ||
| # of the intbitset. | ||
| # """ | ||
| # return bin(self.bitset)[2:] |
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.
What about this:
| # return bin(self.bitset)[2:] | |
| def strbits(self): | |
| """ | |
| Return a string of 0s and 1s representing the content in memory | |
| of the intbitset. | |
| """ | |
| bits = '0' * len(self.bitset) | |
| for i in self.bitset: | |
| bits[i] = '1' | |
| return bits |
| yield size | ||
| size -= 1 | ||
|
|
||
| def __hash__(self): |
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.
are intbitset hashable?
| def __str__(self): | ||
| binary = bin(self.bitset)[2:] | ||
| n = len(binary) | ||
| ans = "intbitset([" |
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.
You should use bitcode there
| n -= 1 | ||
| ans = ans.rstrip(', ') | ||
| for char in self.bitset: | ||
| ans += str(char) + ", " |
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.
You may consider accumulating in a list and ", ".join the list at the end
src/bitcode/bitcode.py
Outdated
| if item >= n: | ||
| raise IndexError("Sequence index out of range") | ||
| return elements[item] | ||
| return sorted(list(self.bitset))[item] |
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.
| return sorted(list(self.bitset))[item] | |
| if item not in self.bitset: | |
| raise KeyError(... some message) | |
| return item |
tests/test_bitcode.py
Outdated
| def test_len(self): | ||
| A = intbitset([100, 200, 300, 1]) | ||
| self.assertEqual(len(A), len([100, 200, 300, 1])) | ||
| A = intbitset([10**5, 100, 200, 300, 1]) |
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.
You should add new tests, but do not change existing intbitset tests
Signed-off-by: Jay <jaykumar20march@gmail.com>
Yes. |
Signed-off-by: Jay <jaykumar20march@gmail.com>
Signed-off-by: Jay <jaykumar20march@gmail.com>
Signed-off-by: Jay <jaykumar20march@gmail.com>
|
Also I've added tests from intbitset |
Signed-off-by: Jay <jaykumar20march@gmail.com>
Signed-off-by: Jay <jaykumar20march@gmail.com>
New logic for bitcode which uses sets.