This implementation performs a nonparametric KS test for equality of distributions
by resampling under the null hypothesis. It supports one-sided and two-sided alternatives.
If keep.boots = TRUE, the function returns all bootstrap statistics,
which can be used for further analysis (e.g., plotting).
If the p-value is zero due to no bootstrap statistic exceeding the observed value,
it is adjusted to 1 / (2 * nboots) to avoid a zero p-value.