Do we need to implement this algorithm ourselves? Or is there an efficient out-of-the-box implementation we could make use of somewhere?