-
-
Notifications
You must be signed in to change notification settings - Fork 363
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
Extend SetU
#4262
Extend SetU
#4262
Conversation
How about we change this PR to re-implement the sets properly? |
Also I couldn't find any unit tests specifically for the hash tables. Which should be definitely added. |
There are some in |
@ret2libc Any opinion on the |
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.
I like the approach with the iter if it works well ;)
Before using it here, though, i'd like to have it in the hashtable as well so we can really test if it works well (with ASAN).
This comment was marked as resolved.
This comment was marked as resolved.
Ideally |
This comment was marked as resolved.
This comment was marked as resolved.
- Add a getter for length of SetU. - Add a foreach macro.
Co-authored-by: pelijah <[email protected]>
Co-authored-by: pelijah <[email protected]>
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.
foreach
and size method for SetS
SetUIter it; | ||
set_u_foreach (set_u, it) { | ||
x++; | ||
bool matches = it.v == 0x5050505 || it.v == 0x6060606; | ||
mu_assert_true(matches, "Set contained ill-formed value."); | ||
} |
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.
I would prefer rz_list_foreach
like variant with separate value
variable:
SetUIter it; | |
set_u_foreach (set_u, it) { | |
x++; | |
bool matches = it.v == 0x5050505 || it.v == 0x6060606; | |
mu_assert_true(matches, "Set contained ill-formed value."); | |
} | |
SetUIter it; | |
ut64 val; | |
set_u_foreach (set_u, it, val) { | |
x++; | |
bool matches = val == 0x5050505 || val == 0x6060606; | |
mu_assert_true(matches, "Set contained ill-formed value."); | |
} |
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.
@ret2libc your opinion?
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.
Don't really have strong feelings about it. Separated variable means the type is more explicit, which is probably worth the trade against the extra line. But as long as we have a foreach
without a callback, I am happy.
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.
Line 35 in ea460e5
for (it = list->head; it && (pos = it->elem, 1); it = it->next) |
Adapted for your case: (val = iter.v, 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.
I think the one with the explicit value is better.
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.
It will be more important for the SetP, where we have a room for type ambiguity.
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.
i think the value should always be a pointer. so you can read and write the value.
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.
i think the value should always be a pointer. so you can read and write the value.
For HT, yes. But in case of sets value is a key.
Then let me extend the PR to include more foreach macros: So the todo list would be:
|
If you are going to implement typedef struct Ht_(iter_t) {
st64 ti; ///< Table index
ut64 bi; ///< Bucket index
HT_(Kv) *kv; ///< Current KV-pair. Stop iteration if kv is NULL.
} HT(Iter); Also you need to provide in for (Ht_(iter_init)(&iter); iter.kv != NULL && ... ; Ht_(iter_next)(&iter)) |
Implemented by #4500 |
Your checklist for this pull request
Detailed description
Did not add the doxygen yet. Wanted to get some feedback first.
Test plan
Added
Closing issues
...