Messages in this thread | | | Subject | Re: [PATCH -mm 1/2] sort: Add obj_sort() for sorting all kinds of random-accessible objects | From | Matt Mackall <> | Date | Fri, 12 Sep 2008 10:56:04 -0500 |
| |
On Fri, 2008-09-12 at 19:55 +0800, Lai Jiangshan wrote: > current sort can only sort objects on continuous memory, > but sometimes we need to sort objects on noncontinuous memory, > this patch provide obj_sort() for this. > > Sometimes a C struct(the container of objects, or objects) may be designed > with some high-level language's semantic meaning. obj_sort() can sort > for them. > > obj_sort() is need for sort pids for cgroup.tasks file.
Ok, if I understand this correctly, your new function basically changes:
cmp(void *a, void *b) to cmp(void *obj, int a, int b) swap(void *a, void *b, int size) to swap(void *obj, int a, int b)
Since neither function actually looks at the data directly, it seems we could make a unified sort function with:
cmp(void *base, int a, int b) swap(void *base, int a, int b, int size)
What is the underlying data structure you're sorting by the way? Years ago, I wrote a very nice merge sort for linked lists that I never got around to submitting.
-- Mathematics is the supreme nostalgia of our time.
| |