taoensso / nippy

The fastest serialization library for Clojure
https://www.taoensso.com/nippy
Eclipse Public License 1.0
1.04k stars 60 forks source link

sorted-maps are converted into hash-maps #4

Closed bakyeono closed 11 years ago

bakyeono commented 11 years ago

Hi~ This lib is very useful but I found a little problem with sorted-map. After the round-trip, sorted-maps are converted into hash-maps. This can be problem to someone depends on sorted-map data structures.

bakyeono commented 11 years ago

;;;; test about this issue (def before-round (sorted-map 0 "value" 1 "value")) (def after-round (taoensso.nippy/thaw-from-bytes (taoensso.nippy/freeze-to-bytes before-round)))

(class before-round) ; ===> clojure.lang.PersistentTreeMap

(class after-round) ; ===> clojure.lang.PersistentArrayMap

(subseq before-round = 0) ; ===> ([0 "value"])

(subseq after-round = 0) ; ClassCastException clojure.lang.PersistentArrayMap cannot be cast to clojure.lang.Sorted

bakyeono commented 11 years ago

;;;; an improvised solution for users ; use this function to regain sorted-map (defn hash-map->sorted-map [coll] (into (sorted-map) (sort coll)))

; test (class (hash-map->sorted-map after-round)) ; ===> clojure.lang.PersistentTreeMap

ptaoussanis commented 11 years ago

Hi bakyeono,

Sorry for the delay replying - was travelling the past few weeks. Working through a backlog now, will try get back to you in a couple days!

ptaoussanis commented 11 years ago

Just pushed 1.2.0 which adds support for sorted maps and sets. Hope that helps! Cheers :-)

bakyeono commented 11 years ago

Thanks a lot! You're a great man!