Fast k-means code.