Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add batch.BySize function #735

Merged
merged 8 commits into from
Jun 17, 2024
Merged

Conversation

nathan-artie
Copy link
Contributor

No description provided.

@nathan-artie nathan-artie marked this pull request as ready for review June 17, 2024 22:58

// BySize takes a series of elements, encodes them, groups them into batches of bytes that sum to at most [maxSize], and
// then passes each of those batches to the [yield] function.
func BySize[T any](in []T, maxSize int, encode func(T) ([]byte, error), yield func([][]byte) error) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maxSizeBytes?

}
{
// Non-empty slice + all items exactly fit into just under one batch:
batches, err := testBySize([]string{"foo", "bar", "baz", "qux"}, 13, goodEncoder)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth adding a check on how many times goodEncoding was called? Which will test how many times yield was called

Copy link
Contributor Author

@nathan-artie nathan-artie Jun 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case goodEncoder will be called once for each item (4 times) but yield will be called once. The amount of times that yield is called will always equal the length of batches.

@nathan-artie nathan-artie merged commit b75b4ac into master Jun 17, 2024
1 check passed
@nathan-artie nathan-artie deleted the nv/add-function-to-batch-by-size branch June 17, 2024 23:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants