Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / WinForms / Managed / System / WinForms / DataGridViewIntLinkedList.cs / 1305376 / DataGridViewIntLinkedList.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Windows.Forms
{
using System;
using System.Diagnostics;
using System.Collections;
using System.Windows.Forms;
using System.ComponentModel;
///
///
/// Represents a linked list of integers
///
internal class DataGridViewIntLinkedList : IEnumerable
{
private DataGridViewIntLinkedListElement lastAccessedElement;
private DataGridViewIntLinkedListElement headElement;
private int count, lastAccessedIndex;
///
IEnumerator IEnumerable.GetEnumerator()
{
return new DataGridViewIntLinkedListEnumerator(this.headElement);
}
///
public DataGridViewIntLinkedList()
{
lastAccessedIndex = -1;
}
///
public DataGridViewIntLinkedList(DataGridViewIntLinkedList source)
{
Debug.Assert(source != null);
int elements = source.Count;
for (int element = 0; element < elements; element++)
{
Add(source[element]);
}
}
///
public int this[int index]
{
get
{
Debug.Assert(index >= 0);
Debug.Assert(index < this.count);
if (this.lastAccessedIndex == -1 || index < this.lastAccessedIndex)
{
DataGridViewIntLinkedListElement tmp = this.headElement;
int tmpIndex = index;
while (tmpIndex > 0)
{
tmp = tmp.Next;
tmpIndex--;
}
this.lastAccessedElement = tmp;
this.lastAccessedIndex = index;
return tmp.Int;
}
else
{
while (this.lastAccessedIndex < index)
{
this.lastAccessedElement = this.lastAccessedElement.Next;
this.lastAccessedIndex++;
}
return this.lastAccessedElement.Int;
}
}
set
{
Debug.Assert(index >= 0);
if (index != this.lastAccessedIndex)
{
int currentInt = this[index];
Debug.Assert(index == this.lastAccessedIndex);
}
this.lastAccessedElement.Int = value;
}
}
///
public int Count
{
get
{
return this.count;
}
}
///
public int HeadInt
{
get
{
Debug.Assert(this.headElement != null);
return this.headElement.Int;
}
}
///
public void Add(int integer)
{
DataGridViewIntLinkedListElement newHead = new DataGridViewIntLinkedListElement(integer);
if (this.headElement != null)
{
newHead.Next = this.headElement;
}
this.headElement = newHead;
this.count++;
this.lastAccessedElement = null;
this.lastAccessedIndex = -1;
}
///
public void Clear()
{
this.lastAccessedElement = null;
this.lastAccessedIndex = -1;
this.headElement = null;
this.count = 0;
}
///
public bool Contains(int integer)
{
int index = 0;
DataGridViewIntLinkedListElement tmp = this.headElement;
while (tmp != null)
{
if (tmp.Int == integer)
{
this.lastAccessedElement = tmp;
this.lastAccessedIndex = index;
return true;
}
tmp = tmp.Next;
index++;
}
return false;
}
///
public int IndexOf(int integer)
{
if (Contains(integer))
{
return this.lastAccessedIndex;
}
else
{
return -1;
}
}
///
public bool Remove(int integer)
{
DataGridViewIntLinkedListElement tmp1 = null, tmp2 = this.headElement;
while (tmp2 != null)
{
if (tmp2.Int == integer)
{
break;
}
tmp1 = tmp2;
tmp2 = tmp2.Next;
}
if (tmp2.Int == integer)
{
DataGridViewIntLinkedListElement tmp3 = tmp2.Next;
if (tmp1 == null)
{
this.headElement = tmp3;
}
else
{
tmp1.Next = tmp3;
}
this.count--;
this.lastAccessedElement = null;
this.lastAccessedIndex = -1;
return true;
}
return false;
}
///
public void RemoveAt(int index)
{
DataGridViewIntLinkedListElement tmp1 = null, tmp2 = this.headElement;
while (index > 0)
{
tmp1 = tmp2;
tmp2 = tmp2.Next;
index--;
}
DataGridViewIntLinkedListElement tmp3 = tmp2.Next;
if (tmp1 == null)
{
this.headElement = tmp3;
}
else
{
tmp1.Next = tmp3;
}
this.count--;
this.lastAccessedElement = null;
this.lastAccessedIndex = -1;
}
}
///
///
/// Represents an emunerator of elements in a linked list.
///
internal class DataGridViewIntLinkedListEnumerator : IEnumerator
{
private DataGridViewIntLinkedListElement headElement;
private DataGridViewIntLinkedListElement current;
private bool reset;
///
public DataGridViewIntLinkedListEnumerator(DataGridViewIntLinkedListElement headElement)
{
this.headElement = headElement;
this.reset = true;
}
///
object IEnumerator.Current
{
get
{
Debug.Assert(this.current != null); // Since this is for internal use only.
return this.current.Int;
}
}
///
bool IEnumerator.MoveNext()
{
if (this.reset)
{
Debug.Assert(this.current == null);
this.current = this.headElement;
this.reset = false;
}
else
{
Debug.Assert(this.current != null); // Since this is for internal use only.
this.current = this.current.Next;
}
return (this.current != null);
}
///
void IEnumerator.Reset()
{
this.reset = true;
this.current = null;
}
}
///
///
/// Represents an element in a linked list.
///
internal class DataGridViewIntLinkedListElement
{
private int integer;
private DataGridViewIntLinkedListElement next;
///
public DataGridViewIntLinkedListElement(int integer)
{
this.integer = integer;
}
///
public int Int
{
get
{
return this.integer;
}
set
{
this.integer = value;
}
}
///
public DataGridViewIntLinkedListElement Next
{
get
{
return this.next;
}
set
{
this.next = value;
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Windows.Forms
{
using System;
using System.Diagnostics;
using System.Collections;
using System.Windows.Forms;
using System.ComponentModel;
///
///
/// Represents a linked list of integers
///
internal class DataGridViewIntLinkedList : IEnumerable
{
private DataGridViewIntLinkedListElement lastAccessedElement;
private DataGridViewIntLinkedListElement headElement;
private int count, lastAccessedIndex;
///
IEnumerator IEnumerable.GetEnumerator()
{
return new DataGridViewIntLinkedListEnumerator(this.headElement);
}
///
public DataGridViewIntLinkedList()
{
lastAccessedIndex = -1;
}
///
public DataGridViewIntLinkedList(DataGridViewIntLinkedList source)
{
Debug.Assert(source != null);
int elements = source.Count;
for (int element = 0; element < elements; element++)
{
Add(source[element]);
}
}
///
public int this[int index]
{
get
{
Debug.Assert(index >= 0);
Debug.Assert(index < this.count);
if (this.lastAccessedIndex == -1 || index < this.lastAccessedIndex)
{
DataGridViewIntLinkedListElement tmp = this.headElement;
int tmpIndex = index;
while (tmpIndex > 0)
{
tmp = tmp.Next;
tmpIndex--;
}
this.lastAccessedElement = tmp;
this.lastAccessedIndex = index;
return tmp.Int;
}
else
{
while (this.lastAccessedIndex < index)
{
this.lastAccessedElement = this.lastAccessedElement.Next;
this.lastAccessedIndex++;
}
return this.lastAccessedElement.Int;
}
}
set
{
Debug.Assert(index >= 0);
if (index != this.lastAccessedIndex)
{
int currentInt = this[index];
Debug.Assert(index == this.lastAccessedIndex);
}
this.lastAccessedElement.Int = value;
}
}
///
public int Count
{
get
{
return this.count;
}
}
///
public int HeadInt
{
get
{
Debug.Assert(this.headElement != null);
return this.headElement.Int;
}
}
///
public void Add(int integer)
{
DataGridViewIntLinkedListElement newHead = new DataGridViewIntLinkedListElement(integer);
if (this.headElement != null)
{
newHead.Next = this.headElement;
}
this.headElement = newHead;
this.count++;
this.lastAccessedElement = null;
this.lastAccessedIndex = -1;
}
///
public void Clear()
{
this.lastAccessedElement = null;
this.lastAccessedIndex = -1;
this.headElement = null;
this.count = 0;
}
///
public bool Contains(int integer)
{
int index = 0;
DataGridViewIntLinkedListElement tmp = this.headElement;
while (tmp != null)
{
if (tmp.Int == integer)
{
this.lastAccessedElement = tmp;
this.lastAccessedIndex = index;
return true;
}
tmp = tmp.Next;
index++;
}
return false;
}
///
public int IndexOf(int integer)
{
if (Contains(integer))
{
return this.lastAccessedIndex;
}
else
{
return -1;
}
}
///
public bool Remove(int integer)
{
DataGridViewIntLinkedListElement tmp1 = null, tmp2 = this.headElement;
while (tmp2 != null)
{
if (tmp2.Int == integer)
{
break;
}
tmp1 = tmp2;
tmp2 = tmp2.Next;
}
if (tmp2.Int == integer)
{
DataGridViewIntLinkedListElement tmp3 = tmp2.Next;
if (tmp1 == null)
{
this.headElement = tmp3;
}
else
{
tmp1.Next = tmp3;
}
this.count--;
this.lastAccessedElement = null;
this.lastAccessedIndex = -1;
return true;
}
return false;
}
///
public void RemoveAt(int index)
{
DataGridViewIntLinkedListElement tmp1 = null, tmp2 = this.headElement;
while (index > 0)
{
tmp1 = tmp2;
tmp2 = tmp2.Next;
index--;
}
DataGridViewIntLinkedListElement tmp3 = tmp2.Next;
if (tmp1 == null)
{
this.headElement = tmp3;
}
else
{
tmp1.Next = tmp3;
}
this.count--;
this.lastAccessedElement = null;
this.lastAccessedIndex = -1;
}
}
///
///
/// Represents an emunerator of elements in a linked list.
///
internal class DataGridViewIntLinkedListEnumerator : IEnumerator
{
private DataGridViewIntLinkedListElement headElement;
private DataGridViewIntLinkedListElement current;
private bool reset;
///
public DataGridViewIntLinkedListEnumerator(DataGridViewIntLinkedListElement headElement)
{
this.headElement = headElement;
this.reset = true;
}
///
object IEnumerator.Current
{
get
{
Debug.Assert(this.current != null); // Since this is for internal use only.
return this.current.Int;
}
}
///
bool IEnumerator.MoveNext()
{
if (this.reset)
{
Debug.Assert(this.current == null);
this.current = this.headElement;
this.reset = false;
}
else
{
Debug.Assert(this.current != null); // Since this is for internal use only.
this.current = this.current.Next;
}
return (this.current != null);
}
///
void IEnumerator.Reset()
{
this.reset = true;
this.current = null;
}
}
///
///
/// Represents an element in a linked list.
///
internal class DataGridViewIntLinkedListElement
{
private int integer;
private DataGridViewIntLinkedListElement next;
///
public DataGridViewIntLinkedListElement(int integer)
{
this.integer = integer;
}
///
public int Int
{
get
{
return this.integer;
}
set
{
this.integer = value;
}
}
///
public DataGridViewIntLinkedListElement Next
{
get
{
return this.next;
}
set
{
this.next = value;
}
}
}
}
// 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
- FontFaceLayoutInfo.cs
- InternalSafeNativeMethods.cs
- ToolStripSplitStackLayout.cs
- TreeNodeBindingDepthConverter.cs
- LineUtil.cs
- SecureStringHasher.cs
- RenderOptions.cs
- BufferModesCollection.cs
- figurelengthconverter.cs
- CodeIdentifiers.cs
- DataBindingHandlerAttribute.cs
- MD5CryptoServiceProvider.cs
- GlobalId.cs
- WindowPatternIdentifiers.cs
- UriParserTemplates.cs
- listitem.cs
- ActiveDocumentEvent.cs
- AuthorizationContext.cs
- MappedMetaModel.cs
- OptimizerPatterns.cs
- PageWrapper.cs
- HttpsHostedTransportConfiguration.cs
- Table.cs
- SqlInternalConnection.cs
- DateTimeStorage.cs
- Parameter.cs
- StylusPlugin.cs
- SqlAggregateChecker.cs
- MobileSysDescriptionAttribute.cs
- RootDesignerSerializerAttribute.cs
- TypeUtil.cs
- NetworkAddressChange.cs
- WebPartRestoreVerb.cs
- InstancePersistence.cs
- SessionKeyExpiredException.cs
- FunctionCommandText.cs
- MultiBindingExpression.cs
- RelationshipFixer.cs
- WasNotInstalledException.cs
- CharacterString.cs
- SHA1Managed.cs
- XmlSchemaSimpleTypeUnion.cs
- SmiMetaDataProperty.cs
- DrawingImage.cs
- Shared.cs
- AssemblyBuilderData.cs
- SqlParameter.cs
- PathTooLongException.cs
- regiisutil.cs
- PeerNameRecord.cs
- MultiAsyncResult.cs
- ObjectItemNoOpAssemblyLoader.cs
- DesignerDataTableBase.cs
- Errors.cs
- DataObjectAttribute.cs
- ValidatorCompatibilityHelper.cs
- NameService.cs
- ValidatedControlConverter.cs
- OleDbInfoMessageEvent.cs
- LocalizabilityAttribute.cs
- ScriptControlManager.cs
- SystemFonts.cs
- ResourceDescriptionAttribute.cs
- HMAC.cs
- PreloadedPackages.cs
- UpdatePanelTrigger.cs
- XmlRawWriter.cs
- WebPartManagerDesigner.cs
- XmlLanguage.cs
- ObjectIDGenerator.cs
- UIElement3D.cs
- XmlTypeMapping.cs
- RemoteTokenFactory.cs
- Underline.cs
- X509RawDataKeyIdentifierClause.cs
- ServiceManager.cs
- Thickness.cs
- PropertyFilter.cs
- ExecutionContext.cs
- BindingList.cs
- PopupRootAutomationPeer.cs
- ActiveXHelper.cs
- BypassElement.cs
- HttpFileCollection.cs
- Quaternion.cs
- StrongNameKeyPair.cs
- ColumnMapTranslator.cs
- SqlCommandBuilder.cs
- AsyncPostBackErrorEventArgs.cs
- PrintingPermission.cs
- ResourceProviderFactory.cs
- DmlSqlGenerator.cs
- ListViewTableRow.cs
- KoreanCalendar.cs
- SolidBrush.cs
- ParameterToken.cs
- VectorCollectionConverter.cs
- ListViewCommandEventArgs.cs
- TextFormatterHost.cs
- CustomAttribute.cs