#Can i make my code faster???
100 messages · Page 1 of 1 (latest)
made is_part significantly faster :P
well not quite, how it works with these kind of containers it seperates it on hash, but you can have hash collision so you need a way to compare coords
so you need both for unordered_set
no, not quite
the order in partSet is completly "random"
however it's just used to check if a coord matches any of the parts
though I didn't test it just saying
just ran it
but I think it should be fine
as you don't modify values anywhere, and im mirroring pops and pushes in the set
where is actually this hash used?
ide shows me
Struct 'hash<Coord>' is never used
it's used by the internals of std::unordered_set
it's not called directly
do check if this is actually correct
ok
I did not verify the output
why i didnt heard about std::unordered_set
is it like faster than array but unordered???
no it's quite distinct
unordered_set is essentially a hased value set where everything is unique
there is also a regular set what is sorted
can unordered_set or set be faster than array???
faster in iteration
when i dont need to know order
what will be better
because if its unordered
then it dont need to order it
so it can be faster
well it's most likely gona be slower to itterate
or well to do a full itteration, but the neat thing is with this you don't have a linear itteration
on average isPart is constant time at worst linear
before it was always linear
ok
also what type of container u will recommend for fruits??
look what fruits does
it only temporarily saves data
honestly tthat seems fine
deque??
nah never
imho that list never was an issue
yes but it will be good if i will know for the future
look at the timing here
yes
yes but it will be good if i will know for the future what is faster container type for this
std::vector generally
for just holding elements and iterating once
ok
the difference is constraints, arrays need to be compile time constant
vectors are dynamic sized
what well comes at a cost, but itterating speed should be basically the same
yes but in this case im sure what will be size of fruits
so vector is unnecessary
array can handle that better
there is also std::array
hmm
also i can delete new allocated array in good place
@bitter salmon Has your question been resolved? If so, run !solved :)
Thank you and let us know if you have any more questions!
!unsolved
@stone juniper i have found bug
its not finding coord
actually partsSet
is not adding everything
thats because there is moment when there are 2 same coords
when snake is going into its own tail but is not actually like killing itself
everything works except this
wait i know why... when it happens i cant remove element
because its already not adding to this unordered_set
!solved
Thank you and let us know if you have any more questions!
weird how much conversation happened after literally giving the superset of the solution 