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
-
Demolishun3593035dI 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.
-
12bitfloat988034d@jestdotty That's far from a basic bitch sort though
I still don't really understand what you are achieving with this lol -
12bitfloat988034d@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 -
12bitfloat988034d@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 -
jestdotty625234d@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 -
12bitfloat988034d@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 -
12bitfloat988034d@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 -
retoor332734d@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 :)
-
12bitfloat988034d@jestdotty This should now be a less drunk and more functional version :D
https://play.rust-lang.org//... -
12bitfloat988033d@jestdotty No problem :D
Just thought i was getting the cold shoulder even though I put in real programming time doing something for you
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