Skip to content

Defining sorting criteria in SortedDictionary #6

Closed

Description

@andreadelfante

Is it possible defining a sorting criteria in SortedDictionary? I'm using this data structure but i need to sort elements in order descending directly.

Activity

  1. daniel-jonathan commented on May 11, 2017

    @daniel-jonathan
    Member

    The SortedDictionary is sorted by its key value. So if you want to access it in descending order, you can access it backwards. For example:

    let n = dict.count
    for i in 1..<n {
        let e = dict[n - i]
        // do something with `e`
    }

    Something like that should work. If you need, please reopen the issue. All the best!

  2. andreadelfante commented on May 12, 2017

    @andreadelfante
    Author

    Yes, I use SortedDictionary.reversed() to get an array of tuple..but i wanna reduce my algorithm complexity, trying to perform only one iteration. It could be useful implementing a custom comparable closure, like TreeMap in Java.

  3. daniel-jonathan commented on May 14, 2017

    @daniel-jonathan
    Member

    That is a good idea, I will look into that.

  4. daniel-jonathan commented on May 15, 2017

    @daniel-jonathan
    Member

    Here is an issue for your feature request: #7. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions