Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

344
Visualizações
Async Sorting (using Tasks) in .NET

I'm building an interpreter and need to create a function in my standard library that sorts based on a user-defined comparator. This comparator must be async, so this requires a sorting function itself is async (using Tasks).

Is there an existing .NET sorting function that allows Tasks in the comparer? That is, the comparer returns a Task<int> and the sorting function completes the Task and uses the int to sort.

For example, a version of the List.Sort(IComparer<T>) function where Compare(T,T) returned a Task<int> instead of an int.

(I'm using F# but happy to use C# libraries)

Edit: imagine the comparer needed to make a HTTP POST to compare two items.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You could implement an async mergesort implementation that would do that.

And in fact, the Wikipedia article on Mergesort actually discusses parallel implementations.

The basic algorithm is simplicity itself:

  • Start with a list of items to be sorted
  • If its length is 0 or 1, you're done: they are already sorted by definition.
  • Partition that list into two halves
  • Recursively merge sort each half, and then
  • merge them together.

If your list is a linked list, no extra memory is needed, as the next point provides all that's needed.

If your list is an array-like construct, then you have to eat extra memory to create working arrays for each half as an in-place merge is not very practical.

Edited to note: Here's a little paperlet from Microsoft on implementing a .Net parallel mergesort with multiple partitions, not just 2: https://devblogs.microsoft.com/pfxteam/parallel-merge-sort-using-barrier/

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda