00001 // IntArrayList.h 00002 00003 #ifndef _INTARRAYLIST_H__ 00004 #define _INTARRAYLIST_H__ 00005 00006 #include "Array.h" 00007 00008 00009 DSS_NAMESPASE_BEGIN 00010 00011 class IntArrayList 00012 { 00013 public: 00014 long* Items; 00015 long Count; 00016 long Capacity; 00017 00018 IntArrayList(); 00019 00020 IntArrayList(long capacity); 00021 00022 IntArrayList(long n,long* data); 00023 00024 //IntArrayList(ArrayList al) 00025 //{ 00026 // Items = (long[])al.ToArray(typeof(long)); 00027 // Capacity = Count = al.Count; 00028 //} 00029 00030 IntArrayList(const IntArrayList& al); 00031 00032 virtual ~IntArrayList(); 00033 00034 inline long operator[](const long i) const 00035 { 00036 return Items[i]; 00037 } 00038 00039 inline long& operator[](const long i) 00040 { 00041 return Items[i]; 00042 } 00043 00044 long Add(long a); 00045 00046 void AddRange(long count,long val); 00047 00048 void Fill(const IntArrayList& al); 00049 00050 /// <summary>If the last item of the array is not Item, then add it.</summary> 00051 /// <param name="item">Item</param> 00052 /// <returns>index of item</returns> 00053 long AddIfNotLast(long item); 00054 00055 void Clear(); 00056 void TrimToSize(); 00057 void Alloc(); 00058 void Alloc(long size); 00059 void Initialize(); 00060 void Initialize(long val); 00061 void InitIdentity(); 00062 00063 void SortInsert(long item); 00064 long SortInsertIfNot(long item); 00065 void Insert(long pos,long item); 00066 void RemoveAt(long pos); 00067 long BinarySearch(long item); 00068 // long BinarySearch(long startindex,long count, long item) 00069 long BinarySearch(long count, long item); 00070 00071 long* ToArray(); 00072 00073 /// <summary>Sums all contained integers.</summary> 00074 /// <returns>The sum.</returns> 00075 long SumElements(); 00076 00077 /// <summary>Sets items of a ptr* array using all indexes stored in this array.</summary> 00078 /// <param name="ptr">update items of this array</param> 00079 /// <param name="val">set value</param> 00080 void SetIndexesTo(long* ptr,long val); 00081 00082 /// <summary>Sets ~indexes of a ptr* array using all values stored in this array.</summary> 00083 /// <param name="ptr">update items of this array</param> 00084 void SetIndexesToMap(long* ptr); 00085 00086 bool TestSetIndexesTo(long* ptr,long valtest,long valset,bool& ind); 00087 00088 /// <summary>If ptr[element] is nonzero, then element will be removed from the array. </summary> 00089 /// <param name="ptr">Mask of which elements must be removed.</param> 00090 void RemoveByBattern(long* ptr); 00091 00092 /// <summary>If ptr[element] is nonzero, then element will be removed from the array. 00093 /// All remaining elements update ptr[element] to 1 </summary> 00094 /// <param name="ptr">Mask of which elements must be removed.</param> 00095 void RemoveMarkByBattern(long* ptr); 00096 00097 /// <summary>Computes how many elements are not set in the mask.</summary> 00098 /// <param name="ptr">mask</param> 00099 long CountWithoutMask(long* ptr); 00100 00101 }; 00102 00103 DSS_NAMESPASE_END 00104 00105 #endif //INTARRAYLIST_H__