{"id":228,"date":"2009-10-19T11:38:54","date_gmt":"2009-10-19T09:38:54","guid":{"rendered":"http:\/\/dev.flauschig.ch\/wordpress\/?p=228"},"modified":"2009-10-19T16:04:17","modified_gmt":"2009-10-19T14:04:17","slug":"why-you-shouldnt-use-sortedlist","status":"publish","type":"post","link":"http:\/\/dev.flauschig.ch\/wordpress\/?p=228","title":{"rendered":"Why you shouldn&#8217;t use SortedList"},"content":{"rendered":"<p>Today I ran into this problem for the second (and hopefully last) time. Let&#8217;s take a look at the words &#8220;sorted&#8221; and &#8220;list&#8221;. &#8220;sorted&#8221; suggests that the items of the list will somehow be sorted. So far, so good. &#8220;list&#8221; would suggest that you can put any item in the list. Specifically, it isn&#8217;t called &#8220;SortedSet&#8221;, so you could expect that you in fact can add the same item twice with the same key.<\/p>\n<p>Well&#8230; that&#8217;s where you&#8217;d be wrong. The documentation says that the sorted list throws an ArgumentException if &#8220;An element with the same key already exists in the SortedList&#8221;. Unfortunately I don&#8217;t go around looking through the documentation to search for stuff like that. And in fact: you shouldn&#8217;t have to. A list is a list and not a set. And if you decide to implement a sorted list with a dictionary as the backing store, then you are &#8211; quite frankly &#8211; an idiot.<\/p>\n<p>If you would like to save yourself a lot of grief, just don&#8217;t use the sorted list. Use a regular List<T> and the Sort method. But be aware, that the Sort method uses the quicksort algorithm which is unstable (elements that are &#8220;equal&#8221; don&#8217;t keep their relative positions to one another).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today I ran into this problem for the second (and hopefully last) time. Let&#8217;s take a look at the words &#8220;sorted&#8221; and &#8220;list&#8221;. &#8220;sorted&#8221; suggests that the items of the list will somehow be sorted. So far, so good. &#8220;list&#8221; would suggest that you can put any item in the list. Specifically, it isn&#8217;t called &hellip; <\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[4],"tags":[],"class_list":{"0":"entry","1":"post","2":"publish","3":"author-executor","4":"post-228","6":"format-standard","7":"category-csharp"},"acf":[],"views":1610,"_links":{"self":[{"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/228"}],"collection":[{"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=228"}],"version-history":[{"count":0,"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/228\/revisions"}],"wp:attachment":[{"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=228"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=228"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=228"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}