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

optimize: use C implement quick sort #423

Open
liuq19 opened this issue May 19, 2023 · 3 comments
Open

optimize: use C implement quick sort #423

liuq19 opened this issue May 19, 2023 · 3 comments
Assignees
Labels
good first issue Good for newcomers

Comments

@liuq19
Copy link
Collaborator

liuq19 commented May 19, 2023

We want use C implement quick sort for higer performance.

The origin go implement is https://github.com/bytedance/sonic/blob/main/encoder/sort.go#L21

@Monib007
Copy link

Hey would you assign me this task? I'm just beginning to open source and I'd like to contribute.

@liuq19
Copy link
Collaborator Author

liuq19 commented May 22, 2023

Sure, Welcome~

@liuq19
Copy link
Collaborator Author

liuq19 commented May 22, 2023

Currently, Sonic has implemented a fast string sorting algorithm in Golang, which can be ported to C language for further optimization of sorting time. The specific sorting algorithm can refer to the existing Golang implementation in Sonic, which has implemented the 3-way Radix Quicksort. The code can be found at https://github.com/bytedance/sonic/blob/main/encoder/sort.go#L21.

You can implement quick-sort as follows:

typedef struct MapPair{
GoString key;
void* value;
} MapPair;

// The following interface is used to swap MapPair.
void swap(MapPair* lhs, MapPair* rhs) {
MapPair temp;
temp = *lhs;
*lhs = *rhs;
*rhs = temp;
}

// Sort the MapPair array kvs by the string key, n is the length of MapPiar array.
// Implement the quick-sort algorithm in a non-recursive way. 
// A Stack data structure needs to be implemented for non-recursive implementation. The max stack depth may be 4096.
// If the stack space is exceeded, return an error -1, otherwise return 0.
long quick_sort(MapPair* kvs, size_t n, Stack* stk) {

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants