<ed_t>
anyone know of examples of using std.sort to sort structures. I assume I will have to pass a compare function...
<dvaun>
i see a `binarySearch`, `insertionSort` and others in the sort file
<andrewrk>
ed_t, check the tests in sort.zig for example usage
<ed_t>
I am not understanding how the example comptime funtions are working. Anyone have an example for a user defined stucture?
<ed_t>
in std.sort
<justin_smith>
ed_t: in test "binarySearch" look at S, it has functions for u32 and i32 but a function on a custom struct would have the same outline
<justin_smith>
you usually don't need context, and the next two args it receives will be instances of your type
<ed_t>
that almost makes sense except its returning math.Order. Does not sort require a lessthan function and a boolean?
<justin_smith>
ed_t: no, the functions there are literally what it provides to sort
<ed_t>
then I am still very confused (40+ of programming in I do not know how many languages, it gets very very frustrating when something you know is simple does not make sense)...
<justin_smith>
ed_t: oh, wait, I think I see what you mean - what I pointed out was what binarySearch uses, which is a different sig
<justin_smith>
ed_t: I wrongly assumed the other sort functions would use the same type, they don't
<ed_t>
so S for sort would contain one function for lessthan returning a boolean?
ifreund has quit [Ping timeout: 240 seconds]
<justin_smith>
ed_t: std.sort.sort you want a function of this sig: fn (context: @TypeOf(context), lhs: T, rhs: T) bool
<justin_smith>
where T matches the type in your collection, and context can be void as in that other example (and usually is)
<ed_t>
there are two pub fn asc and desc, some how I need to use them to build my compare - I think
<justin_smith>
ed_t: asc and desc are conveniences for arbitrary numeric types
<justin_smith>
all you need is to take a void arg, two of your type, and return a bool
<ed_t>
let me see if I can get that to work. I am making progress in learning this language
<justin_smith>
ed_t: it's unusual (knowing ml before learning zig helped for me), but the rules are actually smaller and simpler than what I'm more familiar with
<justin_smith>
sorry for the sidetrack with binarySearch, I should know better than to have assumed it would use the same type of comparator sort does
<ed_t>
my set of languages are a bit dated but the ideas are similar
<ed_t>
justin_smith no need to be sorry. Help IS appreciated. Very much so.
<justin_smith>
ed_t: a working sort comparator from before I knew about the built in ones: "pub fn less_than(_: void, a: isize, b: isize) bool { return(a < b); }"
<ed_t>
error: expected function, found 'type'
<ed_t>
sort(point, alive.items, {}, point_lt);
<ed_t>
probably something stupid
<ed_t>
point is:
<ed_t>
const point = struct {
<ed_t>
x: u32,
<ed_t>
};
<ed_t>
y: u32
<justin_smith>
ed_t: is point_lt a struct containing a function or a function? that's the only function arg it expects right?
<ed_t>
I am teaching myself zig so I suspect there is alot that can be improved, aside from the sort it works.
<dutchie>
it seems to work for me. i wonder if it's a little weird because that point_lt function isn't a total order in the mathematical sense: you can have two points p1 and p2 such that neither p1 < p2 nor p2 < p1
<ifreund>
ed_t: I think the problem is with your point_lt function. (10,12) < (11,10) and (11,10) < (10,12) are both true depending on what order the args ar passed
<dutchie>
yeah, also that
<ifreund>
You'd probably get better results with (a.x + a.y) < (b.x + b.y)
<v_m_v>
Hello. Does anyone have some exp. with zig and zeroMQ C binding?
v0idify has quit [Remote host closed the connection]
v0idify has joined #zig
jokoon has quit [Quit: Leaving]
earnestly has quit [Ping timeout: 256 seconds]
evbo has quit [Remote host closed the connection]
evbo has joined #zig
v0idify has quit [Remote host closed the connection]
v0idify has joined #zig
nycex- has joined #zig
nycex has quit [Ping timeout: 268 seconds]
donniewest has joined #zig
waleee-cl has joined #zig
craigo has joined #zig
sawzall has quit [Read error: Connection reset by peer]
sawzall has joined #zig
<ed_t>
is there a simple way to have a program pause for a second or two?
<dutchie>
`std.time.sleep(nanoseconds: u64) void`
mtiljeset[m] has quit [Quit: Idle for 30+ days]
hnOsmium0001 has joined #zig
earnestly has joined #zig
Akuli has joined #zig
tnorth has quit [Ping timeout: 260 seconds]
gonz_ has quit [Ping timeout: 240 seconds]
tcsc has quit [Ping timeout: 244 seconds]
lqd has quit [Read error: Connection reset by peer]
euantorano has quit [Ping timeout: 260 seconds]
procnto has quit [Ping timeout: 265 seconds]
dputtick has quit [Ping timeout: 272 seconds]
shurane has quit [Ping timeout: 240 seconds]
nikita` has quit [Read error: Connection reset by peer]
nikki93 has quit [Read error: Connection reset by peer]
sjd has quit [Read error: Connection reset by peer]
jzelinskie has quit [Read error: Connection reset by peer]
rtpg has quit [Read error: Connection reset by peer]
guan has quit [Read error: Connection reset by peer]
bitmapper has quit [Read error: Connection reset by peer]
yrashk has quit [Read error: Connection reset by peer]
kushalp has quit [Read error: Connection reset by peer]
dch has quit [Read error: Connection reset by peer]
betawaffle has quit [Write error: Connection reset by peer]
travv0 has quit [Write error: Connection reset by peer]
tracernz has quit [Write error: Connection reset by peer]
r0bby has quit [Read error: Connection reset by peer]
waleee-cl has quit [Read error: Connection reset by peer]
kwilczynski has quit [Read error: Connection reset by peer]
jjido has quit [Read error: Connection reset by peer]
ovf has quit [Ping timeout: 258 seconds]
eddyb[legacy] has quit [Ping timeout: 258 seconds]
dputtick has joined #zig
yrashk has joined #zig
tracernz has joined #zig
hnOsmium0001 has quit [Ping timeout: 265 seconds]
euantorano has joined #zig
nikki93 has joined #zig
dch has joined #zig
bitmapper has joined #zig
jjido has joined #zig
midgard has quit [Ping timeout: 246 seconds]
ovf has joined #zig
lqd has joined #zig
procnto has joined #zig
r0bby has joined #zig
jzelinskie has joined #zig
kwilczynski has joined #zig
tcsc has joined #zig
betawaffle has joined #zig
travv0 has joined #zig
nikita` has joined #zig
euantorano has quit [Ping timeout: 264 seconds]
waleee-cl has joined #zig
midgard has joined #zig
gonz_ has joined #zig
rtpg has joined #zig
hnOsmium0001 has joined #zig
hnOsmium0001 has quit [Ping timeout: 272 seconds]
rtpg has quit [Ping timeout: 264 seconds]
guan has joined #zig
eddyb[legacy] has joined #zig
kushalp has joined #zig
hnOsmium0001 has joined #zig
euantorano has joined #zig
rtpg has joined #zig
shurane has joined #zig
decentpenguin has joined #zig
gonz_ has quit [Read error: Connection reset by peer]
hnOsmium0001 has quit [Ping timeout: 260 seconds]
rtpg has quit [Read error: Connection reset by peer]
shurane has quit [Read error: Connection reset by peer]
euantorano has quit [Read error: Connection reset by peer]
gonz_ has joined #zig
rtpg has joined #zig
shurane has joined #zig
euantorano has joined #zig
hnOsmium0001 has joined #zig
kushalp has quit [Read error: Connection reset by peer]
tracernz has quit [Write error: Connection reset by peer]
kwilczynski has quit [Write error: Connection reset by peer]
r0bby has quit [Write error: Connection reset by peer]
tracernz has joined #zig
r0bby has joined #zig
craigo has quit [Ping timeout: 265 seconds]
kushalp has joined #zig
kwilczynski has joined #zig
kwilczynski has quit [Ping timeout: 272 seconds]
kushalp has quit [Ping timeout: 264 seconds]
v_m_v has quit [Remote host closed the connection]
kwilczynski has joined #zig
LanceThePants has joined #zig
sawzall has quit [Read error: Connection reset by peer]
kushalp has joined #zig
jzelinskie has quit [Read error: Connection reset by peer]
ovf has quit [Ping timeout: 256 seconds]
eddyb[legacy] has quit [Read error: Connection reset by peer]
hnOsmium0001 has quit [Write error: Connection reset by peer]
eddyb[legacy] has joined #zig
jzelinskie has joined #zig
hnOsmium0001 has joined #zig
ovf has joined #zig
jzelinskie has quit [Ping timeout: 260 seconds]
kushalp has quit [Ping timeout: 260 seconds]
eddyb[legacy] has quit [Read error: Connection reset by peer]
ovf has quit [Ping timeout: 260 seconds]
hnOsmium0001 has quit [Ping timeout: 272 seconds]
bitmapper has quit [Ping timeout: 260 seconds]
nikita` has quit [Read error: Connection reset by peer]
tcsc has quit [Read error: Connection reset by peer]
<andrewrk>
ifreund, there is one upside to the separate allocations: it lets you do the equivalent of toOwnedSlice() and have the allocator shop off the extra bytes
gonz_ has quit [Read error: Connection reset by peer]
<andrewrk>
I'll test both and report back
nikita` has joined #zig
jzelinskie has joined #zig
eddyb[legacy] has joined #zig
kushalp has joined #zig
gonz_ has joined #zig
hnOsmium0001 has joined #zig
tcsc has joined #zig
bitmapper has joined #zig
ovf has joined #zig
<ifreund>
andrewrk: note that in my current implementation the allocations aren't aligned properly, gotta fix that if we go with the separate allocations
<andrewrk>
oh yeah I noticed that. I think the sorting in mine solves that but it doesn't (yet?) solve the rare case of a field with larger alignment than size
nikita` has quit [Read error: Connection reset by peer]
kushalp has quit [Read error: Connection reset by peer]
<ifreund>
with how things are currently structured and because the allocator interface requires alignment to be comptime-known, handling it properly with multiple allocations might get a little ugly
<andrewrk>
if you had such a situation you probably don't want this data structure anyway
gonz_ has quit [Read error: Connection reset by peer]
bitmapper has quit [Read error: Connection reset by peer]
tcsc has quit [Read error: Connection reset by peer]
jzelinskie has quit [Read error: Connection reset by peer]
<andrewrk>
there is always the nuclear option of calling the Allocator function pointers directly which allows for runtime known alignment
<andrewrk>
I think that's probably not the best way to go tho
<ifreund>
yeah that seems like a hack
<ifreund>
we could also align all the allocations to the max alignment of the fields
hnOsmium0001 has quit [Ping timeout: 272 seconds]
eddyb[legacy] has quit [Ping timeout: 272 seconds]
<ifreund>
trade code bloat for heap bloat
ovf has quit [Ping timeout: 260 seconds]
nikita` has joined #zig
<ifreund>
anyhow, I've got to go finish a paper that's due in 4 hours
kushalp has joined #zig
<ifreund>
(it's been kinda fun though, I learned how the signal messaging protocol works)
<andrewrk>
godspeed!
bitmapper has joined #zig
eddyb[legacy] has joined #zig
jzelinskie has joined #zig
hnOsmium0001 has joined #zig
gonz_ has joined #zig
tcsc has joined #zig
ovf has joined #zig
fritchie has joined #zig
notzmv has joined #zig
tcsc has quit [Read error: Connection reset by peer]
bitmapper has quit [Read error: Connection reset by peer]
hnOsmium0001 has quit [Read error: Connection reset by peer]
gonz_ has quit [Read error: Connection reset by peer]
eddyb[legacy] has quit [Read error: Connection reset by peer]
ovf has quit [Read error: Connection reset by peer]
jzelinskie has quit [Read error: Connection reset by peer]
protheory8-new-m has quit [Ping timeout: 260 seconds]
notzmv has quit [Remote host closed the connection]
ugla has quit [Ping timeout: 260 seconds]
protheory8-new-m has joined #zig
jukan_ has joined #zig
ugla has joined #zig
eddyb[legacy] has joined #zig
jukan has quit [Ping timeout: 260 seconds]
bitmapper has joined #zig
hnOsmium0001 has joined #zig
tcsc has joined #zig
jzelinskie has joined #zig
ovf has joined #zig
notzmv has joined #zig
gonz_ has joined #zig
waffle_ethics has joined #zig
M-ou-se has quit [Quit: WeeChat 2.7.1]
midgard has quit [Ping timeout: 260 seconds]
M-ou-se has joined #zig
cole-h has joined #zig
Xavi92 has joined #zig
gonz_ has quit [Read error: Connection reset by peer]
kwilczynski has quit []
gonz_ has joined #zig
ur5us has joined #zig
frett27 has joined #zig
kwilczynski has joined #zig
fritchie has quit [Remote host closed the connection]
fritchie has joined #zig
sord937 has quit [Quit: sord937]
frett27 has quit [Ping timeout: 272 seconds]
decentpenguin has quit [Ping timeout: 246 seconds]
Biolunar has quit [Quit: leaving]
<ikskuh>
reasons why zig is awesome: @bitCast([4][4]f32, array_len_16)
gazler_ has quit [Ping timeout: 264 seconds]
bitmapper has quit [Quit: Connection closed for inactivity]
gazler has joined #zig
midgard has joined #zig
jzelinskie has quit [Read error: Connection reset by peer]
jzelinskie has joined #zig
bitmapper has joined #zig
sebonirc has joined #zig
ur5us has quit [Ping timeout: 264 seconds]
Akuli has quit [Quit: Leaving]
waffle_ethics has quit [Ping timeout: 256 seconds]
<johnLate>
What does Auto in AutoHashMap mean exacly?
<ikskuh>
it means that the hashing and equal function for the key type is automatically chosen
ugla has quit [Ping timeout: 246 seconds]
pafmaf[m] has quit [Ping timeout: 240 seconds]
BaroqueLarouche has quit [Ping timeout: 240 seconds]
protheory8-new-m has quit [Ping timeout: 260 seconds]
Snektron has quit [Ping timeout: 240 seconds]
<andrewrk>
AutoHashMap is really comfy
kameliya[m] has quit [Ping timeout: 240 seconds]
dtz has quit [Ping timeout: 265 seconds]
Nypsie[m] has quit [Ping timeout: 265 seconds]
siraben has quit [Ping timeout: 268 seconds]
signop has quit [Quit: Quit.]
signop has joined #zig
cmcaine has joined #zig
rtpg has quit [Ping timeout: 246 seconds]
rtpg has joined #zig
<johnLate>
(looking at hash_map.zig) Is there any other reason for the "return struct { fn foo(...){...} }.foo;" pattern than not wanting to change the grammar and not wanting to define that function outside the containing one?
<ifreund>
johnLate: that pattern only exists because #1717 hasn't been implemented yet
<johnLate>
thx
mokafolio has quit [Quit: Bye Bye!]
mokafolio has joined #zig
waffle_ethics has joined #zig
waffle_ethics has quit [Ping timeout: 246 seconds]
hspak has quit [Ping timeout: 264 seconds]
a_chou has joined #zig
rinfo has quit [*.net *.split]
oats has quit [*.net *.split]
bgiannan has quit [*.net *.split]
drvirgilio has quit [*.net *.split]
bgiannan has joined #zig
drvirgilio has joined #zig
oats has joined #zig
rinfo has joined #zig
Biolunar has joined #zig
jmiven has quit [Quit: reboot]
jmiven has joined #zig
waffle_ethics has joined #zig
a_chou has quit [Ping timeout: 246 seconds]
donniewest has quit [Quit: WeeChat 3.0]
waffle_ethics has quit [Ping timeout: 240 seconds]
ugla has joined #zig
Piraty has quit [Quit: ---]
Piraty has joined #zig
ky0ko1 has joined #zig
jaens[m] has joined #zig
ugla has quit [Quit: Bridge terminating on SIGTERM]
jaens[m] has quit [Client Quit]
Nypsie[m] has joined #zig
Nypsie[m] has quit [Remote host closed the connection]
ky0ko1 has quit [Quit: Bridge terminating on SIGTERM]