Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / ndp / fx / src / DataEntity / System / Data / Common / Utils / Boolean / Clause.cs / 1 / 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
- XmlnsCompatibleWithAttribute.cs
- ExpressionDumper.cs
- WinEventWrap.cs
- OptimalBreakSession.cs
- SqlProcedureAttribute.cs
- PeerApplication.cs
- TransportOutputChannel.cs
- ProxyWebPart.cs
- ConsoleKeyInfo.cs
- RowsCopiedEventArgs.cs
- GPPOINTF.cs
- WorkflowTransactionOptions.cs
- XPathBinder.cs
- PiiTraceSource.cs
- PolyBezierSegmentFigureLogic.cs
- PowerEase.cs
- ApplicationInfo.cs
- WebUtil.cs
- ViewGenResults.cs
- WebPartZoneDesigner.cs
- DecimalAverageAggregationOperator.cs
- KeyProperty.cs
- PointValueSerializer.cs
- CodeArrayIndexerExpression.cs
- DateBoldEvent.cs
- filewebresponse.cs
- ProcessInfo.cs
- TextAnchor.cs
- ViewStateModeByIdAttribute.cs
- XmlToDatasetMap.cs
- EventLogQuery.cs
- ListCollectionView.cs
- RadioButton.cs
- DbXmlEnabledProviderManifest.cs
- UnmanagedHandle.cs
- TextBox.cs
- IISUnsafeMethods.cs
- SqlNotificationRequest.cs
- FixedStringLookup.cs
- DragEventArgs.cs
- Matrix3D.cs
- TemplateColumn.cs
- OleAutBinder.cs
- CngKey.cs
- RelatedPropertyManager.cs
- EntityContainer.cs
- FileVersion.cs
- LabelAutomationPeer.cs
- AuthorizationRule.cs
- SendKeys.cs
- MemberNameValidator.cs
- RepeaterItem.cs
- Activity.cs
- ProviderSettingsCollection.cs
- ListDictionary.cs
- MessageVersionConverter.cs
- EventSetter.cs
- DynamicMethod.cs
- VisualBrush.cs
- RepeaterItemEventArgs.cs
- Random.cs
- SolidColorBrush.cs
- dbenumerator.cs
- ClientUrlResolverWrapper.cs
- Image.cs
- SqlServices.cs
- BinarySerializer.cs
- MediaPlayer.cs
- BroadcastEventHelper.cs
- ArgumentException.cs
- WindowsMenu.cs
- MenuItemStyleCollection.cs
- ArrayConverter.cs
- XmlSerializationReader.cs
- ColumnWidthChangingEvent.cs
- MimeTypeAttribute.cs
- ProxyWebPartConnectionCollection.cs
- DelayedRegex.cs
- ScrollBar.cs
- Context.cs
- AspCompat.cs
- OleCmdHelper.cs
- FormParameter.cs
- HashMembershipCondition.cs
- StaticContext.cs
- DataTableMapping.cs
- RestHandlerFactory.cs
- BitmapEffect.cs
- ClaimTypeElement.cs
- DeobfuscatingStream.cs
- CollectionCodeDomSerializer.cs
- XmlSchemaFacet.cs
- ActivityValidator.cs
- ConfigXmlCDataSection.cs
- DataGridViewCellFormattingEventArgs.cs
- UpDownEvent.cs
- EraserBehavior.cs
- Regex.cs
- StringValueSerializer.cs
- WebPartAuthorizationEventArgs.cs