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
feat: insert sort and heap sort in sort.c #467
base: main
Are you sure you want to change the base?
Conversation
…sonic into feat/insert_sort_and_heap_sort
…sonic into feat/insert_sort_and_heap_sort
Codecov Report
❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more. @@ Coverage Diff @@
## main #467 +/- ##
=======================================
Coverage ? 77.92%
=======================================
Files ? 63
Lines ? 10418
Branches ? 0
=======================================
Hits ? 8118
Misses ? 1947
Partials ? 353 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
native/sort.c
Outdated
} | ||
|
||
static always_inline int _strcmp(const char *p,const char *q){ | ||
while(*p && *q && *p == *q) { |
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.
这里仍然可能有越界访问,例如 p 和 q 是完全相等的key,同时不以 '\0' 结尾,那么就会访问到越界的内存。可以先判断是否超过 key.len, 避免越界访问
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, i will fix that.
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.
ok, thanks
i fix the problem in the new commit. |
native/sort.c
Outdated
static always_inline bool less(MapPair lhs, MapPair rhs) { | ||
size_t index = 0; | ||
size_t size = min(lhs.key.len, rhs.key.len); | ||
while(index < size && *lhs.key.buf && *rhs.key.buf && *lhs.key.buf == *rhs.key.buf) { |
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.
这里比较长度之后,应该不用确认 *lhs.key.buf && *rhs.key.buf了,另外这里可以使用局部变量表示两个lhs.key.buf 和 rhs.key.buf。
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, LGTM. We will consider merging it in the future when needed.
|
add insert sort and heap sort in sort.c and add related unit test.