Skip to content
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

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

Skyseaee
Copy link

add insert sort and heap sort in sort.c and add related unit test.

@codecov-commenter
Copy link

codecov-commenter commented Jun 25, 2023

Codecov Report

❗ No coverage uploaded for pull request base (main@3ed2c48). Click here to learn what that means.
The diff coverage is n/a.

❗ 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) {
Copy link
Collaborator

@liuq19 liuq19 Jun 26, 2023

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, 避免越界访问

Copy link
Author

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.

Copy link
Collaborator

Choose a reason for hiding this comment

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

ok, thanks

@Skyseaee
Copy link
Author

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) {
Copy link
Collaborator

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。

native/sort.c Show resolved Hide resolved
Copy link
Collaborator

@liuq19 liuq19 left a 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.

@CLAassistant
Copy link

CLAassistant commented Jul 13, 2023

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ liuq19
❌ Skyseaee
You have signed the CLA already but the status is still pending? Let us recheck it.

@AsterDY AsterDY marked this pull request as draft January 24, 2024 12:48
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.

None yet

4 participants