I'm working on a
LinqEnumerable class (reviewable here), and I'm no Big-O expert and I'm pretty bad with algorithms, so I wonder what the complexity is for what I've implemented here, and whether it could be improved.
Correlates the elements of two sequences based on matching keys.
Private encapsulated As New Collection Option Explicit
Public Function Join(ByVal inner As LinqEnumerable, _ ByVal outerKeySelector As Delegate, _ ByVal innerKeySelector As Delegate, _ ByVal resultSelector As Delegate) As LinqEnumerable Dim result As New LinqEnumerable Dim outerValue As Variant Dim outerKey As Variant Dim innerValue As Variant Dim innerKey As Variant Dim innerList As System.List Set innerList = inner.ToList For Each outerValue In encapsulated outerKey = outerKeySelector.Execute(outerValue) For Each innerValue In innerList innerKey = innerKeySelector.Execute(innerValue) If outerKey = innerKey Then result.Add resultSelector.Execute(outerValue, innerValue) innerList.Remove innerValue End If Next Next Set Join = result End Function
I've been told this might be \$O(log(n))\$, but since
innerList.Remove is \$O(n)\$ I'm not sure. Could it be?