Diff
checker
Testo
Testo
Immagini
Documenti
Excel
Cartelle
Legal
Enterprise
Applicazione per desktop
Prezzi
Accedi
Scarica Diffchecker Desktop
Confronta il testo
Trova la differenza tra due file di testo
Strumenti
Cronologia
Editor live
Comprimi invariate
Senza a capo
Layout
Diviso
Unificato
Livello di dettaglio
Intelligente
Parola
Carattere
Evidenziazione sintassi
Scegli sintassi
Ignora
Trasforma testo
Vai alla prima modifica
Modifica input
Diffchecker Desktop
Il modo più sicuro per usare Diffchecker. Ottieni l'app Diffchecker Desktop: i tuoi diff non lasciano mai il tuo computer!
Ottieni Desktop
Defined Concurrency
Creato
4 anni fa
Il diff non scade mai
Eliminare
Esporta
Condividere
Spiegare
4 rimozioni
Linee
Totale
Rimosso
Caratteri
Totale
Rimosso
Per continuare a utilizzare questa funzione, aggiorna a
Diff
checker
Pro
Visualizza prezzi
24 linee
Copia tutti
21 aggiunte
Linee
Totale
Aggiunto
Caratteri
Totale
Aggiunto
Per continuare a utilizzare questa funzione, aggiorna a
Diff
checker
Pro
Visualizza prezzi
41 linee
Copia tutti
Copia
Copiato
Copia
Copiato
import
"sync"
import
(
"runtime"
"sync"
)
var _concurrency = runtime.NumCPU()
func MaxConcurrency(concurrency int) {
_concurrency = concurrency
}
// Map manipulates a slice and transforms it to a slice of another type.
// Map manipulates a slice and transforms it to a slice of another type.
// `iteratee` is call in parallel. Result keep the same order.
// `iteratee` is call in parallel. Result keep the same order.
func Map[T any, R any](collection []T, iteratee func(T, int) R) []R {
func Map[T any, R any](collection []T, iteratee func(T, int) R) []R {
result := make([]R, len(collection))
result := make([]R, len(collection))
Copia
Copiato
Copia
Copiato
c := _concurrency
if c <= 0 {
c = len(collection)
}
routines := make(chan struct{}, c)
var wg sync.WaitGroup
var wg sync.WaitGroup
Copia
Copiato
Copia
Copiato
wg.Add(len(collection))
for i, item := range collection {
for i, item := range collection {
Copia
Copiato
Copia
Copiato
wg.Add(1)
go func(_item T, _i int) {
go func(_item T, _i int) {
Copia
Copiato
Copia
Copiato
defer wg.Done()
routines <- struct{}{}
res := iteratee(_item, _i)
res := iteratee(_item, _i)
Copia
Copiato
Copia
Copiato
<-routines
result[_i] = res
result[_i] = res
Copia
Copiato
Copia
Copiato
wg.Done()
}(item, i)
}(item, i)
}
}
wg.Wait()
wg.Wait()
return result
return result
}
}
Diff salvati
Testo originale
Apri file
import "sync" // Map manipulates a slice and transforms it to a slice of another type. // `iteratee` is call in parallel. Result keep the same order. func Map[T any, R any](collection []T, iteratee func(T, int) R) []R { result := make([]R, len(collection)) var wg sync.WaitGroup wg.Add(len(collection)) for i, item := range collection { go func(_item T, _i int) { res := iteratee(_item, _i) result[_i] = res wg.Done() }(item, i) } wg.Wait() return result }
Testo modificato
Apri file
import ( "runtime" "sync" ) var _concurrency = runtime.NumCPU() func MaxConcurrency(concurrency int) { _concurrency = concurrency } // Map manipulates a slice and transforms it to a slice of another type. // `iteratee` is call in parallel. Result keep the same order. func Map[T any, R any](collection []T, iteratee func(T, int) R) []R { result := make([]R, len(collection)) c := _concurrency if c <= 0 { c = len(collection) } routines := make(chan struct{}, c) var wg sync.WaitGroup for i, item := range collection { wg.Add(1) go func(_item T, _i int) { defer wg.Done() routines <- struct{}{} res := iteratee(_item, _i) <-routines result[_i] = res }(item, i) } wg.Wait() return result }
Trovare la differenza