The Crystal Programming Language Forum

Hash of Int64 and || operator?

hello,

i want to remove duplicates from my hdd so i wrote this code

which is a companion for `find ~ -type f -printf “%s %p\n”.

i tried to store the sizes as Int64 instead but now have this message

20 | (seen[size] ||= [] of String ).push(filename)
^-
Error: no overload matches ‘Hash(Int64, Array(String))#[]=’ with types Int32, Array(String)

as i’m very new to crystal, try to work around it. any help (or other feedback about the repo itself) is welcome

I’m guessing you tried to convert it to Int64 like this:

size,filename = l.split(" ",2)
size = size.to_i
( seen[size] ||= [] of String ).push(filename)

Play Link

The error you mentioned is because #to_i convert to Int32. The solution is to use #to_i64:

size,filename = l.split(" ",2)
size = size.to_i64
( seen[size] ||= [] of String ).push(filename)

Play Link

However, I had some trouble figuring out what your question was, so please let me know (and clarify) if it doesn’t help.

@eiro Could you submit the failing code? Otherwise we don’t know what you tried (the code you posted works just fine).

1 Like

hello,

I’m guessing you tried to convert it to Int64 like this:

size,filename = l.split(" ",2)
size = size.to_i
( seen[size] ||= [] of String ).push(filename)

this is exactly what i did!

The error you mentioned is because #to_i convert to Int32. The solution is to use #to_i64

well … the message was somewhat explicit but i assumed that crystal
can infer the expected type because of the declaration of seen.

thanks a lot.

However, I had some trouble figuring out what your question was, so
please let me know (and clarify) if it doesn’t help.

i’m really sorry if i was confusing. your anwser fit the need perfectly.

regards,
marc

Hello Ary,

@eiro Could you submit the failing code? Otherwise we don’t know what
you tried (the code you posted works just fine).

next time, i’ll push a “failing” branch. promise :)

regards
marc