agglomerative cluster and dbscan implementation