Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / ndp / fx / src / DataEntity / System / Data / Common / Utils / Boolean / Clause.cs / 2 / Clause.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Text; using System.Globalization; using System.Collections.ObjectModel; using System.Diagnostics; using System.Linq; namespace System.Data.Common.Utils.Boolean { ////// Base class for clauses, which are (constrained) combinations of literals. /// ///Type of normal form literal. internal abstract class Clause: NormalFormNode { private readonly Set > _literals; private readonly int _hashCode; /// /// Initialize a new clause. /// /// Literals contained in the clause. /// Type of expression tree to produce from literals. protected Clause(Set> literals, ExprType treeType) : base(ConvertLiteralsToExpr(literals, treeType)) { _literals = literals.AsReadOnly(); _hashCode = _literals.GetElementsHashCode(); } /// /// Gets the literals contained in this clause. /// internal Set> Literals { get { return _literals; } } // Given a collection of literals and a tree type, returns an expression of the given type. private static BoolExpr ConvertLiteralsToExpr(Set > literals, ExprType treeType) { bool isAnd = ExprType.And == treeType; Debug.Assert(isAnd || ExprType.Or == treeType); IEnumerable > literalExpressions = literals.Select( new Func , BoolExpr >(ConvertLiteralToExpression)); if (isAnd) { return new AndExpr (literalExpressions); } else { return new OrExpr (literalExpressions); } } // Given a literal, returns its logical equivalent expression. private static BoolExpr ConvertLiteralToExpression(Literal literal) { return literal.Expr; } public override string ToString() { StringBuilder builder = new StringBuilder(); builder.Append("Clause{"); builder.Append(_literals); return builder.Append("}").ToString(); } public override int GetHashCode() { return _hashCode; } public override bool Equals(object obj) { Debug.Fail("call typed Equals"); return base.Equals(obj); } } /// /// A DNF clause is of the form: /// /// Literal1 . Literal2 . ... /// /// Each literal is of the form: /// /// Term /// /// or /// /// !Term /// ///Type of normal form literal. internal sealed class DnfClause: Clause , IEquatable > { /// /// Initialize a DNF clause. /// /// Literals in clause. internal DnfClause(Set> literals) : base(literals, ExprType.And) { } public bool Equals(DnfClause other) { return null != other && other.Literals.SetEquals(Literals); } } /// /// A CNF clause is of the form: /// /// Literal1 + Literal2 . ... /// /// Each literal is of the form: /// /// Term /// /// or /// /// !Term /// ///Type of normal form literal. internal sealed class CnfClause: Clause , IEquatable > { /// /// Initialize a CNF clause. /// /// Literals in clause. internal CnfClause(Set> literals) : base(literals, ExprType.Or) { } public bool Equals(CnfClause other) { return null != other && other.Literals.SetEquals(Literals); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Text; using System.Globalization; using System.Collections.ObjectModel; using System.Diagnostics; using System.Linq; namespace System.Data.Common.Utils.Boolean { ////// Base class for clauses, which are (constrained) combinations of literals. /// ///Type of normal form literal. internal abstract class Clause: NormalFormNode { private readonly Set > _literals; private readonly int _hashCode; /// /// Initialize a new clause. /// /// Literals contained in the clause. /// Type of expression tree to produce from literals. protected Clause(Set> literals, ExprType treeType) : base(ConvertLiteralsToExpr(literals, treeType)) { _literals = literals.AsReadOnly(); _hashCode = _literals.GetElementsHashCode(); } /// /// Gets the literals contained in this clause. /// internal Set> Literals { get { return _literals; } } // Given a collection of literals and a tree type, returns an expression of the given type. private static BoolExpr ConvertLiteralsToExpr(Set > literals, ExprType treeType) { bool isAnd = ExprType.And == treeType; Debug.Assert(isAnd || ExprType.Or == treeType); IEnumerable > literalExpressions = literals.Select( new Func , BoolExpr >(ConvertLiteralToExpression)); if (isAnd) { return new AndExpr (literalExpressions); } else { return new OrExpr (literalExpressions); } } // Given a literal, returns its logical equivalent expression. private static BoolExpr ConvertLiteralToExpression(Literal literal) { return literal.Expr; } public override string ToString() { StringBuilder builder = new StringBuilder(); builder.Append("Clause{"); builder.Append(_literals); return builder.Append("}").ToString(); } public override int GetHashCode() { return _hashCode; } public override bool Equals(object obj) { Debug.Fail("call typed Equals"); return base.Equals(obj); } } /// /// A DNF clause is of the form: /// /// Literal1 . Literal2 . ... /// /// Each literal is of the form: /// /// Term /// /// or /// /// !Term /// ///Type of normal form literal. internal sealed class DnfClause: Clause , IEquatable > { /// /// Initialize a DNF clause. /// /// Literals in clause. internal DnfClause(Set> literals) : base(literals, ExprType.And) { } public bool Equals(DnfClause other) { return null != other && other.Literals.SetEquals(Literals); } } /// /// A CNF clause is of the form: /// /// Literal1 + Literal2 . ... /// /// Each literal is of the form: /// /// Term /// /// or /// /// !Term /// ///Type of normal form literal. internal sealed class CnfClause: Clause , IEquatable > { /// /// Initialize a CNF clause. /// /// Literals in clause. internal CnfClause(Set> literals) : base(literals, ExprType.Or) { } public bool Equals(CnfClause other) { return null != other && other.Literals.SetEquals(Literals); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SpecularMaterial.cs
- InkCanvasFeedbackAdorner.cs
- LinqDataSourceInsertEventArgs.cs
- SmiGettersStream.cs
- VisualStyleRenderer.cs
- DynamicUpdateCommand.cs
- TextEditor.cs
- SHA512Managed.cs
- UriParserTemplates.cs
- InvalidateEvent.cs
- TableLayout.cs
- VarRemapper.cs
- TypeValidationEventArgs.cs
- ThreadBehavior.cs
- SequentialActivityDesigner.cs
- BuildProviderAppliesToAttribute.cs
- KerberosReceiverSecurityToken.cs
- SoapFault.cs
- Enum.cs
- SecondaryViewProvider.cs
- ParallelQuery.cs
- InternalMappingException.cs
- AVElementHelper.cs
- ParserOptions.cs
- StandardOleMarshalObject.cs
- ApplicationSettingsBase.cs
- QueryIntervalOp.cs
- Pen.cs
- TypefaceMetricsCache.cs
- List.cs
- EmptyReadOnlyDictionaryInternal.cs
- WebPartEditorOkVerb.cs
- CommentAction.cs
- ValidatedMobileControlConverter.cs
- DecimalStorage.cs
- Page.cs
- RequiredFieldValidator.cs
- CodeMemberEvent.cs
- LinkedResourceCollection.cs
- ListBoxItemAutomationPeer.cs
- WindowsEditBox.cs
- SimpleHandlerFactory.cs
- BoundField.cs
- PointAnimationBase.cs
- SmiContextFactory.cs
- SchemaObjectWriter.cs
- AlignmentYValidation.cs
- ViewBase.cs
- DataTableCollection.cs
- TransformPatternIdentifiers.cs
- LambdaCompiler.ControlFlow.cs
- CallTemplateAction.cs
- Type.cs
- ArrayConverter.cs
- Timer.cs
- ModelMemberCollection.cs
- JoinGraph.cs
- DetailsViewUpdatedEventArgs.cs
- Setter.cs
- WindowsFormsHostAutomationPeer.cs
- LinearGradientBrush.cs
- SchemaTableColumn.cs
- SetState.cs
- ProgramPublisher.cs
- DispatchChannelSink.cs
- QueryContinueDragEvent.cs
- PaginationProgressEventArgs.cs
- StyleXamlParser.cs
- mactripleDES.cs
- AstNode.cs
- ProcessHost.cs
- RadioButtonFlatAdapter.cs
- SimpleHandlerFactory.cs
- IndexOutOfRangeException.cs
- TextEditorParagraphs.cs
- sqlinternaltransaction.cs
- XmlObjectSerializerWriteContext.cs
- RemoteEndpointMessageProperty.cs
- Pair.cs
- PowerStatus.cs
- ButtonField.cs
- CanExecuteRoutedEventArgs.cs
- XmlUtilWriter.cs
- SafeBitVector32.cs
- _SSPISessionCache.cs
- BuilderElements.cs
- ToolStripSplitButton.cs
- OleDbCommand.cs
- TextLineBreak.cs
- MethodInfo.cs
- EmissiveMaterial.cs
- FontConverter.cs
- dataSvcMapFileLoader.cs
- MasterPageBuildProvider.cs
- _TimerThread.cs
- BaseProcessor.cs
- TripleDESCryptoServiceProvider.cs
- SafeNativeMethods.cs
- FileSystemEventArgs.cs
- RepeatBehavior.cs