[ANN] immutable-int-map

238 views
Skip to first unread message

Zach Tellman

unread,
Apr 21, 2014, 12:40:45 AM4/21/14
to clo...@googlegroups.com
This one's pretty simple: it's an immutable map that can only have positive integers as keys.  It can be found at https://github.com/ztellman/immutable-int-map.

The one interesting aspect of this is that it has an efficient merge mechanism, which means it plays better with Clojure's reducer framework than Clojure's own data structures.  This was a non-obvious consequence to me before I started working on it, so I figure others might also find it interesting.

Plínio Balduino

unread,
Apr 21, 2014, 12:44:21 AM4/21/14
to Clojure Official
"it's an immutable map that can only have positive integers as keys" -- Like an array?

(My question is child of my complete ignorance, and I'm not questioning your knowledge or motivation)

Plínio


On Mon, Apr 21, 2014 at 1:40 AM, Zach Tellman <ztel...@gmail.com> wrote:
This one's pretty simple: it's an immutable map that can only have positive integers as keys.  It can be found at https://github.com/ztellman/immutable-int-map.

The one interesting aspect of this is that it has an efficient merge mechanism, which means it plays better with Clojure's reducer framework than Clojure's own data structures.  This was a non-obvious consequence to me before I started working on it, so I figure others might also find it interesting.

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Zach Tellman

unread,
Apr 21, 2014, 12:52:23 AM4/21/14
to clo...@googlegroups.com
I could represent the map {0 :foo, 1000000 :bar} as an array, but it would have to be a million element array with a lot of empty space. This would be (maybe) faster w.r.t. lookups, but would be vastly slower for enumerating entries, merging other maps, and adding keys that are larger than the boundaries of the underlying array.  This data structure, which is described by the paper linked in the readme,  I also mention the possibility of using this to represent a sparse vector (as opposed to the array, which is dense) in the readme.

Hope that answers your question,
Zach

Alex Miller

unread,
Apr 21, 2014, 8:12:05 AM4/21/14
to clo...@googlegroups.com
This is great stuff. Why not longs? Are you going for space savings?

Alex Miller

unread,
Apr 21, 2014, 8:26:10 AM4/21/14
to clo...@googlegroups.com
Never mind, look like you mean integer in the generic sense and you are using longs, right?

Zach Tellman

unread,
Apr 21, 2014, 11:55:37 AM4/21/14
to clo...@googlegroups.com

Correct. I'll clarify that I mean 64 bit integers in the readme.

On Apr 21, 2014 5:26 AM, "Alex Miller" <al...@puredanger.com> wrote:
Never mind, look like you mean integer in the generic sense and you are using longs, right?

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to a topic in the Google Groups "Clojure" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/clojure/0EysWMml6Ks/unsubscribe.
To unsubscribe from this group and all its topics, send an email to clojure+u...@googlegroups.com.

Plínio Balduino

unread,
Apr 21, 2014, 8:04:17 PM4/21/14
to Clojure Official
Got it. Awesome.

Good job, Zach

tcrayford

unread,
Apr 22, 2014, 5:14:58 AM4/22/14
to clo...@googlegroups.com
Bonus: rename the library "immutable-long-map", then you can have a section in the readme titled "why the long map?"

Alex Miller

unread,
Apr 22, 2014, 11:27:18 AM4/22/14
to clo...@googlegroups.com
<groan>
Reply all
Reply to author
Forward
0 new messages