Implementation of get adjacency function