mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
Solution for keysSortedByValueUsingComparator: incl multiple keys with same value
This commit is contained in:
parent
a4ec3d9d6f
commit
c692d5e5ca
1 changed files with 9 additions and 2 deletions
|
@ -29,6 +29,8 @@
|
|||
#import "common.h"
|
||||
#import "Foundation/NSDictionary.h"
|
||||
#import "Foundation/NSArray.h"
|
||||
#import "Foundation/NSMutableArray.h"
|
||||
#import "Foundation/NSOrderedSet.h"
|
||||
#import "Foundation/NSData.h"
|
||||
#import "Foundation/NSException.h"
|
||||
#import "Foundation/NSAutoreleasePool.h"
|
||||
|
@ -958,8 +960,13 @@ compareIt(id o1, id o2, void* context)
|
|||
- (NSArray *)keysSortedByValueWithOptions: (NSSortOptions)opts
|
||||
usingComparator: (NSComparator)cmptr
|
||||
{
|
||||
return [[self allKeys] sortedArrayWithOptions: opts
|
||||
usingComparator: cmptr];
|
||||
NSArray* sortedValues = [[self allValues] sortedArrayWithOptions: opts usingComparator: cmptr];
|
||||
NSArray* noDuplicates = [[NSOrderedSet orderedSetWithArray:sortedValues] array];
|
||||
NSMutableArray* result = [[NSMutableArray alloc] initWithCapacity:[sortedValues length]];
|
||||
for (NSObject* value in noDuplicates) {
|
||||
[result addObjectsFromArray:[self allKeysForObject:value]];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue