a function for link distance