Search algorithm now generic across all graph types