Giter VIP home page Giter VIP logo

Comments (5)

RaduBerinde avatar RaduBerinde commented on July 20, 2024

Hi,

One thing I'm seeing is that you are capturing idx inside the func of a goroutine which until Go 1.22 was a mistake (https://go.dev/blog/loopvar-preview). What version of Go are you using?

from pebble.

siennathesane avatar siennathesane commented on July 20, 2024

I'm using go.1.22.3

from pebble.

RaduBerinde avatar RaduBerinde commented on July 20, 2024

Overall the way the API is used is correct, this should be working. There must be some detail that's wrong. Could I get a pointer to utilities.GenerateRanges? Just want to check that To is indeed exclusive as this code assumes.

from pebble.

siennathesane avatar siennathesane commented on July 20, 2024

Sure, it's pretty straightforward.

// IteratorRange represents a range of numbers to chunk slices into.
type IteratorRange struct{ From, To uint64 }

// GenerateRanges generates a list of ranges from min to max with a batch size.
func GenerateRanges(min, max uint64, batchSize uint64) []IteratorRange {
	if batchSize == 0 {
		batchSize = 1
	}

	var ranges []IteratorRange
	// this has to be from <= max to include the last batch
	for from := min; from <= max; from += batchSize {
		// without -1 the first batch will be 10-20 and the second batch will be 20-30
		// with -1 the first batch will be 10-19 and the second batch will be 20-29
		to := (from + batchSize) - 1
		if to > max {
			to = max
		}
		ranges = append(ranges, IteratorRange{from, to})
	}

	return ranges
}

from pebble.

RaduBerinde avatar RaduBerinde commented on July 20, 2024

Well, it looks like To is inclusive (it's from+batchsize-1

from pebble.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.