public void Test2() { var fastCollection = new FastCollection <int>(); var filter1 = new ComparisonFilter(OperationTargetBuilder.BuildForRoot(fastCollection), ComparisonFilterType.Less, 4); var filter2 = new ComparisonFilter(OperationTargetBuilder.BuildForRoot(fastCollection), ComparisonFilterType.Greater, 6); var filter3 = new CompoundFilter( CompoundFilter.CompoundFilterType.And, filter1, filter2); var filter4 = new ComparisonFilter(OperationTargetBuilder.BuildForRoot(fastCollection), ComparisonFilterType.Less, 2); var filter5 = new ComparisonFilter(OperationTargetBuilder.BuildForRoot(fastCollection), ComparisonFilterType.Less, 7); var filter7 = new CompoundFilter( CompoundFilter.CompoundFilterType.And, filter4, filter5); var filter6 = new ComparisonFilter(OperationTargetBuilder.BuildForRoot(fastCollection), ComparisonFilterType.Less, 8); var filter8 = new CompoundFilter( CompoundFilter.CompoundFilterType.And, filter3, filter7, filter6); var executionGroups = FiltersExecutionPipeline.Build(filter8).GetExecutionGroups(); Assert.AreEqual(0, executionGroups.ElementAt(0).Level); CollectionAssert.AreEquivalent(new [] { filter1, filter2, filter4, filter5, filter6 }, executionGroups.ElementAt(0).Filters); Assert.AreEqual(1, executionGroups.ElementAt(1).Level); Assert.AreEqual(new [] { filter3, filter7 }, executionGroups.ElementAt(1).Filters); Assert.AreEqual(2, executionGroups.ElementAt(2).Level); Assert.AreEqual(new [] { filter8 }, executionGroups.ElementAt(2).Filters); }
public void Test1() { var parser = new FiltersParser(); var fastCollection = new FastCollection <TestClassA>(); var parsed = parser.ParsePredicate((TestClassA x) => x.F1 > 3, OperationTargetBuilder.BuildForRoot(fastCollection)); Assert.IsAssignableFrom <ComparisonFilter>(parsed); Assert.AreEqual(ComparisonFilterType.Greater, ((ComparisonFilter)parsed).ComparisonFilterType); Assert.AreEqual(3, ((ComparisonFilter)parsed).Value); Assert.AreSame(fastCollection, ((ComparisonFilter)parsed).OperationTarget.RootFastCollection); }
public void Test1() { var fastCollection = new FastCollection <int>(); var filter1 = new ComparisonFilter(OperationTargetBuilder.BuildForRoot(fastCollection), ComparisonFilterType.Less, 3); var filter2 = new ComparisonFilter(OperationTargetBuilder.BuildForRoot(fastCollection), ComparisonFilterType.Greater, 6); var filter3 = new CompoundFilter( CompoundFilter.CompoundFilterType.And, filter1, filter2); var executionGroups = FiltersExecutionPipeline.Build(filter3).GetExecutionGroups(); Assert.AreEqual(0, executionGroups.ElementAt(0).Level); CollectionAssert.AreEquivalent(new [] { filter1, filter2 }, executionGroups.ElementAt(0).Filters); Assert.AreEqual(1, executionGroups.ElementAt(1).Level); CollectionAssert.AreEquivalent(new [] { filter3 }, executionGroups.ElementAt(1).Filters); }
public FastCollectionBuilderFlow <TRaw> AddIndex <TIndexKey>( [NotNull] Expression <Func <TRaw, TIndexKey> > target, [NotNull] params IIndexFactory[] indexFactories) { if (target == null) { throw new ArgumentNullException(nameof(target)); } if (indexFactories == null) { throw new ArgumentNullException(nameof(indexFactories)); } foreach (var indexFactory in indexFactories) { var index = indexFactory.CreateIndex <TIndexKey>(); var operationTarget = OperationTargetBuilder.BuildForSelector(_fastCollection, target); FillIndex(index, _fastCollection, target.Compile()); _fastCollection.IndicesCoverageInternal.AddIndex(operationTarget, index); } return(this); }
/// <summary> /// Try parse comparasion filter (less, greater and others) /// </summary> private static ComparisonFilter TryParseComparisonFilter(Expression expression) { if (!(expression is BinaryExpression binaryExpression)) { return(null); } var comparationType = ComparisonFilterType.None; switch (expression.NodeType) { case ExpressionType.GreaterThan: comparationType = ComparisonFilterType.Greater; break; case ExpressionType.GreaterThanOrEqual: comparationType = ComparisonFilterType.GreaterOrEqual; break; case ExpressionType.LessThan: comparationType = ComparisonFilterType.Less; break; case ExpressionType.LessThanOrEqual: comparationType = ComparisonFilterType.LessOrEqual; break; case ExpressionType.Equal: comparationType = ComparisonFilterType.Equal; break; case ExpressionType.NotEqual: comparationType = ComparisonFilterType.NotEqual; break; default: return(null); } if (binaryExpression.Right.NodeType == ExpressionType.Constant) { var operationTarget = OperationTargetBuilder.Build(binaryExpression.Left); if (operationTarget == null) { return(null); } return(new ComparisonFilter(operationTarget, comparationType, ((ConstantExpression)binaryExpression.Right).Value)); } if (binaryExpression.Left.NodeType == ExpressionType.Constant) { var operationTarget = OperationTargetBuilder.Build(binaryExpression.Right); if (operationTarget == null) { return(null); } return(new ComparisonFilter(operationTarget, comparationType.Mirror(), ((ConstantExpression)binaryExpression.Left).Value)); } return(null); }
public void AndCompoundTest() { var parser = new FiltersParser(); var fastCollection = new FastCollection <TestClassA>(); var parsed = parser.ParsePredicate((TestClassA x) => (x.F1 > 3) && (x.F1 <= 10), OperationTargetBuilder.BuildForRoot(fastCollection)); Assert.IsAssignableFrom <CompoundFilter>(parsed); Assert.AreEqual(CompoundFilter.CompoundFilterType.And, ((CompoundFilter)parsed).OperationType); var filter1 = (ComparisonFilter)((CompoundFilter)parsed).Operands.ElementAt(0); Assert.AreEqual(ComparisonFilterType.Greater, filter1.ComparisonFilterType); Assert.AreEqual(3, filter1.Value); var filter2 = (ComparisonFilter)((CompoundFilter)parsed).Operands.ElementAt(1); Assert.AreEqual(ComparisonFilterType.LessOrEqual, filter2.ComparisonFilterType); Assert.AreEqual(10, filter2.Value); }
/// <inheritdoc /> public IFastCollectionEnumerator <TData> GetEnumerator() { return(new FastCollectionIterator <TData>(this, OperationTargetBuilder.BuildForRoot(this), Items)); }