Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataEntity / System / Data / Common / Utils / Boolean / DomainConstraint.cs / 1305376 / DomainConstraint.cs
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace System.Data.Common.Utils.Boolean
{
///
/// Represents a variable with finite domain, e.g., c in {1, 2, 3}
///
/// Type of domain variables (int in the above example).
/// Type of the identifier (c above -- it need not be int).
internal class DomainVariable
{
private readonly T_Variable _identifier;
private readonly Set _domain;
private readonly int _hashCode;
private readonly IEqualityComparer _identifierComparer;
///
/// Constructs a new domain variable.
///
/// Identifier
/// Domain of variable.
/// Comparer of identifier
internal DomainVariable(T_Variable identifier, Set domain, IEqualityComparer identifierComparer)
{
Debug.Assert(null != identifier && null != domain);
_identifier = identifier;
_domain = domain.AsReadOnly();
_identifierComparer = identifierComparer ?? EqualityComparer.Default;
int domainHashCode = _domain.GetElementsHashCode();
int identifierHashCode = _identifierComparer.GetHashCode(_identifier);
_hashCode = domainHashCode ^ identifierHashCode;
}
internal DomainVariable(T_Variable identifier, Set domain) : this(identifier, domain, null) { }
///
/// Gets the variable.
///
internal T_Variable Identifier { get { return _identifier; } }
///
/// Gets the domain of this variable.
///
internal Set Domain { get { return _domain; } }
public override int GetHashCode()
{
return _hashCode;
}
public override bool Equals(object obj)
{
if (Object.ReferenceEquals(this, obj)) { return true; }
DomainVariable other = obj as DomainVariable;
if (null == other) { return false; }
if (_hashCode != other._hashCode) { return false; }
return (_identifierComparer.Equals(_identifier, other._identifier) && _domain.SetEquals(other._domain));
}
public override string ToString()
{
return StringUtil.FormatInvariant("{0}{{{1}}}",
_identifier.ToString(), _domain);
}
}
///
/// Represents a constraint of the form:
///
/// Var1 in Range
///
/// Type of range elements.
/// Type of the variable.
internal class DomainConstraint
{
private readonly DomainVariable _variable;
private readonly Set _range;
private readonly int _hashCode;
///
/// Constructs a new constraint for the given variable and range.
///
/// Variable in constraint.
/// Range of constraint.
internal DomainConstraint(DomainVariable variable, Set range)
{
Debug.Assert(null != variable && null != range);
_variable = variable;
_range = range.AsReadOnly();
_hashCode = _variable.GetHashCode() ^ _range.GetElementsHashCode();
}
///
/// Constructor supporting a singleton range domain constraint
///
internal DomainConstraint(DomainVariable variable, T_Element element)
: this(variable, new Set(new T_Element[] { element }).MakeReadOnly())
{
}
///
/// Gets the variable for this constraint.
///
internal DomainVariable Variable { get { return _variable; } }
///
/// Get the range for this constraint.
///
internal Set Range { get { return _range; } }
///
/// Inverts this constraint (this iff. !result)
/// !(Var in Range) iff. Var in (Var.Domain - Range)
///
///
internal DomainConstraint InvertDomainConstraint()
{
return new DomainConstraint(_variable,
_variable.Domain.Difference(_range).AsReadOnly());
}
public override bool Equals(object obj)
{
if (Object.ReferenceEquals(this, obj)) { return true; }
DomainConstraint other = obj as DomainConstraint;
if (null == other) { return false; }
if (_hashCode != other._hashCode) { return false; }
return (_range.SetEquals(other._range) && _variable.Equals(other._variable));
}
public override int GetHashCode()
{
return _hashCode;
}
public override string ToString()
{
return StringUtil.FormatInvariant("{0} in [{1}]",
_variable, _range);
}
}
}
// 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.Linq;
using System.Text;
using System.Diagnostics;
namespace System.Data.Common.Utils.Boolean
{
///
/// Represents a variable with finite domain, e.g., c in {1, 2, 3}
///
/// Type of domain variables (int in the above example).
/// Type of the identifier (c above -- it need not be int).
internal class DomainVariable
{
private readonly T_Variable _identifier;
private readonly Set _domain;
private readonly int _hashCode;
private readonly IEqualityComparer _identifierComparer;
///
/// Constructs a new domain variable.
///
/// Identifier
/// Domain of variable.
/// Comparer of identifier
internal DomainVariable(T_Variable identifier, Set domain, IEqualityComparer identifierComparer)
{
Debug.Assert(null != identifier && null != domain);
_identifier = identifier;
_domain = domain.AsReadOnly();
_identifierComparer = identifierComparer ?? EqualityComparer.Default;
int domainHashCode = _domain.GetElementsHashCode();
int identifierHashCode = _identifierComparer.GetHashCode(_identifier);
_hashCode = domainHashCode ^ identifierHashCode;
}
internal DomainVariable(T_Variable identifier, Set domain) : this(identifier, domain, null) { }
///
/// Gets the variable.
///
internal T_Variable Identifier { get { return _identifier; } }
///
/// Gets the domain of this variable.
///
internal Set Domain { get { return _domain; } }
public override int GetHashCode()
{
return _hashCode;
}
public override bool Equals(object obj)
{
if (Object.ReferenceEquals(this, obj)) { return true; }
DomainVariable other = obj as DomainVariable;
if (null == other) { return false; }
if (_hashCode != other._hashCode) { return false; }
return (_identifierComparer.Equals(_identifier, other._identifier) && _domain.SetEquals(other._domain));
}
public override string ToString()
{
return StringUtil.FormatInvariant("{0}{{{1}}}",
_identifier.ToString(), _domain);
}
}
///
/// Represents a constraint of the form:
///
/// Var1 in Range
///
/// Type of range elements.
/// Type of the variable.
internal class DomainConstraint
{
private readonly DomainVariable _variable;
private readonly Set _range;
private readonly int _hashCode;
///
/// Constructs a new constraint for the given variable and range.
///
/// Variable in constraint.
/// Range of constraint.
internal DomainConstraint(DomainVariable variable, Set range)
{
Debug.Assert(null != variable && null != range);
_variable = variable;
_range = range.AsReadOnly();
_hashCode = _variable.GetHashCode() ^ _range.GetElementsHashCode();
}
///
/// Constructor supporting a singleton range domain constraint
///
internal DomainConstraint(DomainVariable variable, T_Element element)
: this(variable, new Set(new T_Element[] { element }).MakeReadOnly())
{
}
///
/// Gets the variable for this constraint.
///
internal DomainVariable Variable { get { return _variable; } }
///
/// Get the range for this constraint.
///
internal Set Range { get { return _range; } }
///
/// Inverts this constraint (this iff. !result)
/// !(Var in Range) iff. Var in (Var.Domain - Range)
///
///
internal DomainConstraint InvertDomainConstraint()
{
return new DomainConstraint(_variable,
_variable.Domain.Difference(_range).AsReadOnly());
}
public override bool Equals(object obj)
{
if (Object.ReferenceEquals(this, obj)) { return true; }
DomainConstraint other = obj as DomainConstraint;
if (null == other) { return false; }
if (_hashCode != other._hashCode) { return false; }
return (_range.SetEquals(other._range) && _variable.Equals(other._variable));
}
public override int GetHashCode()
{
return _hashCode;
}
public override string ToString()
{
return StringUtil.FormatInvariant("{0} in [{1}]",
_variable, _range);
}
}
}
// 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
- Interlocked.cs
- WebContext.cs
- Animatable.cs
- SapiRecognizer.cs
- XmlTypeMapping.cs
- DispatcherHooks.cs
- TimeoutValidationAttribute.cs
- GregorianCalendar.cs
- BindingNavigator.cs
- OdbcConnectionPoolProviderInfo.cs
- EventSetter.cs
- GetLastErrorDetailsRequest.cs
- PropertyGridView.cs
- IndexingContentUnit.cs
- InternalResources.cs
- EditingCoordinator.cs
- AuthenticationManager.cs
- DecimalConstantAttribute.cs
- XmlWrappingReader.cs
- peernodestatemanager.cs
- TableItemProviderWrapper.cs
- BlockCollection.cs
- WinInetCache.cs
- RightsManagementInformation.cs
- CollectionTypeElement.cs
- ComMethodElement.cs
- StrongNameMembershipCondition.cs
- AnchoredBlock.cs
- QilIterator.cs
- RightsManagementPermission.cs
- ColorAnimationBase.cs
- TabPanel.cs
- DirectionalLight.cs
- SessionPageStateSection.cs
- ImpersonationContext.cs
- BitmapMetadataEnumerator.cs
- SqlDataSourceWizardForm.cs
- SqlGatherProducedAliases.cs
- CharUnicodeInfo.cs
- ProxyManager.cs
- Image.cs
- TypeElementCollection.cs
- UserInitiatedNavigationPermission.cs
- MethodBody.cs
- FaultException.cs
- VectorConverter.cs
- RegisteredDisposeScript.cs
- XamlHostingConfiguration.cs
- AddInToken.cs
- EventLogEntryCollection.cs
- AssociationSetEnd.cs
- CodeFieldReferenceExpression.cs
- XmlSchemaComplexContent.cs
- ScrollContentPresenter.cs
- MultipleViewPattern.cs
- InvokePatternIdentifiers.cs
- EntityKey.cs
- WebControl.cs
- Viewport2DVisual3D.cs
- IPHostEntry.cs
- ExtendedProperty.cs
- SecurityTokenAuthenticator.cs
- RequestCacheValidator.cs
- DictionaryCustomTypeDescriptor.cs
- Contracts.cs
- DesignOnlyAttribute.cs
- TextPenaltyModule.cs
- XmlTypeMapping.cs
- PauseStoryboard.cs
- DynamicEntity.cs
- Metafile.cs
- SchemaImporterExtensionsSection.cs
- ArglessEventHandlerProxy.cs
- XPathEmptyIterator.cs
- SqlCacheDependency.cs
- UIElementHelper.cs
- PageCodeDomTreeGenerator.cs
- ReadOnlyHierarchicalDataSourceView.cs
- XmlDataSourceView.cs
- ConnectionProviderAttribute.cs
- FixedSOMPageConstructor.cs
- Model3D.cs
- Regex.cs
- SessionEndedEventArgs.cs
- ToolboxComponentsCreatingEventArgs.cs
- InheritanceAttribute.cs
- ScaleTransform.cs
- BindableTemplateBuilder.cs
- ServiceObjectContainer.cs
- TypeDelegator.cs
- Label.cs
- GZipStream.cs
- WebPartConnectionsConnectVerb.cs
- ListViewSortEventArgs.cs
- EventProxy.cs
- MessageQueuePermissionEntry.cs
- DataGridColumnDropSeparator.cs
- HttpResponse.cs
- KerberosTicketHashIdentifierClause.cs
- ScriptingScriptResourceHandlerSection.cs