private static PostingWithFoundListOfTerms[] Intersect(PostingWithFoundListOfTerms[] a, PostingWithFoundTerm[] b) { int aIdx = 0; int bIdx = 0; int oldTermCount = a.First().Terms.Count; while (aIdx < a.Length && bIdx < b.Length) { PostingWithFoundListOfTerms aItem = a[aIdx]; PostingWithFoundTerm bItem = b[bIdx]; if (aItem.PostingId < bItem.PostingId) { aIdx++; } else if (bItem.PostingId < aItem.PostingId) { bIdx++; } else { aItem.Terms.Add(bItem.Term); aIdx++; bIdx++; } } return(a.Where(x => x.Terms.Count > oldTermCount).ToArray()); }
private static PostingWithFoundTerm[] Union(PostingWithFoundTerm[] list1, PostingWithFoundTerm[] list2) { var result = new List <PostingWithFoundTerm>(); int i1 = 0; int i2 = 0; while (i1 < list1.Length && i2 < list2.Length) { PostingWithFoundTerm item1 = list1[i1]; PostingWithFoundTerm item2 = list2[i2]; if (item1.PostingId < item2.PostingId) { result.Add(item1); i1++; } else if (item2.PostingId < item1.PostingId) { result.Add(item2); i2++; } else { result.Add(item1.Term.IsExactMatch ? item1 : item2); i1++; i2++; } } while (i1 < list1.Length) { result.Add(list1[i1]); i1++; } while (i2 < list2.Length) { result.Add(list2[i2]); i2++; } return(result.ToArray()); }