Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / ndp / fx / src / DataEntity / System / Data / Query / ResultAssembly / BitVec.cs / 3 / BitVec.cs
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....], [....]
//---------------------------------------------------------------------
namespace System.Data.Query.ResultAssembly {
using System.Diagnostics;
using System.Text;
///
/// BitVector helper class; used to keep track of the used columns
/// in the result assembly.
///
///
/// BitVec can be a struct because it contains a readonly reference to an int[].
/// This code is a copy of System.Collections.BitArray so that we can have an efficient implementation of Minus.
///
internal struct BitVec {
private readonly int[] m_array;
private readonly int m_length;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal BitVec(int length)
{
Debug.Assert(0 < length, "zero length");
m_array = new int[(length + 31) / 32];
m_length = length;
}
internal int Count {
get { return m_length; }
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal void Set(int index)
{
Debug.Assert(unchecked((uint)index < (uint)m_length), "index out of range");
m_array[index / 32] |= (1 << (index % 32));
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal void ClearAll() {
for (int i = 0; i < m_array.Length; i++) {
m_array[i] = 0;
}
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal bool IsEmpty() {
for (int i = 0; i < m_array.Length; i++) {
if (0 != m_array[i]) {
return false;
}
}
return true;
}
internal bool IsSet(int index) {
Debug.Assert(unchecked((uint)index < (uint)m_length), "index out of range");
return (m_array[index / 32] & (1 << (index % 32))) != 0;
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal void Or(BitVec value) {
Debug.Assert(m_length == value.m_length, "unequal sized bitvec");
for (int i = 0; i < m_array.Length; i++) {
m_array[i] |= value.m_array[i];
}
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal void Minus(BitVec value) {
Debug.Assert(m_length == value.m_length, "unequal sized bitvec");
for (int i = 0; i < m_array.Length; i++) {
m_array[i] &= ~value.m_array[i];
}
}
public override string ToString() {
StringBuilder sb = new StringBuilder(3 * Count);
string separator = string.Empty;
for (int i = 0; i < Count; i++) {
if (IsSet(i)) {
sb.Append(separator);
sb.Append(i);
separator = ",";
}
}
return sb.ToString();
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....], [....]
//---------------------------------------------------------------------
namespace System.Data.Query.ResultAssembly {
using System.Diagnostics;
using System.Text;
///
/// BitVector helper class; used to keep track of the used columns
/// in the result assembly.
///
///
/// BitVec can be a struct because it contains a readonly reference to an int[].
/// This code is a copy of System.Collections.BitArray so that we can have an efficient implementation of Minus.
///
internal struct BitVec {
private readonly int[] m_array;
private readonly int m_length;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal BitVec(int length)
{
Debug.Assert(0 < length, "zero length");
m_array = new int[(length + 31) / 32];
m_length = length;
}
internal int Count {
get { return m_length; }
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal void Set(int index)
{
Debug.Assert(unchecked((uint)index < (uint)m_length), "index out of range");
m_array[index / 32] |= (1 << (index % 32));
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal void ClearAll() {
for (int i = 0; i < m_array.Length; i++) {
m_array[i] = 0;
}
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal bool IsEmpty() {
for (int i = 0; i < m_array.Length; i++) {
if (0 != m_array[i]) {
return false;
}
}
return true;
}
internal bool IsSet(int index) {
Debug.Assert(unchecked((uint)index < (uint)m_length), "index out of range");
return (m_array[index / 32] & (1 << (index % 32))) != 0;
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal void Or(BitVec value) {
Debug.Assert(m_length == value.m_length, "unequal sized bitvec");
for (int i = 0; i < m_array.Length; i++) {
m_array[i] |= value.m_array[i];
}
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal void Minus(BitVec value) {
Debug.Assert(m_length == value.m_length, "unequal sized bitvec");
for (int i = 0; i < m_array.Length; i++) {
m_array[i] &= ~value.m_array[i];
}
}
public override string ToString() {
StringBuilder sb = new StringBuilder(3 * Count);
string separator = string.Empty;
for (int i = 0; i < Count; i++) {
if (IsSet(i)) {
sb.Append(separator);
sb.Append(i);
separator = ",";
}
}
return sb.ToString();
}
}
}
// 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
- BaseTemplateCodeDomTreeGenerator.cs
- CounterSampleCalculator.cs
- BaseAddressPrefixFilterElementCollection.cs
- TextFindEngine.cs
- Int32RectConverter.cs
- RegularExpressionValidator.cs
- KeyGestureValueSerializer.cs
- DictionaryKeyPropertyAttribute.cs
- System.Data_BID.cs
- SchemaObjectWriter.cs
- Rule.cs
- CodeStatementCollection.cs
- MailMessageEventArgs.cs
- LateBoundBitmapDecoder.cs
- XmlLanguage.cs
- ModelChangedEventArgsImpl.cs
- ipaddressinformationcollection.cs
- BridgeDataRecord.cs
- ViewValidator.cs
- DispatcherFrame.cs
- Window.cs
- SqlDataReaderSmi.cs
- MLangCodePageEncoding.cs
- DesignDataSource.cs
- BufferAllocator.cs
- KnownTypesProvider.cs
- XmlNamespaceManager.cs
- TextServicesCompartmentEventSink.cs
- TypeBuilderInstantiation.cs
- PersonalizationEntry.cs
- Internal.cs
- FlowLayout.cs
- HTMLTagNameToTypeMapper.cs
- DoubleKeyFrameCollection.cs
- TextBox.cs
- BaseTemplateBuildProvider.cs
- DispatcherSynchronizationContext.cs
- ProxyGenerationError.cs
- DrawListViewItemEventArgs.cs
- TdsParserSessionPool.cs
- Scripts.cs
- X509Utils.cs
- XNodeNavigator.cs
- QilTargetType.cs
- Int32CollectionValueSerializer.cs
- WeakReferenceList.cs
- ResourceDisplayNameAttribute.cs
- ToolStripOverflow.cs
- DocumentPageViewAutomationPeer.cs
- ItemMap.cs
- WorkflowDesigner.cs
- PackagingUtilities.cs
- Thumb.cs
- IsolatedStorageFilePermission.cs
- AppDomainEvidenceFactory.cs
- NamespaceExpr.cs
- DigestComparer.cs
- XmlSchemaObjectCollection.cs
- TraceHandler.cs
- Journal.cs
- FolderBrowserDialog.cs
- WebPartConnectionsConfigureVerb.cs
- LongValidatorAttribute.cs
- ReadOnlyDictionary.cs
- oledbmetadatacolumnnames.cs
- AuthenticateEventArgs.cs
- ScrollableControl.cs
- CheckedPointers.cs
- OdbcEnvironment.cs
- QilBinary.cs
- FileChangeNotifier.cs
- SessionParameter.cs
- SmiEventSink_DeferedProcessing.cs
- ClosableStream.cs
- NamespaceEmitter.cs
- Connector.cs
- Stylesheet.cs
- DetailsViewUpdateEventArgs.cs
- PropertyToken.cs
- CodeExporter.cs
- WebDisplayNameAttribute.cs
- HttpProxyTransportBindingElement.cs
- EndPoint.cs
- ListViewItemEventArgs.cs
- ThaiBuddhistCalendar.cs
- EntitySqlQueryCacheKey.cs
- PreservationFileReader.cs
- ResXResourceWriter.cs
- SettingsContext.cs
- CodeTypeDeclarationCollection.cs
- SafeFileMappingHandle.cs
- SmtpSection.cs
- RouteValueExpressionBuilder.cs
- WindowsRegion.cs
- NativeMethods.cs
- FieldTemplateUserControl.cs
- XmlSchemaGroup.cs
- FacetEnabledSchemaElement.cs
- SequentialActivityDesigner.cs
- WizardSideBarListControlItem.cs