Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defining sorting criteria in SortedDictionary #6

Closed
andreadelfante opened this issue May 11, 2017 · 4 comments
Closed

Defining sorting criteria in SortedDictionary #6

andreadelfante opened this issue May 11, 2017 · 4 comments
Assignees

Comments

@andreadelfante
Copy link

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.

@daniel-jonathan
Copy link
Member

daniel-jonathan commented May 11, 2017

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!

@andreadelfante
Copy link
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.

@daniel-jonathan
Copy link
Member

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

@daniel-jonathan
Copy link
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
Development

No branches or pull requests

2 participants