我有一个TDictionary。它正在通过一个大循环填充。当循环结束后,我需要检索得分更高的前10个键(字符串)。最有效的方法是什么?
在Objective-C(Cocoa)中,我使用以下代码:
NSArray *top_words_sorted_array = [top_words_dictionary keysSortedByValueUsingSelector:@selector(compare:)];
如何在Delphi中对新排序的数组进行迭代?
我有一个TDictionary。它正在通过一个大循环填充。当循环结束后,我需要检索得分更高的前10个键(字符串)。最有效的方法是什么?
在Objective-C(Cocoa)中,我使用以下代码:
NSArray *top_words_sorted_array = [top_words_dictionary keysSortedByValueUsingSelector:@selector(compare:)];
如何在Delphi中对新排序的数组进行迭代?
您的Cocoa代码相应的Delphi代码如下:
type
TScorePair = TPair<string,Integer>;
var
ScoresArray: TArray<TScorePair>;
....
ScoresArray := Scores.ToArray;
TArray.Sort(ScoresArray,
TComparer<TScorePair>.Construct(
function(const L, R: TScorePair): Integer
begin
Result := R.Value - L.Value;
end
)
);
DeHL.Collections.DoubleSortedBidiMap
正好符合您的需求。该项目页面上说已停止更新,但我每天都在使用它,并且从未出现问题。