News for hackers. Stuff that matters.
Re:Data Structures in Clojure: Hash Tables by Jach on Tuesday February 04, 2014 @07:42PM (#7181241)
I love these posts. Even though I'd never use this in production, it's an excellent intro to the same basic data structure taught everywhere. But instead of mucking with a templated C++ implementation (or getting lost in the "plain cons cells for everything!" weeds)... Clojure! It also shows that as much as idiomatic Clojure frowns on OOP and mutability... it's not really that unpleasant to read. I almost want to go through all my old C++ assignments and redo them in Clojure like this.
Re:Data Structures in Clojure: Hash Tables by gleenn on Wednesday February 05, 2014 @07:54PM (#7187983)
Totally agree. Most Clojure code I read is far from easy to jump into for an amateur like myself. It is awesome to see some well-explained and simple code that you can learn from like this.
Re:Data Structures in Clojure: Hash Tables by vinkelhake on Tuesday February 04, 2014 @12:30PM (#7178877)
> On the machine this was implemented, insertion speed increased ~110x, compared with the non-hinted implementation.

That makes it sound like type hints are essentially mandatory for anything where performance matters.

Nice article! It would have been interesting to see how it fares against something like java.util.HashMap.

Re:Data Structures in Clojure: Hash Tables by chc on Tuesday February 04, 2014 @01:26PM (#7179281)
As the article suggests, rather than consider type hints mandatory, it's better just to check whether you need them with warn-on-reflection.
Re:Data Structures in Clojure: Hash Tables by zephjc on Tuesday February 04, 2014 @12:48PM (#7179027)
Yeah, the less runtime reflection you make it use, the better the speed gains (I'm glad type hints are optional though).
Re:Data Structures in Clojure: Hash Tables by DigitalJack on Tuesday February 04, 2014 @01:01PM (#7179119)
I only start type hinting if performance has proven to be a problem.
Re:Data Structures in Clojure: Hash Tables by cbp on Tuesday February 04, 2014 @01:26PM (#7179282)
If performance matters _and_ you're doing interop with java.
Re:Data Structures in Clojure: Hash Tables by copx on Tuesday February 04, 2014 @01:24PM (#7179267)
Where is the definition of the actual hash function? That is the interesting and tricky part of a hash table. Is "hash" a Clojure built-in?
Re:Data Structures in Clojure: Hash Tables by shriphani on Tuesday February 04, 2014 @01:38PM (#7179377)
Clojure has a built-in hash which (I believe) returns the value of <your_obj>.hashCode() [the one java provides].
Re:Data Structures in Clojure: Hash Tables by dantiberian on Tuesday February 04, 2014 @03:44PM (#7180121)
You are correct, (hash x) returns x.hashCode() from Java http://clojuredocs.org/clojure_core/clojure.core/hash
Re:Data Structures in Clojure: Hash Tables by the_french on Tuesday February 04, 2014 @01:02PM (#7179123)
Very nitpicky but I find the ligatures on all the "t" characters very distracting.

Additionally, I don't know Closure, but are there any default hash-table implementations? If so, how does this implementation compare against the base one?

Re:Data Structures in Clojure: Hash Tables by brandonbloom on Tuesday February 04, 2014 @01:46PM (#7179431)
It's Clojure with a "j".

Clojure provides Persistent Hash Tries (look them up) as well as several other immutable map implementations. Mutable maps are provided by the Java base class libraries.