#Order arrayList?
1 messages · Page 1 of 1 (latest)
use one of those functions on ArrayList.items
Could you give an example with std.sort.desc() on someArray.items? Thanks so much in advance!
oh yeah thatd just be std.mem.sort(T, someArray.items, {}, std.sort.desc(T)); where T is your element type, {} is just an instance of void because the function returned by std.sort.desc takes void as it's context
This was really helpful! I missed the void type {}.
np, {} actually just happens to evaluate to void because it's an empty block, but you can also do void{}
Just one last questions, I can't slice the result with something like orderdArraylist[0..2]: error: slice of non-array type 'void'. Is there a way to extract specific slices, or do I need to convert the ordered arrayList?
oh :,) i did think it was nice to be explicit sometimes, maybe we should make no one happy and do () 👹
it orders it in place, std.mem.sort doesnt return anything
Is there a variant that has the ordered arrayList as return type?
you can clone() and then order that one
Sorry I'm just starting with Zig. How should I use clone from what I have now: var somrArrayListOrd = std.mem.sort(u32, someArrayList.items, {}, std.sort.desc(u32))
var orderedArray = try someArray.clone();
std.mem.sort(u32, orderedArray.items, {}, std.sort.desc(u32));
that seems like a not so good idea
although thats only if you need an unordered version too
No, I need the only the ordered version. Which is retrieved form the unordered on...
then just std.mem.sort(u32, someArray.items, {}, std.sort.desc(u32)) is all you need
someArray will be sorted after that line
the sorting functions change the underlying data in the list you give it to become sorted
A very big thank you!