#how should i pass a function to std.sort.insertion()

1 messages · Page 1 of 1 (latest)

solemn shard
#

i wanna sort an struct via std.sort.insertion() but idk how i pass functions into that function.

also what should context be?

#

do i need to add an type variable to my function?

#
    rank.items = std.sort.insertion(NameRanking, rank.items, NameRanking, NameRanking.lessThen);```
#

or whats the best way to sort an arraylist with structs with an lessThen function

lime epoch
solemn shard
#

should context be the items too?

solemn shard
#
└─ install rhp
   └─ zig build-exe rhp Debug native 1 errors
/usr/lib/zig/lib/std/sort.zig:75:41: error: unable to resolve comptime value
    heapContext(0, items.len, Context{ .items = items, .sub_ctx = context });
                                       ~^~~~~~~~~~~~~
/usr/lib/zig/lib/std/sort.zig:75:41: note: initializer of comptime only struct must be comptime-known
referenced by:
    init: src/plugin.zig:63:18
    handle: src/cli.zig:46:28
    4 reference(s) hidden; use '-freference-trace=6' to see all references
error: the following command failed with 1 compilation errors:
/usr/lib/zig/zig build-exe -ODebug -Mroot=/home/kybe/Documents/code/zih/rhp/src/main.zig --cache-dir /home/kybe/Documents/code/zih/rhp/.zig-cache --global-cache-dir /home/kybe/.cache/zig --name rhp --zig-lib-dir /usr/lib/zig/lib/ --listen=-
Build Summary: 0/3 steps succeeded; 1 failed
install transitive failure
└─ install rhp transitive failure
   └─ zig build-exe rhp Debug native 1 errors
error: the following build command failed with exit code 1:
/home/kybe/Documents/code/zih/rhp/.zig-cache/o/02510ac226275256e32ff0b5cfe7a42b/build /usr/lib/zig/zig /usr/lib/zig/lib /home/kybe/Documents/code/zih/rhp /home/kybe/Documents/code/zih/rhp/.zig-cache /home/kybe/.cache/zig --seed 0x9f778981 -Z8eac856db3124c1b --summary all``` does it need to be compile time known or am i just stupid
lime epoch
#

How does NameRanking.lessThen compare NameRanking instances?