<FromGitter>
<noahlh> can someone explain why the first has output and the second does not?
<FromGitter>
<straight-shoota> @noahlh `#to_s` returns the internal buffer as string
<FromGitter>
<straight-shoota> `#gets` reads a line. But since the stream pointer is at the end of the buffer, there is nothing to read (hence returns `nil`)
<FromGitter>
<straight-shoota> If you want to read the previously printed string, you need to `#rewind` the io
mjanssen has quit [Remote host closed the connection]
Raimondi has quit [Remote host closed the connection]
Raimondi has joined #crystal-lang
<yxhuvud>
proyb: It depends on hashes, and hashes are kinda slow. You might gain a little by changing the initial size allocated to the hash, but I don't think that will make up for the difference.
<FromGitter>
<proyb6> @yxhuvud I do see it use 400MB of memory which is too high on Crystal while Go allocates 160MB
<FromGitter>
<j8r> A Set is indexed? You could use it
<FromGitter>
<j8r> (I don't know the problem)
<FromGitter>
<asterite> hashes could be more efficient in crystal but by the default they preserve insertion order and they use the old algorithm Ruby used... also maybe it would be nice to have a faster hash that doesn't care about insertion order
<jokke>
def
<FromGitter>
<proyb6> HashUnordered? :)
<jokke>
relying on insertion order isn't a good idea imho
<FromGitter>
<asterite> unless it's guaranteed
<jokke>
yeah sure..
<jokke>
but idk if it should be guaranteed
<FromGitter>
<mpcjanssen> python switched to making it guaranteed because so many were depending on it
<FromGitter>
<asterite> Right, in Ruby it's guaranteed too. In Crystal too. I found it to be sometimes useful (and it's intuitive)
<FromGitter>
<j8r> Having both sound like a good option
<FromGitter>
<j8r> Hash, and HashOrdered something like that
DTZUZO has quit [Ping timeout: 246 seconds]
<FromGitter>
<asterite> In that case it would be UnorderedHash :-)
Linuxer4Fun1 has joined #crystal-lang
Linuxer4Fun has quit [Read error: Connection reset by peer]
Linuxer4Fun1 is now known as Linuxer4Fun
<FromGitter>
<j8r> or there are plenty of names: Dict, HashMap, Map, KeyedList, AssociativeArray
<FromGitter>
<j8r> instantiate only in the same namespace, but be able to call getters externally
<z64>
i think private types would be the only solution
<z64>
but may not play well with other things
akaiiro has quit [Ping timeout: 240 seconds]
DTZUZO has joined #crystal-lang
<yxhuvud>
asterite: one question though is how much of the overhead is due to the orderedness, rather than just the overhead of all pointer chasing in the current implemenation.
<yxhuvud>
jokke: it must be either guaranteed to be ordered or guaranteed not to be (like in go).
<yxhuvud>
otherwise people will depend on de facto behaviour and force orderedness.
<oprypin>
> [15:47:27] <f44336@mpcjanssen> python switched to making it guaranteed because so many were depending on it
<oprypin>
that is incorrect
<oprypin>
Python has the fastest, most compact AND ordered implementation
<oprypin>
so if that one is copied directly, there will be no downsides
<oprypin>
that is the only reason why the ordered implementation was able to replace the unordered one in Python - because it has no downsides
<yxhuvud>
oprypin: I can beleive that the new python implementation was faster than the older impl, but when it comes to performance vs other hash or dict implementations, [citation needed].
akaiiro has joined #crystal-lang
Renich has quit [Ping timeout: 250 seconds]
DTZUZO has quit [Ping timeout: 244 seconds]
Renich has joined #crystal-lang
<FromGitter>
<j8r> The Python stdlib has rough edges
<FromGitter>
<girng> i love `Hash(Type, Type).new`, that's all i need in life
<FromGitter>
<j8r> @girng don't forget to use structs whenever possible 😏
<oprypin>
j8r, i don't think that this is good advice to give so generally
<FromGitter>
<girng> @j8r yeah i do need to use structs more.. i was just kinda saying i really like how easy the hash is setup in crystal. i mean `hash.delete key` and BOOM it's gone. and `clear`, `each`, etc make it so easy to work with
<FromGitter>
<j8r> Struct are for known mapping, when keys are know in advance
<FromGitter>
<j8r> This avoids runtime errors
<FromGitter>
<j8r> Yeah Hash is very practical
<FromGitter>
<j8r> Nearly every language have associative arrays (sparse or not)
return0e_ has quit [Read error: Connection reset by peer]
return0e has joined #crystal-lang
non-aristotelian has joined #crystal-lang
Raimondi has joined #crystal-lang
DTZUZO has joined #crystal-lang
Raimondi has quit [Ping timeout: 240 seconds]
DTZUZO has quit [Ping timeout: 250 seconds]
<FromGitter>
<asterite> Yxhuvud: good question. I don't know. I think changing Hash to use an open-addressing algorithm would improve performance, and I think one of the tentative PRs also kept the order, so yeah, maybe the ordering doesn't matter much
druonysus has quit [Ping timeout: 244 seconds]
<yxhuvud>
Yeah. my impression of reading that pr is that he ran into GC issues. boehm doesn't like big allocations, and also mistook some stored hashes as pointers.
<FromGitter>
<asterite> Yxhuvud: wow, you finally solved AoC 20 part 2. I spent hours trying to implement it, I think I have an idea but probably have bugs in it... I'm still not sure of a good algorithm for it, but these days I won't have time for AoC :-(
virkony has quit [Remote host closed the connection]
<yxhuvud>
part2 was easy. I tried to be too general on part1 which was a big problem as it didn't terminate
<FromGitter>
<asterite> right, the same thing happened to me
<FromGitter>
<asterite> I might eventually spoil myself and look at your solution :-P
Raimondi has joined #crystal-lang
druonysus has joined #crystal-lang
<oprypin>
asterite, Yxhuvud, why are you talking as if there isn't already a widely used open-addressing hashtable implementation that keeps ordering?