k-means component implementation