Conversation
Signed-off-by: Jay <jaykumar20march@gmail.com>
pombredanne
left a comment
There was a problem hiding this comment.
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.
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): |
| def __str__(self): | ||
| binary = bin(self.bitset)[2:] | ||
| n = len(binary) | ||
| ans = "intbitset([" |
There was a problem hiding this comment.
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.
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.
| 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.
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.