Diff
checker
텍스트
텍스트
이미지
문서
Excel
폴더
Legal
Enterprise
데스크톱
요금제
로그인
데스크톱 앱 다운로드
텍스트 비교
두 텍스트 파일의 차이점을 찾아보세요
도구
기록
실시간 편집
변경 없는 행 숨기기
줄바꿈 비활성화
레이아웃
나란히 보기
합쳐 보기
비교 단위
스마트
단어
글자
구문 강조
언어 선택
제외
텍스트 변환
첫 변경으로
수정
Diffchecker Desktop
가장 안전하게 Diffchecker를 사용하는 방법. 데스크톱 앱을 사용하면 비교 데이터가 외부로 전송되지 않습니다!
데스크톱 앱 받기
Defined Concurrency
생성일
4년 전
비교 결과 만료 없음
초기화
내보내기
공유
설명
4 삭제
행
총
삭제
글자
총
삭제
이 기능을 계속 사용하려면 업그레이드해 주세요
Diff
checker
Pro
요금제 보기
24 행
복사
21 추가
행
총
추가
글자
총
추가
이 기능을 계속 사용하려면 업그레이드해 주세요
Diff
checker
Pro
요금제 보기
41 행
복사
복사
복사됨
복사
복사됨
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))
복사
복사됨
복사
복사됨
c := _concurrency
if c <= 0 {
c = len(collection)
}
routines := make(chan struct{}, c)
var wg sync.WaitGroup
var wg sync.WaitGroup
복사
복사됨
복사
복사됨
wg.Add(len(collection))
for i, item := range collection {
for i, item := range collection {
복사
복사됨
복사
복사됨
wg.Add(1)
go func(_item T, _i int) {
go func(_item T, _i int) {
복사
복사됨
복사
복사됨
defer wg.Done()
routines <- struct{}{}
res := iteratee(_item, _i)
res := iteratee(_item, _i)
복사
복사됨
복사
복사됨
<-routines
result[_i] = res
result[_i] = res
복사
복사됨
복사
복사됨
wg.Done()
}(item, i)
}(item, i)
}
}
wg.Wait()
wg.Wait()
return result
return result
}
}
저장된 비교 결과
원본
파일 열기
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 }
수정본
파일 열기
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 }
비교하기