  An optimal constant-composition or constant-weight code of weight $w$ has
linear size if and only if its distance $d$ is at least $2w-1$. When $d\geq
2w$, the determination of the exact size of such a constant-composition or
constant-weight code is trivial, but the case of $d=2w-1$ has been solved
previously only for binary and ternary constant-composition and constant-weight
codes, and for some sporadic instances.
  This paper provides a construction for quasicyclic optimal
constant-composition and constant-weight codes of weight $w$ and distance
$2w-1$ based on a new generalization of difference triangle sets. As a result,
the sizes of optimal constant-composition codes and optimal constant-weight
codes of weight $w$ and distance $2w-1$ are determined for all such codes of
sufficiently large lengths. This solves an open problem of Etzion.
  The sizes of optimal constant-composition codes of weight $w$ and distance
$2w-1$ are also determined for all $w\leq 6$, except in two cases.
