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: Multiple OrderBy #152
Comments
This is a great idea ! We could change this Also, for the red-black tree, it's not a problem but how would you achieve the in-place sort? |
Oh, of course the variadic form will keep working for existing users, that makes life easy. My off-the-cuff thinking was to just use |
The problem i see using Currently, we are generating a slice of bytes from the value of the chosen field (see here) Example: which would be sorted like this: WDYT? |
Unfortunately, that doesn't work as expected, consider: // OrderBy("Name, "Age", "Country")
A = Person{Name: "John12", Age: 9, Country: "France"}
B = Person{Name: "John" Age: 15, Country: "Germany"}
// A sorting key: `John129France`
// B sorting key: `John15Germany` Expected result ( This is why I mentioned the issue with arbitrary padding - to use a single string for comparison you'd have to pad each field to the maximum length from all values, which you don't know ahead of time, and the keys would blow out massively in memory and comparison time. As an aside, time-complexity of the tree sort should be worst-case |
You are right, i spoke too fast. Furthermore, it's more interesting to compare non encoded values together than encoded ones since they are already loaded in memory, and i don't see any other solution to keep using the rb tree. Let's try with the |
Results are sorted by the specified fields with descending precedence. Fixes asdine#152
The limitation of a single
OrderBy
field is somewhat problematic, requiring the user to do a second sort pass when multi-field ordering is required.I'd be happy to help produce a PR, but I'd appreciate some guidance. The red-black tree would have to go, since we can't pad arbitrary-length values to obtain correct sorting over multiple keys. Since all values end up in memory anyway, would performing an in-place sort after filtering be acceptable?
The other side is the API - as
OrderBy
currently takes a string, I guess the way to deal with it without breaking the API is to allowOrderBy
to be called multiple times.Thoughts?
The text was updated successfully, but these errors were encountered: