📄 valueweightpaircollection.cs
字号:
using System;
using System.Collections;
namespace Org.InteliIM.HuffCode
{
/// <summary>
/// A collection that stores <see cref='HuffTree'/> objects.
/// </summary>
[Serializable()]
public class ValueWeightPairCollection : CollectionBase
{
/// <summary>
/// Initializes a new instance of <see cref='ValueWeightPairCollection'/>.
/// </summary>
public ValueWeightPairCollection()
{
}
/// <summary>
/// Initializes a new instance of <see cref='ValueWeightPairCollection'/> based on another <see cref='ValueWeightPairCollection'/>.
/// </summary>
/// <param name='val'>
/// A <see cref='ValueWeightPairCollection'/> from which the contents are copied
/// </param>
public ValueWeightPairCollection(ValueWeightPairCollection val)
{
this.AddRange(val);
}
/// <summary>
/// Initializes a new instance of <see cref='ValueWeightPairCollection'/> containing any array of <see cref='HuffTree'/> objects.
/// </summary>
/// <param name='val'>
/// A array of <see cref='HuffTree'/> objects with which to intialize the collection
/// </param>
public ValueWeightPairCollection(ValueWeightPair[] val)
{
this.AddRange(val);
}
/// <summary>
/// Represents the entry at the specified index of the <see cref='HuffTree'/>.
/// </summary>
/// <param name='index'>The zero-based index of the entry to locate in the collection.</param>
/// <value>The entry at the specified index of the collection.</value>
/// <exception cref='ArgumentOutOfRangeException'><paramref name='index'/> is outside the valid range of indexes for the collection.</exception>
public ValueWeightPair this[int index]
{
get { return ((ValueWeightPair) (List[index])); }
set { List[index] = value; }
}
/// <summary>
/// Adds a <see cref='HuffTree'/> with the specified value to the
/// <see cref='ValueWeightPairCollection'/>.
/// </summary>
/// <param name='val'>The <see cref='HuffTree'/> to add.</param>
/// <returns>The index at which the new element was inserted.</returns>
/// <seealso cref='ValueWeightPairCollection.AddRange'/>
public int Add(ValueWeightPair val)
{
return List.Add(val);
}
/// <summary>
/// Copies the elements of an array to the end of the <see cref='ValueWeightPairCollection'/>.
/// </summary>
/// <param name='val'>
/// An array of type <see cref='HuffTree'/> containing the objects to add to the collection.
/// </param>
/// <seealso cref='ValueWeightPairCollection.Add'/>
public void AddRange(ValueWeightPair[] val)
{
for (int i = 0; i < val.Length; i++)
{
this.Add(val[i]);
}
}
/// <summary>
/// Adds the contents of another <see cref='ValueWeightPairCollection'/> to the end of the collection.
/// </summary>
/// <param name='val'>
/// A <see cref='ValueWeightPairCollection'/> containing the objects to add to the collection.
/// </param>
/// <seealso cref='ValueWeightPairCollection.Add'/>
public void AddRange(ValueWeightPairCollection val)
{
for (int i = 0; i < val.Count; i++)
{
this.Add(val[i]);
}
}
/// <summary>
/// Gets a value indicating whether the
/// <see cref='ValueWeightPairCollection'/> contains the specified <see cref='HuffTree'/>.
/// </summary>
/// <param name='val'>The <see cref='HuffTree'/> to locate.</param>
/// <returns>
/// <see langword='true'/> if the <see cref='HuffTree'/> is contained in the collection;
/// otherwise, <see langword='false'/>.
/// </returns>
/// <seealso cref='ValueWeightPairCollection.IndexOf'/>
public bool Contains(ValueWeightPair val)
{
return List.Contains(val);
}
/// <summary>
/// Copies the <see cref='ValueWeightPairCollection'/> values to a one-dimensional <see cref='Array'/> instance at the
/// specified index.
/// </summary>
/// <param name='array'>The one-dimensional <see cref='Array'/> that is the destination of the values copied from <see cref='ValueWeightPairCollection'/>.</param>
/// <param name='index'>The index in <paramref name='array'/> where copying begins.</param>
/// <exception cref='ArgumentException'>
/// <para><paramref name='array'/> is multidimensional.</para>
/// <para>-or-</para>
/// <para>The number of elements in the <see cref='ValueWeightPairCollection'/> is greater than
/// the available space between <paramref name='arrayIndex'/> and the end of
/// <paramref name='array'/>.</para>
/// </exception>
/// <exception cref='ArgumentNullException'><paramref name='array'/> is <see langword='null'/>. </exception>
/// <exception cref='ArgumentOutOfRangeException'><paramref name='arrayIndex'/> is less than <paramref name='array'/>'s lowbound. </exception>
/// <seealso cref='Array'/>
public void CopyTo(ValueWeightPair[] array, int index)
{
List.CopyTo(array, index);
}
/// <summary>
/// Returns the index of a <see cref='HuffTree'/> in
/// the <see cref='ValueWeightPairCollection'/>.
/// </summary>
/// <param name='val'>The <see cref='HuffTree'/> to locate.</param>
/// <returns>
/// The index of the <see cref='HuffTree'/> of <paramref name='val'/> in the
/// <see cref='ValueWeightPairCollection'/>, if found; otherwise, -1.
/// </returns>
/// <seealso cref='ValueWeightPairCollection.Contains'/>
public int IndexOf(ValueWeightPair val)
{
return List.IndexOf(val);
}
/// <summary>
/// Inserts a <see cref='HuffTree'/> into the <see cref='ValueWeightPairCollection'/> at the specified index.
/// </summary>
/// <param name='index'>The zero-based index where <paramref name='val'/> should be inserted.</param>
/// <param name='val'>The <see cref='HuffTree'/> to insert.</param>
/// <seealso cref='ValueWeightPairCollection.Add'/>
public void Insert(int index, ValueWeightPair val)
{
List.Insert(index, val);
}
/// <summary>
/// Returns an enumerator that can iterate through the <see cref='ValueWeightPairCollection'/>.
/// </summary>
/// <seealso cref='IEnumerator'/>
new public ValueWeightPairEnumerator GetEnumerator()
{
return new ValueWeightPairEnumerator(this);
}
/// <summary>
/// Removes a specific <see cref='HuffTree'/> from the <see cref='ValueWeightPairCollection'/>.
/// </summary>
/// <param name='val'>The <see cref='HuffTree'/> to remove from the <see cref='ValueWeightPairCollection'/>.</param>
/// <exception cref='ArgumentException'><paramref name='val'/> is not found in the Collection.</exception>
public void Remove(ValueWeightPair val)
{
List.Remove(val);
}
/// <summary>
/// Enumerator that can iterate through a ValueWeightPairCollection.
/// </summary>
/// <seealso cref='IEnumerator'/>
/// <seealso cref='ValueWeightPairCollection'/>
/// <seealso cref='HuffTree'/>
public class ValueWeightPairEnumerator : IEnumerator
{
private IEnumerator baseEnumerator;
private IEnumerable temp;
/// <summary>
/// Initializes a new instance of <see cref='ValueWeightPairEnumerator'/>.
/// </summary>
public ValueWeightPairEnumerator(ValueWeightPairCollection mappings)
{
this.temp = ((IEnumerable) (mappings));
this.baseEnumerator = temp.GetEnumerator();
}
/// <summary>
/// Gets the current <see cref='HuffTree'/> in the <seealso cref='ValueWeightPairCollection'/>.
/// </summary>
public ValueWeightPair Current
{
get { return ((ValueWeightPair) (baseEnumerator.Current)); }
}
object IEnumerator.Current
{
get { return baseEnumerator.Current; }
}
/// <summary>
/// Advances the enumerator to the next <see cref='HuffTree'/> of the <see cref='ValueWeightPairCollection'/>.
/// </summary>
public bool MoveNext()
{
return baseEnumerator.MoveNext();
}
/// <summary>
/// Sets the enumerator to its initial position, which is before the first element in the <see cref='ValueWeightPairCollection'/>.
/// </summary>
public void Reset()
{
baseEnumerator.Reset();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -