From 085e9251c5b2ca1d6300a46cf88e7d99207bbeb0 Mon Sep 17 00:00:00 2001 From: frosch Date: Sat, 16 Jan 2010 14:02:22 +0000 Subject: (svn r18823) -Codechange: Some uints for unsigned ints. (skidd13) --- src/misc/array.hpp | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) (limited to 'src/misc/array.hpp') diff --git a/src/misc/array.hpp b/src/misc/array.hpp index 737877c75..414d3efe0 100644 --- a/src/misc/array.hpp +++ b/src/misc/array.hpp @@ -17,10 +17,9 @@ /** Flexible array with size limit. Implemented as fixed size * array of fixed size arrays */ -template +template class SmallArray { public: - typedef T Titem; ///< Titem is now visible from outside typedef FixedSizeArray SubArray; ///< inner array typedef FixedSizeArray SuperArray; ///< outer array @@ -28,30 +27,28 @@ protected: SuperArray data; ///< array of arrays of items public: - static const int Tblock_size = B; ///< block size is now visible from outside - static const int Tnum_blocks = N; ///< number of blocks is now visible from outside - static const int Tcapacity = B * N; ///< total max number of items + static const uint Tcapacity = B * N; ///< total max number of items /** implicit constructor */ FORCEINLINE SmallArray() { } /** Clear (destroy) all items */ FORCEINLINE void Clear() {data.Clear();} /** Return actual number of items */ - FORCEINLINE int Length() const + FORCEINLINE uint Length() const { - int super_size = data.Length(); + uint super_size = data.Length(); if (super_size == 0) return 0; - int sub_size = data[super_size - 1].Length(); - return (super_size - 1) * Tblock_size + sub_size; + uint sub_size = data[super_size - 1].Length(); + return (super_size - 1) * B + sub_size; } /** return true if array is empty */ FORCEINLINE bool IsEmpty() { return data.IsEmpty(); } /** return true if array is full */ - FORCEINLINE bool IsFull() { return data.IsFull() && data[Tnum_blocks - 1].IsFull(); } + FORCEINLINE bool IsFull() { return data.IsFull() && data[N - 1].IsFull(); } /** return first sub-array with free space for new item */ FORCEINLINE SubArray& FirstFreeSubArray() { - int super_size = data.Length(); + uint super_size = data.Length(); if (super_size > 0) { SubArray& s = data[super_size - 1]; if (!s.IsFull()) return s; @@ -63,28 +60,28 @@ public: /** allocate and construct new item */ FORCEINLINE T& AppendC() { return FirstFreeSubArray().AppendC(); } /** indexed access (non-const) */ - FORCEINLINE Titem& operator [] (int index) + FORCEINLINE T& operator [] (uint index) { - SubArray& s = data[index / Tblock_size]; - Titem& item = s[index % Tblock_size]; + const SubArray& s = data[index / B]; + T& item = s[index % B]; return item; } /** indexed access (const) */ - FORCEINLINE const Titem& operator [] (int index) const + FORCEINLINE const T& operator [] (uint index) const { - const SubArray& s = data[index / Tblock_size]; - const Titem& item = s[index % Tblock_size]; + const SubArray& s = data[index / B]; + const T& item = s[index % B]; return item; } template void Dump(D &dmp) const { dmp.WriteLine("capacity = %d", Tcapacity); - int num_items = Length(); + uint num_items = Length(); dmp.WriteLine("num_items = %d", num_items); CStrA name; - for (int i = 0; i < num_items; i++) { - const Titem& item = (*this)[i]; + for (uint i = 0; i < num_items; i++) { + const T& item = (*this)[i]; name.Format("item[%d]", i); dmp.WriteStructT(name.Data(), &item); } -- cgit v1.2.3-54-g00ecf