internal void Refine(TPredicate other) { if (_left is null && _right is null) { // If this is a leaf node create left and/or right children for the new predicate TPredicate thisAndOther = _solver.And(_pred, other); if (_solver.IsSatisfiable(thisAndOther)) { // The predicates overlap, now check if this is contained in other TPredicate thisMinusOther = _solver.And(_pred, _solver.Not(other)); if (_solver.IsSatisfiable(thisMinusOther)) { // This is not contained in other, both children are needed _left = new PartitionTree(_solver, thisAndOther, null, null); // The right child corresponds to a conjunction with a negation, which matches thisMinusOther _right = new PartitionTree(_solver, thisMinusOther, null, null); } else // [[this]] subset of [[other]] { // Other implies this, so populate the left child with this _left = new PartitionTree(_solver, _pred, null, null); } } else // [[this]] subset of [[not(other)]] { // negation of other implies this, so populate the right child with this _right = new PartitionTree(_solver, _pred, null, null); //other must be false } }
internal void Refine(IBooleanAlgebra <TPredicate> solver, TPredicate other) { if (!StackHelper.TryEnsureSufficientExecutionStack()) { StackHelper.CallOnEmptyStack(Refine, solver, other); return; } TPredicate thisAndOther = solver.And(_pred, other); if (solver.IsSatisfiable(thisAndOther)) { // The predicates overlap, now check if this is contained in other TPredicate thisMinusOther = solver.And(_pred, solver.Not(other)); if (solver.IsSatisfiable(thisMinusOther)) { // This is not contained in other, minterms may need to be split if (_left is null) { Debug.Assert(_right is null); _left = new PartitionTree(thisAndOther); _right = new PartitionTree(thisMinusOther); } else { Debug.Assert(_right is not null); _left.Refine(solver, other); _right.Refine(solver, other); } } } }
/// <summary> /// Constructs a new internal enumerator. /// </summary> /// <param name="collection">The parent collection.</param> /// <param name="currentPredicate">The view predicate.</param> internal Enumerator( MethodMapping <Method> .ReadOnlyCollection collection, TPredicate currentPredicate) { enumerator = collection.GetEnumerator(); predicate = currentPredicate; }
private PartitionTree(IBooleanAlgebra <TPredicate> solver, TPredicate pred, PartitionTree?left, PartitionTree?right) { _solver = solver; _pred = pred; _left = left; _right = right; }
static T?FindDescendantWithBreadthFirstSearch(DependencyObject element, ref TPredicate predicate) { // We're using a pooled buffer writer to amortize allocations for the temporary collection of children // to visit for each level. The underlying array is deliberately just of type object and not DependencyObject // to reduce the number of generic instantiations and allow the rented arrays to be reused more. using ArrayPoolBufferWriter <object> bufferWriter = ArrayPoolBufferWriter <object> .Create(); int childrenCount = VisualTreeHelper.GetChildrenCount(element); // Add the top level children for (int i = 0; i < childrenCount; i++) { DependencyObject child = VisualTreeHelper.GetChild(element, i); if (child is T result && predicate.Match(result)) { return(result); } bufferWriter.Add(child); } // Explore each depth level for (int i = 0; i < bufferWriter.Count; i++) { DependencyObject parent = (DependencyObject)bufferWriter[i]; childrenCount = VisualTreeHelper.GetChildrenCount(parent); for (int j = 0; j < childrenCount; j++) { DependencyObject child = VisualTreeHelper.GetChild(parent, j); if (child is T result && predicate.Match(result)) { return(result); } bufferWriter.Add(child); } } return(null); }
static async ValueTask <bool> ExecuteAsync(TEnumerable source, TPredicate predicate, CancellationToken cancellationToken) { var enumerator = source.GetAsyncEnumerator(cancellationToken); try { while (await enumerator.MoveNextAsync().ConfigureAwait(false)) { if (await predicate.InvokeAsync(enumerator.Current, cancellationToken).ConfigureAwait(false)) { return(true); } } return(false); } finally { await enumerator.DisposeAsync().ConfigureAwait(false); } }
static T?FindDescendantWithDepthFirstSearch(DependencyObject element, ref TPredicate predicate) { int childrenCount = VisualTreeHelper.GetChildrenCount(element); for (int i = 0; i < childrenCount; i++) { DependencyObject child = VisualTreeHelper.GetChild(element, i); if (child is T result && predicate.Match(result)) { return(result); } T?descendant = FindDescendantWithDepthFirstSearch(child, ref predicate); if (descendant is not null) { return(descendant); } } return(null); }
internal PartitionTree(TPredicate pred) { _pred = pred; }
internal EquivalenceClass(IBooleanAlgebra <TPredicate> algebra, TPredicate set) { _set = set; _algebra = algebra; }