% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/shards.R
\name{shards}
\alias{shards}
\title{Shard Descriptor Creation}
\usage{
shards(
  n,
  block_size = "auto",
  workers = NULL,
  strategy = c("contiguous", "strided"),
  min_shards_per_worker = 4L,
  max_shards_per_worker = 64L,
  scratch_bytes_per_item = 0,
  scratch_budget = 0
)
}
\arguments{
\item{n}{Integer. Total number of items to shard.}

\item{block_size}{Block size specification. Can be:
\itemize{
\item \code{"auto"} (default): Autotune based on worker count
\item Integer: Explicit number of items per shard
\item Character: Human-readable like \code{"1K"}, \code{"10K"}
}}

\item{workers}{Integer. Number of workers for autotuning (default: pool size or detectCores - 1).}

\item{strategy}{Sharding strategy: \code{"contiguous"} (default) or \code{"strided"}.}

\item{min_shards_per_worker}{Integer. Minimum shards per worker for load balancing (default 4).}

\item{max_shards_per_worker}{Integer. Maximum shards per worker to limit overhead (default 64).}

\item{scratch_bytes_per_item}{Numeric. Expected scratch memory per item for memory budgeting.}

\item{scratch_budget}{Character or numeric. Total scratch memory budget (e.g., "1GB").}
}
\value{
A \code{shard_descriptor} object containing:
\itemize{
\item \code{n}: Total items
\item \code{block_size}: Computed block size
\item \code{strategy}: Strategy used
\item \code{shards}: List of shard descriptors with \code{id}, \code{start}, \code{end}, \code{idx} fields
}
}
\description{
Create shard descriptors for parallel execution with autotuning.

Produces shard descriptors (index ranges) for use with \code{shard_map()}.
Supports autotuning based on worker count and memory constraints.
}
\examples{
blocks <- shards(1e6, workers = 8)
length(blocks$shards)

blocks <- shards(1000, block_size = 100)

blocks$shards[[1]]$idx
}
