internal override IntArrayList GetMatchingResources(out bool sortedById) { bool reverseLink = (_propId < 0 && MyPalStorage.Storage.IsLinkDirected(-_propId)); IResultSet rs = MyPalStorage.Storage.SelectLinksOfType(reverseLink ? -_propId : _propId); try { IntArrayList list; if (reverseLink) { list = DoGetResourcesFromResultSet(rs, 1); list.Sort(); } else { list = DoGetResourcesFromResultSet(rs, 0); list.Sort(); if (!MyPalStorage.Storage.IsLinkDirected(_propId)) { IntArrayList list2 = DoGetResourcesFromResultSet(rs, 1); list2.Sort(); list = IntArrayList.MergeSorted(list, list2); } } list.RemoveDuplicatesSorted(); sortedById = true; return(list); } finally { rs.Dispose(); } }
internal override IntArrayList GetMatchingResources(out bool sortedById) { sortedById = true; if (_sourcePredicates.Length == 0) { return(new IntArrayList()); } bool srcSortedById; IntArrayList result = _sourcePredicates [0].GetMatchingResources(out srcSortedById); if (!srcSortedById) { result.Sort(); } for (int i = 1; i < _sourcePredicates.Length; i++) { IntArrayList list2 = _sourcePredicates [i].GetMatchingResources(out srcSortedById); if (!srcSortedById) { list2.Sort(); } result = IntArrayList.MergeSorted(result, list2); } return(result); }
[Test] public void MergeSorted() { IntArrayList list1 = new IntArrayList(); list1.AddRange(new int[] { 2, 3, 5, 8 }); IntArrayList list2 = new IntArrayList(); list2.AddRange(new int[] { 2, 4, 5, 7 }); IntArrayList merged = IntArrayList.MergeSorted(list1, list2); AssertEquals(6, merged.Count); AssertEquals(2, merged [0]); AssertEquals(3, merged [1]); AssertEquals(4, merged [2]); AssertEquals(5, merged [3]); AssertEquals(7, merged [4]); AssertEquals(8, merged [5]); }