implement the SLINK algorithm