Skip to content

Commit

Permalink
Linked set prints iteself as a vector
Browse files Browse the repository at this point in the history
So the order is not lost. Uniqueness can always be added later.
  • Loading branch information
frankiesardo committed Nov 6, 2014
1 parent f9c96d5 commit 40c573d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject frankiesardo/linked "1.0.5"
(defproject frankiesardo/linked "1.0.6"
:description "Efficient ordered map and set"
:url "http://github.com/frankiesardo/linked"
:license {:name "Eclipse Public License"
Expand Down
8 changes: 4 additions & 4 deletions src/linked/set.cljx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@

Object
(toString [this]
(str "#{" (string/join " " (map str this)) "}"))
(str "[" (string/join " " (map str this)) "]"))
(hashCode [this]
(reduce + (map hash (.seq this))))
(equals [this other]
Expand All @@ -89,14 +89,14 @@
#+clj
(defmethod print-method LinkedSet [o ^java.io.Writer w]
(.write w "#linked/set ")
(print-method (seq o) w))
(print-method (into [] (seq o)) w))


#+cljs
(deftype LinkedSet [linked-map]
Object
(toString [this]
(str "#{" (string/join " " (map str this)) "}"))
(str "[" (string/join " " (map str this)) "]"))
(equiv [this other]
(-equiv this other))

Expand Down Expand Up @@ -160,7 +160,7 @@

IPrintWithWriter
(-pr-writer [coll writer opts]
(-write writer (str "#linked/set " (if-let [s (seq coll)] s '())))))
(-write writer (str "#linked/set " (into [] (seq coll))))))

#+cljs (reader/register-tag-parser! "linked/set" linked-set)

Expand Down
4 changes: 2 additions & 2 deletions test/linked/set_test.cljx
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@

(deftest object-features
(let [s (linked-set 'a 1 :b 2)]
(is (= "#{a 1 :b 2}" (str s)))))
(is (= "[a 1 :b 2]" (str s)))))

(deftest print-and-read-ordered
(let [s (linked-set 1 2 9 8 7 5)]
(is (= "#linked/set (1 2 9 8 7 5)"
(is (= "#linked/set [1 2 9 8 7 5]"
(pr-str s)))
(let [o (read-string (pr-str s))]
#+clj (is (= linked.set.LinkedSet (type o)))
Expand Down

0 comments on commit 40c573d

Please sign in to comment.