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

I found that your previous version contained the sorting API, but it was wrong. I have corrected it for you. Now I can't find this api. #21

Open
CodeSlaveZhang opened this issue Feb 13, 2023 · 0 comments

Comments

@CodeSlaveZhang
Copy link

  • (void)sortWithValuesUsingComparator:(NSComparator NS_NOESCAPE)cmptr{
    //[self.readWriteLock lock];
    NSArray *valuesBefore = _mutableValues.copy;
    NSArray *keysBefore = _mutableKeys.copy;
    [_mutableValues sortUsingComparator:cmptr];
    [_mutableKeys sortUsingComparator:^NSComparisonResult(id _Nonnull key1, id _Nonnull key2) {
    ///find the obj before sort operation with key
    NSInteger keyIndexBefore1 = [keysBefore indexOfObject:key1];
    id obj1 = valuesBefore[keyIndexBefore1];
    NSInteger keyIndexBefore2 = [keysBefore indexOfObject:key2];
    id obj2 = valuesBefore[keyIndexBefore2];
    ///find the objct index in sorted values
    NSInteger index1 = [_mutableValues indexOfObject:obj1];;
    NSInteger index2 = [_mutableValues indexOfObject:obj2];;
    return index2<index1;
    }];
    //[self.readWriteLock unlock];
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant