[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnetlib/Generics ICapacity.cs,NONE,1.1 Array
From: |
Rhys Weatherley <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnetlib/Generics ICapacity.cs,NONE,1.1 ArrayList.cs,1.7,1.8 ArrayQueue.cs,1.6,1.7 ArrayStack.cs,1.6,1.7 Generics.html,1.1,1.2 Generics.txt,1.4,1.5 |
Date: |
Mon, 24 Feb 2003 23:45:20 -0500 |
Update of /cvsroot/dotgnu-pnet/pnetlib/Generics
In directory subversions:/tmp/cvs-serv4725/Generics
Modified Files:
ArrayList.cs ArrayQueue.cs ArrayStack.cs Generics.html
Generics.txt
Added Files:
ICapacity.cs
Log Message:
Remove utility routines from ArrayList; add the ICapacity interface.
--- NEW FILE ---
/*
* ICapacity.cs - Get or set the capacity of a collection.
*
* Copyright (c) 2003 Southern Storm Software, Pty Ltd
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Generics
{
using System;
public interface ICapacity
{
int Capacity { get; set; }
}; // interface ICapacity
}; // namespace Generics
Index: ArrayList.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Generics/ArrayList.cs,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -r1.7 -r1.8
*** ArrayList.cs 25 Feb 2003 01:43:47 -0000 1.7
--- ArrayList.cs 25 Feb 2003 04:45:17 -0000 1.8
***************
*** 28,32 ****
using System;
! public class ArrayList<T> : ICollection<T>, IList<T>, ICloneable
{
// Internal state.
--- 28,32 ----
using System;
! public sealed class ArrayList<T> : IList<T>, ICapacity, ICloneable
{
// Internal state.
***************
*** 51,72 ****
}
- // Construct an array list from the contents of a collection.
- public ArrayList(ICollection<T> c)
- {
- IIterator<T> iterator;
- int index;
- if(c == null)
- {
- throw new ArgumentNullException("c");
- }
- count = c.Count;
- store = new T [count];
- iterator = c.GetIterator();
- for(index = 0; iterator.MoveNext(); ++index)
- {
- store[index] = iterator.Current;
- }
- }
-
// Reallocate the array to accomodate "n" new entries at "index".
// This leaves "count" unchanged.
--- 51,54 ----
***************
*** 120,124 ****
// Implement the IList<T> interface.
! public virtual int Add(T value)
{
if(count >= store.Length)
--- 102,106 ----
// Implement the IList<T> interface.
! public int Add(T value)
{
if(count >= store.Length)
***************
*** 129,138 ****
return count++;
}
! public virtual void Clear()
{
Array.Clear(store, 0, count);
count = 0;
}
! public virtual bool Contains(T item)
{
int index;
--- 111,120 ----
return count++;
}
! public void Clear()
{
Array.Clear(store, 0, count);
count = 0;
}
! public bool Contains(T item)
{
int index;
***************
*** 174,182 ****
}
}
! public virtual int IndexOf(T value)
{
return IndexOf(value, 0, Count);
}
! public virtual void Insert(int index, T value)
{
if(index < 0 || index > count)
--- 156,168 ----
}
}
! public IListIterator<T> GetIterator()
! {
! return new ArrayListIterator<T>(this);
! }
! public int IndexOf(T value)
{
return IndexOf(value, 0, Count);
}
! public void Insert(int index, T value)
{
if(index < 0 || index > count)
***************
*** 189,193 ****
++count;
}
! public virtual void Remove(T value)
{
int index = Array.IndexOf(store, T, 0, count);
--- 175,179 ----
++count;
}
! public void Remove(T value)
{
int index = Array.IndexOf(store, T, 0, count);
***************
*** 197,201 ****
}
}
! public virtual void RemoveAt(int index)
{
if(index < 0 || index > count)
--- 183,187 ----
}
}
! public void RemoveAt(int index)
{
if(index < 0 || index > count)
***************
*** 206,210 ****
Delete(1, index);
}
! public virtual bool IsRandomAccess
{
get
--- 192,196 ----
Delete(1, index);
}
! public bool IsRandomAccess
{
get
***************
*** 213,217 ****
}
}
! public virtual T this[int index]
{
get
--- 199,203 ----
}
}
! public T this[int index]
{
get
***************
*** 235,391 ****
}
- // Add the contents of a collection as a range.
- public virtual void AddRange(ICollection<T> c)
- {
- int cCount;
- IIterator<T> iterator;
- if(c == null)
- {
- throw new ArgumentNullException("c");
- }
- cCount = c.Count;
- if((count + cCount) > store.Length)
- {
- Realloc(cCount, count);
- }
- iterator = c.GetIterator();
- while(iterator.MoveNext())
- {
- store[count++] = iterator.Current;
- }
- }
-
- // Insert the contents of a collection as a range.
- public virtual void InsertRange(int index, ICollection<T> c)
- {
- int cCount;
- IIterator<T> iterator;
- if(c == null)
- {
- throw new ArgumentNullException("c");
- }
- if(index < 0 || index > count)
- {
- throw new ArgumentOutOfRangeException
- ("index",
S._("ArgRange_Array"));
- }
- cCount = c.Count;
- Realloc(cCount, index);
- iterator = c.GetIterator();
- while(enumerator.MoveNext())
- {
- store[index++] = iterator.Current;
- }
- count += cCount;
- }
-
- // Remove a range of elements from an array list.
- public virtual void RemoveRange(int index, int count)
- {
- if(index < 0)
- {
- throw new ArgumentOutOfRangeException
- ("index",
S._("ArgRange_Array"));
- }
- if(count < 0)
- {
- throw new ArgumentOutOfRangeException
- ("count",
S._("ArgRange_Array"));
- }
- if((this.count - index) < count)
- {
- throw new
ArgumentException(S._("Arg_InvalidArrayRange"));
- }
- Delete(count, index);
- }
-
- // Perform a binary search on an array list.
- public virtual int BinarySearch(T value)
- {
- return BinarySearch(0, Count, value, null);
- }
- public virtual int BinarySearch(T value, IComparer<T> comparer)
- {
- return BinarySearch(0, Count, value, comparer);
- }
- public virtual int BinarySearch(int index, int count,
- T value,
IComparer<T> comparer)
- {
- // Validate the arguments.
- if(index < 0)
- {
- throw new ArgumentOutOfRangeException
- ("index",
S._("ArgRange_Array"));
- }
- if(count < 0)
- {
- throw new ArgumentOutOfRangeException
- ("count",
S._("ArgRange_Array"));
- }
- if((Count - index) < count)
- {
- throw new
ArgumentException(S._("Arg_InvalidArrayRange"));
- }
-
- // Perform the binary search.
- int left, right, middle, cmp;
- Object elem;
- IComparable icmp;
- left = index;
- right = index + count - 1;
- while(left <= right)
- {
- middle = (left + right) / 2;
- elem = this[middle];
- if(elem != null && value != null)
- {
- if(comparer != null)
- {
- cmp =
comparer.Compare(value, elem);
- }
- else if((icmp = (elem as
IComparable)) != null)
- {
- cmp =
-(icmp.CompareTo(value));
- }
- else if((icmp = (value as
IComparable)) != null)
- {
- cmp =
icmp.CompareTo(elem);
- }
- else
- {
- throw new
ArgumentException
-
(_("Arg_SearchCompare"));
- }
- }
- else if(elem != null)
- {
- cmp = -1;
- }
- else if(value != null)
- {
- cmp = 1;
- }
- else
- {
- cmp = 0;
- }
- if(cmp == 0)
- {
- return middle;
- }
- else if(cmp < 0)
- {
- right = middle - 1;
- }
- else
- {
- left = middle + 1;
- }
- }
- return ~left;
- }
-
// Implement the ICloneable interface.
! public virtual Object Clone()
{
ArrayList<T> clone = new ArrayList<T>(count);
--- 221,226 ----
}
// Implement the ICloneable interface.
! public Object Clone()
{
ArrayList<T> clone = new ArrayList<T>(count);
***************
*** 396,404 ****
// Implement the ICollection<T> interface.
! public virtual void CopyTo(T[] array, int arrayIndex)
{
Array.Copy(store, 0, array, arrayIndex, count);
}
! public virtual int Count
{
get
--- 231,239 ----
// Implement the ICollection<T> interface.
! public void CopyTo(T[] array, int arrayIndex)
{
Array.Copy(store, 0, array, arrayIndex, count);
}
! public int Count
{
get
***************
*** 407,411 ****
}
}
! public virtual bool IsFixedSize
{
get
--- 242,246 ----
}
}
! public bool IsFixedSize
{
get
***************
*** 414,418 ****
}
}
! public virtual bool IsReadOnly
{
get
--- 249,253 ----
}
}
! public bool IsReadOnly
{
get
***************
*** 421,425 ****
}
}
! public virtual bool IsSynchronized
{
get
--- 256,260 ----
}
}
! public bool IsSynchronized
{
get
***************
*** 428,432 ****
}
}
! public virtual Object SyncRoot
{
get
--- 263,267 ----
}
}
! public Object SyncRoot
{
get
***************
*** 436,775 ****
}
! // Copy from this array list to another array.
! public virtual void CopyTo(T[] array)
! {
! Array.Copy(store, 0, array, 0, count);
! }
! public virtual void CopyTo(int index, T[] array,
! int arrayIndex, int
count)
! {
! // Validate the parameters.
! if(index < 0)
! {
! throw new ArgumentOutOfRangeException
! ("index",
S._("ArgRange_Array"));
! }
! if(count < 0)
! {
! throw new ArgumentOutOfRangeException
! ("count",
S._("ArgRange_Array"));
! }
! if((Count - index) < count)
! {
! throw new
ArgumentException(S._("Arg_InvalidArrayRange"));
! }
!
! // Perform the copy.
! if(GetType() == typeof(ArrayList<T>))
! {
! // We can use a short-cut because we
know that
! // the list elements are in "store".
! Array.Copy(store, index, array,
arrayIndex, count);
! }
! else
! {
! // The list elements may be elsewhere.
! while(count > 0)
! {
! array.SetValue(this[index],
arrayIndex);
! ++index;
! ++arrayIndex;
! --count;
! }
! }
! }
!
! // Get the index of a value within an array list.
! public virtual int IndexOf(T value, int startIndex)
! {
! int count = Count;
! if(startIndex < 0 || startIndex >= count)
! {
! throw new ArgumentOutOfRangeException
! ("startIndex",
S._("ArgRange_Array"));
! }
! return IndexOf(value, startIndex, count -
startIndex);
! }
! public virtual int IndexOf(T value, int startIndex, int count)
! {
! // Validate the parameters.
! int thisCount = Count;
! if(startIndex < 0 || startIndex >= thisCount)
! {
! throw new ArgumentOutOfRangeException
! ("startIndex",
S._("ArgRange_Array"));
! }
! if(count < 0)
! {
! throw new ArgumentOutOfRangeException
! ("count",
S._("ArgRange_Array"));
! }
! if((thisCount - startIndex) < count)
! {
! throw new
ArgumentException(S._("Arg_InvalidArrayRange"));
! }
!
! // Perform the search.
! Object elem;
! while(count > 0)
! {
! elem = this[startIndex];
! if(elem != null && value != null)
! {
! if(value.Equals(elem))
! {
! return startIndex;
! }
! }
! else if(elem == value && value == null)
! {
! return startIndex;
! }
! ++startIndex;
! --count;
! }
! return -1;
! }
!
! // Get the last index of a value within an array list.
! public virtual int LastIndexOf(T value)
! {
! int count = Count;
! return LastIndexOf(value, count - 1, count);
! }
! public virtual int LastIndexOf(T value, int startIndex)
! {
! int count = Count;
! if(startIndex < 0 || startIndex >= count)
! {
! throw new ArgumentOutOfRangeException
! ("startIndex",
S._("ArgRange_Array"));
! }
! return LastIndexOf(value, startIndex,
startIndex + 1);
! }
! public virtual int LastIndexOf(T value, int startIndex, int count)
! {
! // Validate the parameters.
! if(startIndex < 0 || startIndex >= Count)
! {
! throw new ArgumentOutOfRangeException
! ("startIndex",
S._("ArgRange_Array"));
! }
! if(count < 0)
! {
! throw new ArgumentOutOfRangeException
! ("count",
S._("ArgRange_Array"));
! }
! if(count > (startIndex + 1))
! {
! throw new
ArgumentException(S._("Arg_InvalidArrayRange"));
! }
!
! // Perform the search.
! Object elem;
! while(count > 0)
! {
! elem = this[startIndex];
! if(elem != null && value != null)
! {
! if(value.Equals(elem))
! {
! return startIndex;
! }
! }
! else if(elem == value && value == null)
! {
! return startIndex;
! }
! --startIndex;
! --count;
! }
! return -1;
! }
!
! // Construct an array list with repeated copies of the same element.
! public static ArrayList<T> Repeat<T>(T value, int count)
! {
! ArrayList list;
! int index;
! if(count < 0)
! {
! throw new ArgumentOutOfRangeException
! ("count",
S_("ArgRange_NonNegative"));
! }
! if(count < 16)
! {
! list = new ArrayList<T>();
! }
! else
! {
! list = new ArrayList<T>(count);
! }
! list.Realloc(count, 0);
! for(index = 0; index < count; ++index)
! {
! list.store[index] = value;
! }
! list.count = count;
! return list;
! }
!
! // Reverse the contents of this array list.
! public virtual void Reverse()
! {
! Array.Reverse(store, 0, count);
! }
! public virtual void Reverse(int index, int count)
! {
! if(index < 0)
! {
! throw new ArgumentOutOfRangeException
! ("index",
S._("ArgRange_Array"));
! }
! if(count < 0)
! {
! throw new ArgumentOutOfRangeException
! ("count",
S._("ArgRange_Array"));
! }
! if((this.count - index) < count)
! {
! throw new
ArgumentException(S._("Arg_InvalidArrayRange"));
! }
! Array.Reverse(store, index, count);
! }
!
! // Set a range of array list elements to the members of a collection.
! public virtual void SetRange(int index, ICollection<T> c)
! {
! int count;
! IIterator<T> iterator;
! if(c == null)
! {
! throw new ArgumentNullException("c");
! }
! if(index < 0)
! {
! throw new ArgumentOutOfRangeException
! ("index",
S._("ArgRange_Array"));
! }
! count = c.Count;
! if((this.count - index) < count)
! {
! throw new
ArgumentException(S._("Arg_InvalidArrayRange"));
! }
! iterator = c.GetIterator();
! while(iterator.MoveNext())
! {
! store[index++] = iterator.Current;
! }
! }
!
! // Inner version of "Sort".
! private void InnerSort(int lower, int upper, IComparer<T> comparer)
! {
! // Temporary hack - use a dumb sort until I can
figure
! // out what is wrong with the Quicksort code --
Rhys.
! int i, j, cmp;
! T valuei;
! T valuej;
! for(i = lower; i < upper; ++i)
! {
! for(j = i + 1; j <= upper; ++j)
! {
! valuei = this[i];
! valuej = this[j];
! if(comparer != null)
! {
! cmp =
comparer.Compare(valuei, valuej);
! }
! else
! {
! cmp =
((IComparable)valuei).CompareTo(valuej);
! }
! if(cmp > 0)
! {
! this[i] = valuej;
! this[j] = valuei;
! }
! }
! }
! }
!
! // Sort the contents of this array list.
! public virtual void Sort()
! {
! InnerSort(0, Count - 1, null);
! }
! public virtual void Sort(IComparer<T> comparer)
! {
! InnerSort(0, Count - 1, comparer);
! }
! public virtual void Sort(int index, int count, IComparer<T> comparer)
! {
! if(index < 0)
! {
! throw new ArgumentOutOfRangeException
! ("index",
S._("ArgRange_Array"));
! }
! if(count < 0)
! {
! throw new ArgumentOutOfRangeException
! ("count",
S._("ArgRange_Array"));
! }
! if((Count - index) < count)
! {
! throw new
ArgumentException(S._("Arg_InvalidArrayRange"));
! }
! InnerSort(index, index + count - 1, comparer);
! }
!
! // Create an array that contains the elements of this array list.
! public virtual T[] ToArray()
! {
! int count = Count;
! T[] array = new T[count];
! int index;
! for(index = 0; index < count; ++index)
! {
! array[index] = this[index];
! }
! return array;
! }
! public virtual Array ToArray(Type type)
! {
! int count = Count;
! Array array = Array.CreateInstance(type, count);
! int index;
! for(index = 0; index < count; ++index)
! {
! array.SetValue(this[index], index);
! }
! return array;
! }
!
! // Trim the array list to its actual size.
! public virtual void TrimToSize()
{
! if(count != 0)
! {
! if(count != store.Length)
! {
! T[] newStore = new T[count];
! int index;
! for(index = 0; index < count;
++index)
! {
! newStore[index] =
store[index];
! }
! store = newStore;
! }
! }
! else if(store.Length != 16)
! {
! store = new T[16];
! }
}
! // Get or set the current capacity of the array list.
! public virtual int Capacity
{
get
--- 271,282 ----
}
! // Implement the IIterable<T> interface.
! IIterator<T> IIterable<T>.GetIterator()
{
! return new ArrayListIterator<T>(this);
}
! // Implement the ICapacity interface.
! public int Capacity
{
get
***************
*** 779,785 ****
set
{
! if(value <= 0)
{
! value = 16;
}
if(value < count)
--- 286,293 ----
set
{
! if(value < 0)
{
! throw new
ArgumentOutOfRangeException
! ("value",
S._("ArgRange_NonNegative"));
}
if(value < count)
***************
*** 801,832 ****
}
- // Get an iterator for this array list.
- public virtual IListIterator<T> GetIterator()
- {
- return new ArrayListIterator<T>(this, 0, Count);
- }
- IIterator<T> IIterable<T>.GetIterator()
- {
- return GetIterator();
- }
- public virtual IListIterator<T> GetIterator(int index, int count)
- {
- if(index < 0)
- {
- throw new ArgumentOutOfRangeException
- ("index",
S._("ArgRange_Array"));
- }
- if(count < 0)
- {
- throw new ArgumentOutOfRangeException
- ("count",
S._("ArgRange_Array"));
- }
- if((Count - index) < count)
- {
- throw new
ArgumentException(S._("Arg_InvalidArrayRange"));
- }
- return new ArrayListIterator<T>(this, index,
index + count);
- }
-
// Array list iterator class.
private class ArrayListIterator<T> : IListIterator<T>
--- 309,312 ----
***************
*** 834,839 ****
// Internal state.
private ArrayList<T> list;
- private int start;
- private int finish;
private int position;
private int removed;
--- 314,317 ----
***************
*** 841,850 ****
// Constructor.
! public ArrayListIterator(ArrayList<T> list, int start, int
finish)
{
this.list = list;
! this.start = start;
! this.finish = finish;
! position = start - 1;
removed = -1;
reset = true;
--- 319,326 ----
// Constructor.
! public ArrayListIterator(ArrayList<T> list)
{
this.list = list;
! position = -1;
removed = -1;
reset = true;
***************
*** 857,861 ****
{
// Start at the beginning of
the range.
! position = start;
reset = false;
}
--- 333,337 ----
{
// Start at the beginning of
the range.
! position = 0;
reset = false;
}
***************
*** 870,884 ****
++position;
}
! return (position < finish);
}
public void Reset()
{
reset = true;
! position = start - 1;
removed = -1;
}
public void Remove()
{
! if(position < start || position >=
finish || removed != -1)
{
throw new
InvalidOperationException
--- 346,360 ----
++position;
}
! return (position < list.Count);
}
public void Reset()
{
reset = true;
! position = -1;
removed = -1;
}
public void Remove()
{
! if(position < 0 || position >=
list.Count || removed != -1)
{
throw new
InvalidOperationException
***************
*** 886,890 ****
}
list.RemoveAt(position);
- --finish;
removed = position;
}
--- 362,365 ----
***************
*** 893,897 ****
get
{
! if(position < start || position
>= finish ||
removed != -1)
{
--- 368,372 ----
get
{
! if(position < 0 || position >=
list.Count ||
removed != -1)
{
***************
*** 909,913 ****
{
// Start at the end of the
range.
! position = finish - 1;
reset = false;
}
--- 384,388 ----
{
// Start at the end of the
range.
! position = list.Count - 1;
reset = false;
}
***************
*** 922,926 ****
--position;
}
! return (position >= start);
}
public int Position
--- 397,401 ----
--position;
}
! return (position >= 0);
}
public int Position
***************
*** 928,932 ****
get
{
! if(position < start || position
>= finish ||
removed != -1)
{
--- 403,407 ----
get
{
! if(position < 0 || position >=
list.Count ||
removed != -1)
{
***************
*** 941,945 ****
get
{
! if(position < start || position
>= finish ||
removed != -1)
{
--- 416,420 ----
get
{
! if(position < 0 || position >=
list.Count ||
removed != -1)
{
***************
*** 951,955 ****
set
{
! if(position < start || position
>= finish ||
removed != -1)
{
--- 426,430 ----
set
{
! if(position < 0 || position >=
list.Count ||
removed != -1)
{
Index: ArrayQueue.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Generics/ArrayQueue.cs,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -r1.6 -r1.7
*** ArrayQueue.cs 25 Feb 2003 01:43:47 -0000 1.6
--- ArrayQueue.cs 25 Feb 2003 04:45:18 -0000 1.7
***************
*** 28,37 ****
using System;
! public sealed class ArrayQueue<T> : IQueue<T>, ICloneable
{
// Internal state.
private T[] items;
private int add, remove, size;
- private float growFactor;
// The default capacity for queues.
--- 28,36 ----
using System;
! public sealed class ArrayQueue<T> : IQueue<T>, ICapacity, ICloneable
{
// Internal state.
private T[] items;
private int add, remove, size;
// The default capacity for queues.
***************
*** 45,49 ****
remove = 0;
size = 0;
- growFactor = 2.0f;
}
public ArrayQueue(int capacity)
--- 44,47 ----
***************
*** 58,80 ****
remove = 0;
size = 0;
- growFactor = 2.0f;
- }
- public ArrayQueue(int capacity, float growFactor)
- {
- if(capacity < 0)
- {
- throw new ArgumentOutOfRangeException
- ("capacity",
S._("ArgRange_NonNegative"));
- }
- if(growFactor < 1.0f || growFactor > 10.0f)
- {
- throw new ArgumentOutOfRangeException
- ("growFactor",
S._("ArgRange_QueueGrowFactor"));
- }
- items = new T [capacity];
- add = 0;
- remove = 0;
- size = 0;
- this.growFactor = growFactor;
}
--- 56,59 ----
***************
*** 146,149 ****
--- 125,167 ----
}
+ // Implement the ICapacity interface.
+ public int Capacity
+ {
+ get
+ {
+ return items.Length;
+ }
+ set
+ {
+ if(value < 0)
+ {
+ throw new
ArgumentOutOfRangeException
+ ("value",
S._("ArgRange_NonNegative"));
+ }
+ if(value < size)
+ {
+ throw new
ArgumentOutOfRangeException
+ ("value",
S._("Arg_CannotReduceCapacity"));
+ }
+ if(value != size)
+ {
+ T[] newItems = new T [value];
+ if(remove < size)
+ {
+ Array.Copy(items,
remove, newItems,
+ 0,
size - remove);
+ }
+ if(remove > 0)
+ {
+ Array.Copy(items, 0,
newItems,
+ size
- remove, remove);
+ }
+ items = newItems;
+ add = size;
+ remove = 0;
+ }
+ }
+ }
+
// Implement the ICloneable<T> interface.
public Object Clone()
***************
*** 217,221 ****
{
// We need to increase the size of the
queue.
! int newCapacity = (int)(items.Length *
growFactor);
if(newCapacity <= items.Length)
{
--- 235,239 ----
{
// We need to increase the size of the
queue.
! int newCapacity = (int)(items.Length *
2);
if(newCapacity <= items.Length)
{
Index: ArrayStack.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Generics/ArrayStack.cs,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -r1.6 -r1.7
*** ArrayStack.cs 25 Feb 2003 01:43:47 -0000 1.6
--- ArrayStack.cs 25 Feb 2003 04:45:18 -0000 1.7
***************
*** 28,32 ****
using System;
! public sealed class ArrayStack<T> : IStack<T>, ICloneable
{
// Internal state.
--- 28,32 ----
using System;
! public sealed class ArrayStack<T> : IStack<T>, ICapacity, ICloneable
{
// Internal state.
***************
*** 37,43 ****
private const int DefaultCapacity = 10;
- // The amount to grow the stack by each time.
- private const int GrowSize = 10;
-
// Constructors.
public ArrayStack()
--- 37,40 ----
***************
*** 128,131 ****
--- 125,156 ----
}
+ // Implement the ICapacity interface.
+ public int Capacity
+ {
+ get
+ {
+ return items.Length;
+ }
+ set
+ {
+ if(value < 0)
+ {
+ throw new
ArgumentOutOfRangeException
+ ("value",
S._("ArgRange_NonNegative"));
+ }
+ if(value < size)
+ {
+ throw new
ArgumentOutOfRangeException
+ ("value",
S._("Arg_CannotReduceCapacity"));
+ }
+ if(value != size)
+ {
+ T[] newItems = new T [value];
+ Array.Copy(items, 0, newItems,
0, size);
+ items = newItems;
+ }
+ }
+ }
+
// Implement the IStack<T> interface.
public void Clear()
***************
*** 175,179 ****
{
// We need to increase the size of the
stack.
! int newCapacity = items.Length +
GrowSize;
T[] newItems = new T [newCapacity];
if(size > 0)
--- 200,208 ----
{
// We need to increase the size of the
stack.
! int newCapacity = items.Length * 2;
! if(newCapacity <= items.Length)
! {
! newCapacity = items.Length + 1;
! }
T[] newItems = new T [newCapacity];
if(size > 0)
Index: Generics.html
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Generics/Generics.html,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** Generics.html 25 Feb 2003 02:37:09 -0000 1.1
--- Generics.html 25 Feb 2003 04:45:18 -0000 1.2
***************
*** 183,186 ****
--- 183,191 ----
a hash code, suitable for use in classes such as
<code>Hashtable<T></code>.</dd>
+
+ <dt><code>ICapacity</code></dt>
+ <dd>Provides an interface to get or set the capacity of a collection.
+ Implemented by classes like <code>ArrayList<T></code>
+ that use an array to implement growable data structures.</dd>
</dl>
Index: Generics.txt
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Generics/Generics.txt,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** Generics.txt 24 Feb 2003 06:56:27 -0000 1.4
--- Generics.txt 25 Feb 2003 04:45:18 -0000 1.5
***************
*** 23,26 ****
--- 23,27 ----
#
Arg_ABMustBeComparable=a or b must implement IComparable<T>
+ Arg_CannotReduceCapacity=Cannot reduce the capacity of an array list below
its current length
Arg_InvalidArrayIndex=Array index is invalid
Arg_InvalidArrayRange=Array range is invalid
***************
*** 28,32 ****
ArgRange_HashLoadFactor=Invalid hash table load factor
ArgRange_NonNegative=Value must not be negative
- ArgRange_QueueGrowFactor=Invalid growth factor for queues
Invalid_BadEnumeratorPosition=The enumerator is not positioned on an element
Invalid_BadIteratorPosition=The iterator is not positioned on an element
--- 29,32 ----
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnetlib/Generics ICapacity.cs,NONE,1.1 ArrayList.cs,1.7,1.8 ArrayQueue.cs,1.6,1.7 ArrayStack.cs,1.6,1.7 Generics.html,1.1,1.2 Generics.txt,1.4,1.5,
Rhys Weatherley <address@hidden> <=