Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
I get that there is value in learning. However, the last time I wrote a sort out of any need was over 20 years ago. Now I just write predicates and let someone smarter than me sort my shit. Also, doing gui work and most sorts are 10 items or less.
-
@12bitfloat ranked sort
aaaa don't wanna paste my code
basically get value of the 5 fields, sort those values, then use indices of those values later to rank sort the whole "struct"
but I ended up making a new vec with the 5 fields on top of it cuz 4 of the 5 fields were f64 which will have rounding errors... so I cast it to *100 and round to u8 to get a clean percentage, and then re-used those values later just in case rounding errors
so it's just a mess I guess. whatever my code can't not look ugly
what would be nicer is probably some kind of macro but that would look even worse -
@12bitfloat figured the ai could figure it out but it was even worse at it
https://blackbox.ai/chat/waAleX6/...
*giggles drunkenly* -
in your example the first compare would be more important than the other fields
I was making every field equally important
actually the way I wrote it you could put a weight beside each field
fuck you know what maybe I'll be lazy
I won't write a full example:
idk why I wrote this out and I didn't give it any data: https://play.rust-lang.org//...
but it is definitely inelegant. it does work though -
@jestdotty That's far from a basic bitch sort though
I still don't really understand what you are achieving with this lol -
@12bitfloat kendall Tau correlation ranks data then checks if the order of the ranks is the same between two different arrays
https://blackbox.ai/chat/oI5TnAc/
this is basically relative sorting. instead of objective numbers
and that makes it work well for multiple fields
I mean I guess I invented it but it seemed like an obvious leap in logic / usability to me
this way it doesn't favour one field -
what makes it ugly is then I'm doing the same code repeatedly on 5 different fields like some kind of accountant or secretary
also if it's a float I have to change the data type to something that can be ordered more exactly -
@jestdotty You could define a `pub struct TotalF32(pub f32);` and implement the necessary traits (implementing compare/equality with f32::total_cmp), then the business logic would be quite a bit nicer
But I'd need to know the actual use case of the rank sort to understand your use of it. Like, is it so you can (more efficiently?) query a list of structs but sorted based on one field? If that's the case, honestly I'd just clone the vec for each case and sort it based on the relevant field and then store those 5 variants. That way you're only doing the work of sorting once instead of on each query
... not to mention it would be a hell of a lot easier -
@12bitfloat it sorts on multiple fields not on one
and yeah it's not particularly relevant. it's just to order data for me and print it out in that order so I waste less time going through the data manually after -
@jestdotty Yeah but sorting how? What does that mean to sort on multiple fields? You really haven't explained what that actually means and what operation that allows you to do
Lists are fundamentally one-dimensional, at the end of the day you need *one* order of elements
Unless it's just an optimization to "resort" a list on the fly based on a subfield... Which I understand but at that point multiple sorted lists probably make more sense if the data is semi-persistant -
@12bitfloat
let's say you have 2 fields, age and weight
bob is 18 and weighs 180
Alice is 28 and weighs 130
George is 14 and weighs 110
ranked list of ages: 14, 18, 28
ranked list of weights: 110, 130, 180
what's the rank of each person?
bob's age is 18 which is rank 1 in an array, weight 180 which is rank 2 = 1+2 = 3 overall rank
Alice is 28 age ranked 2, 130 weight ranked 1 = 2+1 = 3
George is 14 which is rank 0 age, 110 weight which is 0 rank = 0+0 = 0
so Bob and Alice are tied for both weigh the most and are the oldest
and George wins the contest in weighing the least and being the youngest
you can sort on multiple fields at the same time
(you can also add weights later, like if you want age to matter more than weight for example)
it's kind of like how AIs did house estimates. 20% of the price is due to the house material, 50% is due to its location, etc. you can reverse engineer best outcome mathematically
that's the idea behind it for me, but I'm just sort > print here -
@jestdotty Ahhh, I think I get it now, thanks for explaining :D
I think I have a pretty good idea for an implementation for that.... give me a moment -
@jestdotty Here something: https://play.rust-lang.org//...
I think (im very drunk) that it should do what you want, in quite a lot nicer code. This does depend on itertools but that should be fine -
retoor16202d@12bitfloat you show many people sources, so good from you! You remind me when I was so young, regarding the drunk coding part. For me it doesn't even matter that much. Just used to it back then. As a former heavy drinker: I don't regret it. I enjoyed it. Only thing what sucks a bit is that my time-line is a bit screwed up. Nearly don't know when I have done something, what age. Now dont drinking an it makes me happy but back then drinking made me happy. So yh :) maybe, if you grow up, you can upgrade to amphetamine too :)
-
@jestdotty This should now be a less drunk and more functional version :D
https://play.rust-lang.org//... -
@12bitfloat oh
so I read the first one and was gonna go through it better later by experimenting with it myself but I haven't looked at that code for a while. instead been getting fucked up by health issues lol (I tried new food for new years to spoil myself and that predictably was a bad idea. and timing has it that uhhh... well more stuff happened after that)
second I skimmed and I got it tabbed in my phone's browser as a reminder, would end up going through it more later when I end up feeling like it
tbh I just feel depressed rn. just chemical body stuff
maybe in 2 days. am slow -
@jestdotty No problem :D
Just thought i was getting the cold shoulder even though I put in real programming time doing something for you -
@12bitfloat I meaaaan, hopefully you got some fun out of it or something
cuz for me this part works and it's just a useless nitpicking subquest raaghhh
Related Rants
rust, where a basic bitch sort (not even the algorithm) takes you over 100 lines
it's just on 5 fields
rant
rust
sort