<commit_before>package bild

import (
	"runtime"
	"sync"
)

// ParallelizationEnabled sets if package should use goroutines when possible
var ParallelizationEnabled = true

func parallelize(size int, fn func(start, end int)) {
	if !ParallelizationEnabled {
		fn(0, size)
	} else {
		var wg sync.WaitGroup
		procs := runtime.GOMAXPROCS(0)
		partSize := size / procs
		wg.Add(procs)

		for i := 0; i < procs; i++ {
			i := i // needed for the closure to work
			go func() {
				defer wg.Done()
				fn(partSize*i, partSize*(i+1))
			}()
		}

		wg.Wait()
	}
}
<commit_msg>fixed left < partSize case<commit_after>package bild

import (
	"runtime"
	"sync"
)

// ParallelizationEnabled sets if package should use goroutines when possible
var ParallelizationEnabled = true

func parallelize(size int, fn func(start, end int)) {
	if !ParallelizationEnabled {
		fn(0, size)
	} else {
		var wg sync.WaitGroup
		procs := runtime.GOMAXPROCS(0)

		counter := size
		partSize := size / procs
		for counter > 0 {
			start := counter - partSize
			end := counter
			if start < 0 {
				start = 0
			}
			counter -= partSize
			wg.Add(1)
			go func() {
				defer wg.Done()
				fn(start, end)
			}()
		}

		wg.Wait()
	}
}

{'fraction_non_alphanumeric': 0.12063227953410982, 'fraction_numerical': 0.008319467554076539, 'mean_word_length': 3.0234113712374584, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3651459', 'n_tokens_mistral': 497, 'n_tokens_neox': 435, 'n_words': 124}