Skip to content

Conversation

@35C4n0r
Copy link
Collaborator

@35C4n0r 35C4n0r commented Sep 7, 2023

New logic for bitcode which uses sets.

Signed-off-by: Jay <jaykumar20march@gmail.com>
Copy link
Member

@pombredanne pombredanne left a 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

# Return a string of 0s and 1s representing the content in memory
# of the intbitset.
# """
# return bin(self.bitset)[2:]
Copy link
Member

Choose a reason for hiding this comment

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

What about this:

Suggested change
# 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):
Copy link
Member

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(["
Copy link
Member

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) + ", "
Copy link
Member

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

if item >= n:
raise IndexError("Sequence index out of range")
return elements[item]
return sorted(list(self.bitset))[item]
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return sorted(list(self.bitset))[item]
if item not in self.bitset:
raise KeyError(... some message)
return item

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])
Copy link
Member

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>
@35C4n0r
Copy link
Collaborator Author

35C4n0r commented Sep 9, 2023

Thanks here are some nitpickings for your consideration. Are you using this new code already in nexB/scancode-toolkit#3506

Yes.

Signed-off-by: Jay <jaykumar20march@gmail.com>
Signed-off-by: Jay <jaykumar20march@gmail.com>
Signed-off-by: Jay <jaykumar20march@gmail.com>
@35C4n0r
Copy link
Collaborator Author

35C4n0r commented Sep 9, 2023

@35C4n0r 35C4n0r requested a review from pombredanne September 9, 2023 17:10
@35C4n0r 35C4n0r marked this pull request as draft September 10, 2023 11:16
Signed-off-by: Jay <jaykumar20march@gmail.com>
Signed-off-by: Jay <jaykumar20march@gmail.com>
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