<< Back to previous view

[CLJ-694] Set func create sorted hash-set Created: 18/Dec/10  Updated: 27/Dec/10  Resolved: 27/Dec/10

Status: Closed
Project: Clojure
Component/s: None
Affects Version/s: Release 1.2
Fix Version/s: None

Type: Defect Priority: Minor
Reporter: Sergey Krauchenia Assignee: Unassigned
Resolution: Declined Votes: 0
Labels: None
Environment:

Ubuntu 10.04



 Description   
(def _sortedset (set (list 1,3,2)))
(println _sortedset)
(println (class _sortedset))

This code output is:

>> #{1 2 3}
>> clojure.lang.PersistentHashSet

As you can see set function create hash-set, but already sorted.



 Comments   
Comment by Fogus [ 27/Dec/10 8:15 AM ]

The hash set that you're creating only seems sorted. That is, while the ordering of a set is not guaranteed, it's a perfectly valid set if it is. The ordering in this case is due to implementation details guided by the fact that you happen to be inserting values of the same type whose hash values are ordered. If you make a change to one of the values then you could see a change:

(set (list 1 3.0 2))
;=> #{3.0 1 2)

Comment by Sergey Krauchenia [ 27/Dec/10 12:51 PM ]

Thanks Michel for explanation.

Generated at Sat Aug 30 01:22:17 CDT 2014 using JIRA 4.4#649-r158309.