Commits

Alexander Konovalov  committed 6239f17 Draft

Changed uint32_t to size_t where necessary

  • Participants
  • Parent commits c9fd3c4

Comments (0)

Files changed (14)

 	namespace array
 	{
 		/// The number of elements in the array.
-		template<typename T> uint32_t size(const Array<T> &a) ;
+		template<typename T> size_t size(const Array<T> &a) ;
 		/// Returns true if there are any elements in the array.
 		template<typename T> bool any(const Array<T> &a);
 		/// Returns true if the array is empty.
 		template<typename T> const T& back(const Array<T> &a);
 
 		/// Changes the size of the array (does not reallocate memory unless necessary).
-		template <typename T> void resize(Array<T> &a, uint32_t new_size);
+		template <typename T> void resize(Array<T> &a, size_t new_size);
 		/// Removes all items in the array (does not free memory).
 		template <typename T> void clear(Array<T> &a);
 		/// Reallocates the array to the specified capacity.
-		template<typename T> void set_capacity(Array<T> &a, uint32_t new_capacity);
+		template<typename T> void set_capacity(Array<T> &a, size_t new_capacity);
 		/// Makes sure that the array has at least the specified capacity.
 		/// (If not, the array is grown.)
-		template <typename T> void reserve(Array<T> &a, uint32_t new_capacity);
+		template <typename T> void reserve(Array<T> &a, size_t new_capacity);
 		/// Grows the array using a geometric progression formula, so that the ammortized
 		/// cost of push_back() is O(1). If a min_capacity is specified, the array will
 		/// grow to at least that capacity.
-		template<typename T> void grow(Array<T> &a, uint32_t min_capacity = 0);
+		template<typename T> void grow(Array<T> &a, size_t min_capacity = 0);
 		/// Trims the array so that its capacity matches its size.
 		template <typename T> void trim(Array<T> &a);
 
 
 	namespace array
 	{
-		template<typename T> inline uint32_t size(const Array<T> &a) 		{return a._size;}
+		template<typename T> inline size_t size(const Array<T> &a) 		{return a._size;}
 		template<typename T> inline bool any(const Array<T> &a) 			{return a._size != 0;}
 		template<typename T> inline bool empty(const Array<T> &a) 			{return a._size == 0;}
 		
 		template <typename T> inline void clear(Array<T> &a) {resize(a,0);}
 		template <typename T> inline void trim(Array<T> &a) {set_capacity(a,a._size);}
 
-		template <typename T> void resize(Array<T> &a, uint32_t new_size)
+		template <typename T> void resize(Array<T> &a, size_t new_size)
 		{
 			if (new_size > a._capacity)
 				grow(a, new_size);
 			a._size = new_size;
 		}
 
-		template <typename T> inline void reserve(Array<T> &a, uint32_t new_capacity)
+		template <typename T> inline void reserve(Array<T> &a, size_t new_capacity)
 		{
 			if (new_capacity > a._capacity)
 				set_capacity(a, new_capacity);
 		}
 
-		template<typename T> void set_capacity(Array<T> &a, uint32_t new_capacity)
+		template<typename T> void set_capacity(Array<T> &a, size_t new_capacity)
 		{
 			if (new_capacity == a._capacity)
 				return;
 			a._capacity = new_capacity;
 		}
 
-		template<typename T> void grow(Array<T> &a, uint32_t min_capacity)
+		template<typename T> void grow(Array<T> &a, size_t min_capacity)
 		{
-			uint32_t new_capacity = a._capacity*2 + 8;
+			size_t new_capacity = a._capacity*2 + 8;
 			if (new_capacity < min_capacity)
 				new_capacity = min_capacity;
 			set_capacity(a, new_capacity);
 	template <typename T>
 	Array<T>::Array(const Array<T> &other) : _allocator(other._allocator), _size(0), _capacity(0), _data(0)
 	{
-		const uint32_t n = other._size;
+		const size_t n = other._size;
 		array::set_capacity(*this, n);
 		memcpy(_data, other._data, sizeof(T) * n);
 		_size = n;
 	template <typename T>
 	Array<T> &Array<T>::operator=(const Array<T> &other)
 	{
-		const uint32_t n = other._size;
+		const size_t n = other._size;
 		array::resize(*this, n);
 		memcpy(_data, other._data, sizeof(T)*n);
 		return *this;
 	}
 
 	template <typename T>
-	inline T & Array<T>::operator[](uint32_t i)
+	inline T & Array<T>::operator[](size_t i)
 	{
 		return _data[i];
 	}
 
 	template <typename T>
-	inline const T & Array<T>::operator[](uint32_t i) const
+	inline const T & Array<T>::operator[](size_t i) const
 	{
 		return _data[i];
 	}
-}
+}

File collection_types.h

 		Array(const Array &other);
 		Array &operator=(const Array &other);
 		
-		T &operator[](uint32_t i);
-		const T &operator[](uint32_t i) const;
+		T &operator[](size_t i);
+		const T &operator[](size_t i) const;
 
 		Allocator *_allocator;
-		uint32_t _size;
-		uint32_t _capacity;
+		size_t _size;
+		size_t _capacity;
 		T *_data;
 	};
 
 	{
 		Queue(Allocator &a);
 
-		T &operator[](uint32_t i);
-		const T &operator[](uint32_t i) const;
+		T &operator[](size_t i);
+		const T &operator[](size_t i) const;
 
 		Array<T> _data;
-		uint32_t _size;
-		uint32_t _offset;
+		size_t _size;
+		size_t _offset;
 	};
 
 	/// Hash from an uint64_t to POD objects. If you want to use a generic key
 		
 		struct Entry {
 			uint64_t key;
-			uint32_t next;
+			size_t next;
 			T value;
 		};
 
-		Array<uint32_t> _hash;
+		Array<size_t> _hash;
 		Array<Entry> _data;
 	};
-}
+}
 
 		/// Resizes the hash lookup table to the specified size.
 		/// (The table will grow automatically when 70 % full.)
-		template<typename T> void reserve(Hash<T> &h, uint32_t size);
+		template<typename T> void reserve(Hash<T> &h, size_t size);
 
 		/// Returns a pointer to the first entry in the hash table, can be used to
 		/// efficiently iterate over the elements (in random order).
 		template<typename T> const typename Hash<T>::Entry *find_next(const Hash<T> &h, const typename Hash<T>::Entry *e);
 
 		/// Returns the number of entries with the key.
-		template<typename T> uint32_t count(const Hash<T> &h, uint64_t key);
+		template<typename T> size_t count(const Hash<T> &h, uint64_t key);
 
 		/// Returns all the entries with the specified key.
 		/// Use a TempAllocator for the array to avoid allocating memory.
 
 	namespace hash_internal
 	{
-		const uint32_t END_OF_LIST = 0xffffffffu;
+		const size_t END_OF_LIST = SIZE_MAX;
 		
 		struct FindResult
 		{
-			uint32_t hash_i;
-			uint32_t data_prev;
-			uint32_t data_i;
+			size_t hash_i;
+			size_t data_prev;
+			size_t data_i;
 		};	
 
-		template<typename T> uint32_t add_entry(Hash<T> &h, uint64_t key)
+		template<typename T> size_t add_entry(Hash<T> &h, uint64_t key)
 		{
 			typename Hash<T>::Entry e;
 			e.key = key;
 			e.next = END_OF_LIST;
-			uint32_t ei = array::size(h._data);
+			size_t ei = array::size(h._data);
 			array::push_back(h._data, e);
 			return ei;
 		}
 			return fr;
 		}
 
-		template<typename T> uint32_t find_or_fail(const Hash<T> &h, uint64_t key)
+		template<typename T> size_t find_or_fail(const Hash<T> &h, uint64_t key)
 		{
 			return find(h, key).data_i;
 		}
 
-		template<typename T> uint32_t find_or_make(Hash<T> &h, uint64_t key)
+		template<typename T> size_t find_or_make(Hash<T> &h, uint64_t key)
 		{
 			const FindResult fr = find(h, key);
 			if (fr.data_i != END_OF_LIST)
 				return fr.data_i;
 
-			uint32_t i = add_entry(h, key);
+			size_t i = add_entry(h, key);
 			if (fr.data_prev == END_OF_LIST)
 				h._hash[fr.hash_i] = i;
 			else
 			return i;
 		}
 
-		template<typename T> uint32_t make(Hash<T> &h, uint64_t key)
+		template<typename T> size_t make(Hash<T> &h, uint64_t key)
 		{
 			const FindResult fr = find(h, key);
-			const uint32_t i = add_entry(h, key);
+			const size_t i = add_entry(h, key);
 
 			if (fr.data_prev == END_OF_LIST)
 				h._hash[fr.hash_i] = i;
 				erase(h, fr);
 		}
 
-		template<typename T> void rehash(Hash<T> &h, uint32_t new_size)
+		template<typename T> void rehash(Hash<T> &h, size_t new_size)
 		{
 			Hash<T> nh(*h._hash._allocator);
 			array::resize(nh._hash, new_size);
 			array::reserve(nh._data, array::size(h._data));
-			for (uint32_t i=0; i<new_size; ++i)
+			for (size_t i=0; i<new_size; ++i)
 				nh._hash[i] = END_OF_LIST;
-			for (uint32_t i=0; i<array::size(h._data); ++i) {
+			for (size_t i=0; i<array::size(h._data); ++i) {
 				const typename Hash<T>::Entry &e = h._data[i];
 				multi_hash::insert(nh, e.key, e.value);
 			}
 
 		template<typename T> void grow(Hash<T> &h)
 		{
-			const uint32_t new_size = array::size(h._data) * 2 + 10;
+			const size_t new_size = array::size(h._data) * 2 + 10;
 			rehash(h, new_size);
 		}
 	}
 
 		template<typename T> const T &get(const Hash<T> &h, uint64_t key, const T &deffault)
 		{
-			const uint32_t i = hash_internal::find_or_fail(h, key);
+			const size_t i = hash_internal::find_or_fail(h, key);
 			return i == hash_internal::END_OF_LIST ? deffault : h._data[i].value;
 		}
 
 			if (array::size(h._hash) == 0)
 				hash_internal::grow(h);
 
-			const uint32_t i = hash_internal::find_or_make(h, key);
+			const size_t i = hash_internal::find_or_make(h, key);
 			h._data[i].value = value;
 			if (hash_internal::full(h))
 				hash_internal::grow(h);
 			hash_internal::find_and_erase(h, key);
 		}
 
-		template<typename T> void reserve(Hash<T> &h, uint32_t size)
+		template<typename T> void reserve(Hash<T> &h, size_t size)
 		{
 			hash_internal::rehash(h, size);
 		}
 	{
 		template<typename T> const typename Hash<T>::Entry *find_first(const Hash<T> &h, uint64_t key)
 		{
-			const uint32_t i = hash_internal::find_or_fail(h, key);
+			const size_t i = hash_internal::find_or_fail(h, key);
 			return i == hash_internal::END_OF_LIST ? 0 : &h._data[i];
 		}
 
 		template<typename T> const typename Hash<T>::Entry *find_next(const Hash<T> &h, const typename Hash<T>::Entry *e)
 		{
-			uint32_t i = e->next;
+			size_t i = e->next;
 			while (i != hash_internal::END_OF_LIST) {
 				if (h._data[i].key == e->key)
 					return &h._data[i];
 			return 0;
 		}
 
-		template<typename T> uint32_t count(const Hash<T> &h, uint64_t key)
+		template<typename T> size_t count(const Hash<T> &h, uint64_t key)
 		{
-			uint32_t i = 0;
+			size_t i = 0;
 			const typename Hash<T>::Entry *e = find_first(h, key);
 			while (e) {
 				++i;
 			if (array::size(h._hash) == 0)
 				hash_internal::grow(h);
 
-			const uint32_t i = hash_internal::make(h, key);
+			const size_t i = hash_internal::make(h, key);
 			h._data[i].value = value;
 			if (hash_internal::full(h))
 				hash_internal::grow(h);
 	template <typename T> Hash<T>::Hash(Allocator &a) :
 		_hash(a), _data(a)
 	{}
-}
+}
 	// Header stored at the beginning of a memory allocation to indicate the
 	// size of the allocated data.
 	struct Header {
-		uint32_t size;
+		size_t size;
 	};
 
 	// If we need to align the memory allocation we pad the header with this
 	// value after storing the size. That way we can 
-	const uint32_t HEADER_PAD_VALUE = 0xffffffffu;
+	const size_t HEADER_PAD_VALUE = SIZE_MAX;
 
 	// Given a pointer to the header, returns a pointer to the data that follows it.
-	inline void *data_pointer(Header *header, uint32_t align) {
+	inline void *data_pointer(Header *header, size_t align) {
 		void *p = header + 1;
 		return memory::align_forward(p, align);
 	}
 	// Given a pointer to the data, returns a pointer to the header before it.
 	inline Header *header(void *data)
 	{
-		uint32_t *p = (uint32_t *)data;
+		size_t *p = (size_t *)data;
 		while (p[-1] == HEADER_PAD_VALUE)
 			--p;
 		return (Header *)p - 1;
 
 	// Stores the size in the header and pads with HEADER_PAD_VALUE up to the
 	// data pointer.
-	inline void fill(Header *header, void *data, uint32_t size)
+	inline void fill(Header *header, void *data, size_t size)
 	{
 		header->size = size;
-		uint32_t *p = (uint32_t *)(header + 1);
+		size_t *p = (size_t *)(header + 1);
 		while (p < data)
 			*p++ = HEADER_PAD_VALUE;
 	}
 	/// MallocAllocator.)
 	class MallocAllocator : public Allocator
 	{
-		uint32_t _total_allocated;
+		size_t _total_allocated;
 
 		// Returns the size to allocate from malloc() for a given size and align.		
-		static inline uint32_t size_with_padding(uint32_t size, uint32_t align) {
+		static inline size_t size_with_padding(size_t size, size_t align) {
 			return size + align + sizeof(Header);
 		}
 
 			assert(_total_allocated == 0);
 		}
 
-		virtual void *allocate(uint32_t size, uint32_t align) {
-			const uint32_t ts = size_with_padding(size, align);
+		virtual void *allocate(size_t size, size_t align) {
+			const size_t ts = size_with_padding(size, align);
 			Header *h = (Header *)malloc(ts);
 			void *p = data_pointer(h, align);
 			fill(h, p, ts);
 			free(h);
 		}
 
-		virtual uint32_t allocated_size(void *p) {
+		virtual size_t allocated_size(void *p) {
 			return header(p)->size;
 		}
 
-		virtual uint32_t total_allocated() {
+		virtual size_t total_allocated() {
 			return _total_allocated;
 		}
 	};
 		/// that don't fit in the ring buffer.
 		///
 		/// size specifies the size of the ring buffer.
-		ScratchAllocator(Allocator &backing, uint32_t size) : _backing(backing) {
+		ScratchAllocator(Allocator &backing, size_t size) : _backing(backing) {
 			_begin = (char *)_backing.allocate(size);
 			_end = _begin + size;
 			_allocate = _begin;
 			return p >= _free || p < _allocate;
 		}
 
-		virtual void *allocate(uint32_t size, uint32_t align) {
+		virtual void *allocate(size_t size, size_t align) {
 			assert(align % 4 == 0);
 			size = ((size + 3)/4)*4;
 
 
 			// Reached the end of the buffer, wrap around to the beginning.
 			if (p > _end) {
-				h->size = (_end - (char *)h) | 0x80000000u;
+				h->size = (_end - (char *)h) | ((size_t)1 << (SIZE_BITS - 1));
 				
 				p = _begin;
 				h = (Header *)p;
 
 			// Mark this slot as free
 			Header *h = header(p);
-			assert((h->size & 0x80000000u) == 0);
-			h->size = h->size | 0x80000000u;
+			assert((h->size & ((size_t)1 << (SIZE_BITS - 1))) == 0);
+			h->size = h->size | ((size_t)1 << (SIZE_BITS - 1));
 
 			// Advance the free pointer past all free slots.
 			while (_free != _allocate) {
 				Header *h = (Header *)_free;
-				if ((h->size & 0x80000000u) == 0)
+				if ((h->size & ((size_t)1 << (SIZE_BITS - 1))) == 0)
 					break;
 
-				_free += h->size & 0x7fffffffu;
+				_free += h->size & (((size_t)1 << (SIZE_BITS - 1)) - 1);
 				if (_free == _end)
 					_free = _begin;
 			}
 		}
 
-		virtual uint32_t allocated_size(void *p) {
+		virtual size_t allocated_size(void *p) {
 			Header *h = header(p);
 			return h->size - ((char *)p - (char *)h);
 		}
 
-		virtual uint32_t total_allocated() {
+		virtual size_t total_allocated() {
 			return _end - _begin;
 		}
 	};
 {
 	namespace memory_globals
 	{
-		void init(uint32_t temporary_memory) {
+		void init(size_t temporary_memory) {
 			char *p = _memory_globals.buffer;
 			_memory_globals.default_allocator = new (p) MallocAllocator();
 			p += sizeof(MallocAllocator);
 	{
 	public:
 		/// Default alignment for memory allocations.
-		static const uint32_t DEFAULT_ALIGN = 4;
+		static const size_t DEFAULT_ALIGN = 4;
 
 		Allocator() {}
 		virtual ~Allocator() {}
 		
 		/// Allocates the specified amount of memory aligned to the specified alignment.
-		virtual void *allocate(uint32_t size, uint32_t align = DEFAULT_ALIGN) = 0;
+		virtual void *allocate(size_t size, size_t align = DEFAULT_ALIGN) = 0;
 
 		/// Frees an allocation previously made with allocate().
 		virtual void deallocate(void *p) = 0;
 
-		static const uint32_t SIZE_NOT_TRACKED = 0xffffffffu;
+		static const size_t SIZE_NOT_TRACKED = SIZE_MAX;
 
 		/// Returns the amount of usable memory allocated at p. p must be a pointer
 		/// returned by allocate() that has not yet been deallocated. The value returned
 		///
 		/// Not all allocators support tracking the size of individual allocations.
 		/// An allocator that doesn't suppor it will return SIZE_NOT_TRACKED.
-		virtual uint32_t allocated_size(void *p) = 0;
+		virtual size_t allocated_size(void *p) = 0;
 
 		/// Returns the total amount of memory allocated by this allocator. Note that the 
 		/// size returned can be bigger than the size of all individual allocations made,
 		/// because the allocator may keep additional structures.
 		///
 		/// If the allocator doesn't track memory, this function returns SIZE_NOT_TRACKED.
-		virtual uint32_t total_allocated() = 0;
+		virtual size_t total_allocated() = 0;
 
 	private:
 		/// Allocators cannot be copied.
 	namespace memory_globals {
 		/// Initializes the global memory allocators. scratch_buffer_size is the size of the
 		/// memory buffer used by the scratch allocators.
-		void init(uint32_t scratch_buffer_size = 4*1024*1024);
+		void init(size_t scratch_buffer_size = 4*1024*1024);
 
 		/// Returns a default memory allocator that can be used for most allocations.
 		///
 	}
 
 	namespace memory {
-		inline void *align_forward(void *p, uint32_t align);
-		inline void *pointer_add(void *p, uint32_t bytes);
-		inline const void *pointer_add(const void *p, uint32_t bytes);
-		inline void *pointer_sub(void *p, uint32_t bytes);
-		inline const void *pointer_sub(const void *p, uint32_t bytes);
+		inline void *align_forward(void *p, size_t align);
+		inline void *pointer_add(void *p, size_t bytes);
+		inline const void *pointer_add(const void *p, size_t bytes);
+		inline void *pointer_sub(void *p, size_t bytes);
+		inline const void *pointer_sub(const void *p, size_t bytes);
 	}
 
 	// ---------------------------------------------------------------
 
 	// Aligns p to the specified alignment by moving it forward if necessary
 	// and returns the result.
-	inline void *memory::align_forward(void *p, uint32_t align) {
+	inline void *memory::align_forward(void *p, size_t align) {
 		uintptr_t pi = uintptr_t(p);
-		const uint32_t mod = pi % align;
+		const size_t mod = pi % align;
 		if (mod)
 			pi += (align - mod);
 		return (void *)pi;
 	}
 
 	/// Returns the result of advancing p by the specified number of bytes
-	inline void *memory::pointer_add(void *p, uint32_t bytes)	{
+	inline void *memory::pointer_add(void *p, size_t bytes)	{
 		return (void*)((char *)p + bytes);
 	}
 
-	inline const void *memory::pointer_add(const void *p, uint32_t bytes)	{
+	inline const void *memory::pointer_add(const void *p, size_t bytes)	{
 		return (const void*)((const char *)p + bytes);
 	}
 
 	/// Returns the result of moving p back by the specified number of bytes
-	inline void *memory::pointer_sub(void *p, uint32_t bytes)	{
+	inline void *memory::pointer_sub(void *p, size_t bytes)	{
 		return (void*)((char *)p - bytes);
 	}
 
-	inline const void *memory::pointer_sub(const void *p, uint32_t bytes)	{
+	inline const void *memory::pointer_sub(const void *p, size_t bytes)	{
 		return (const void*)((const char *)p - bytes);
 	}
 }

File murmur_hash.cpp

 
 namespace foundation
 {
-	uint64_t murmur_hash_64(const void * key, uint32_t len, uint64_t seed)
+	uint64_t murmur_hash_64(const void * key, size_t len, uint64_t seed)
 	{
 		const uint64_t m = 0xc6a4a7935bd1e995ULL;
 		const uint32_t r = 47;
 
 		return h;
 	}
-}
+}

File murmur_hash.h

 {
 	/// Implementation of the 64 bit MurmurHash2 function
 	/// http://murmurhash.googlepages.com/
-	uint64_t murmur_hash_64(const void *key, uint32_t len, uint64_t seed);
-}
+	uint64_t murmur_hash_64(const void *key, size_t len, uint64_t seed);
+}
 	namespace queue 
 	{
 		/// Returns the number of items in the queue.
-		template <typename T> uint32_t size(const Queue<T> &q);
+		template <typename T> size_t size(const Queue<T> &q);
 		/// Returns the ammount of free space in the queue/ring buffer.
 		/// This is the number of items we can push before the queue needs to grow.
-		template<typename T> uint32_t space(const Queue<T> &q);
+		template<typename T> size_t space(const Queue<T> &q);
 		/// Makes sure the queue has room for at least the specified number of items.
-		template<typename T> void reserve(Queue<T> &q, uint32_t size);
+		template<typename T> void reserve(Queue<T> &q, size_t size);
 
 		/// Pushes the item to the end of the queue.
 		template<typename T> void push_back(Queue<T> &q, const T &item);
 		template<typename T> void pop_front(Queue<T> &q);
 
 		/// Consumes n items from the front of the queue.
-		template <typename T> void consume(Queue<T> &q, uint32_t n);
+		template <typename T> void consume(Queue<T> &q, size_t n);
 		/// Pushes n items to the back of the queue.
-		template <typename T> void push(Queue<T> &q, const T *items, uint32_t n);
+		template <typename T> void push(Queue<T> &q, const T *items, size_t n);
 
 		/// Returns the begin and end of the continuous chunk of elements at
 		/// the start of the queue. (Note that this chunk does not necessarily
 	namespace queue_internal
 	{
 		// Can only be used to increase the capacity.
-		template<typename T> void increase_capacity(Queue<T> &q, uint32_t new_capacity)
+		template<typename T> void increase_capacity(Queue<T> &q, size_t new_capacity)
 		{
-			uint32_t end = array::size(q._data);
+			size_t end = array::size(q._data);
 			array::resize(q._data, new_capacity);
 			if (q._offset + q._size > end) {
-				uint32_t end_items = end - q._offset;
+				size_t end_items = end - q._offset;
 				memmove(array::begin(q._data) + new_capacity - end_items, array::begin(q._data) + q._offset, end_items * sizeof(T));
 				q._offset += new_capacity - end;
 			}
 		}
 
-		template<typename T> void grow(Queue<T> &q, uint32_t min_capacity = 0)
+		template<typename T> void grow(Queue<T> &q, size_t min_capacity = 0)
 		{
-			uint32_t new_capacity = array::size(q._data)*2 + 8;
+			size_t new_capacity = array::size(q._data)*2 + 8;
 			if (new_capacity < min_capacity)
 				new_capacity = min_capacity;
 			increase_capacity(q, new_capacity);
 
 	namespace queue 
 	{
-		template<typename T> inline uint32_t size(const Queue<T> &q)
+		template<typename T> inline size_t size(const Queue<T> &q)
 		{
 			return q._size;
 		}
 
-		template<typename T> inline uint32_t space(const Queue<T> &q)
+		template<typename T> inline size_t space(const Queue<T> &q)
 		{
 			return array::size(q._data) - q._size;
 		}
 
-		template<typename T> void reserve(Queue<T> &q, uint32_t size)
+		template<typename T> void reserve(Queue<T> &q, size_t size)
 		{
 			if (size > q._size)
 				queue_internal::increase_capacity(q, size);
 			--q._size;
 		}
 
-		template <typename T> inline void consume(Queue<T> &q, uint32_t n)
+		template <typename T> inline void consume(Queue<T> &q, size_t n)
 		{
 			q._offset = (q._offset + n) % array::size(q._data);
 			q._size -= n;
 		}
 
-		template <typename T> void push(Queue<T> &q, const T *items, uint32_t n)
+		template <typename T> void push(Queue<T> &q, const T *items, size_t n)
 		{
 			if (space(q) < n)
 				queue_internal::grow(q, size(q) + n);
-			const uint32_t size = array::size(q._data);
-			const uint32_t insert = (q._offset + q._size) % size;
-			uint32_t to_insert = n;
+			const size_t size = array::size(q._data);
+			const size_t insert = (q._offset + q._size) % size;
+			size_t to_insert = n;
 			if (insert + to_insert > size)
 				to_insert = size - insert;
 			memcpy(array::begin(q._data) + insert, items, to_insert * sizeof(T));
 		}
 		template<typename T> T* end_front(Queue<T> &q)
 		{
-			uint32_t end = q._offset + q._size;
+			size_t end = q._offset + q._size;
 			return end > array::size(q._data) ? array::end(q._data) : array::begin(q._data) + end;
 		}
 		template<typename T> const T* end_front(const Queue<T> &q)
 		{
-			uint32_t end = q._offset + q._size;
+			size_t end = q._offset + q._size;
 			return end > array::size(q._data) ? array::end(q._data) : array::begin(q._data) + end;
 		}
 	}
 
 	template <typename T> inline Queue<T>::Queue(Allocator &allocator) : _data(allocator), _size(0), _offset(0) {}
 
-	template <typename T> inline T & Queue<T>::operator[](uint32_t i)
+	template <typename T> inline T & Queue<T>::operator[](size_t i)
 	{
 		return _data[(i + _offset) % array::size(_data)];
 	}
 
-	template <typename T> inline const T & Queue<T>::operator[](uint32_t i) const
+	template <typename T> inline const T & Queue<T>::operator[](size_t i) const
 	{
 		return _data[(i + _offset) % array::size(_data)];
 	}
-}
+}
 file 'unit_test.o' => %w(unit_test.cpp) + HEADERS
 file 'memory.o' => %w(memory.cpp) + %w(types.h memory_types.h memory.h)
 file 'murmur_hash.o' => %w(murmur_hash.cpp) + %w(murmur_hash.h)
-file 'string_stream.o' => %w(string_stream.cpp) + %w(string_stream.h collection_types.h array.h types.h memory_types.h  )
+file 'string_stream.o' => %w(string_stream.cpp) + %w(string_stream.h collection_types.h array.h types.h memory_types.h  )

File string_stream.cpp

 			int n = vsnprintf(NULL, 0, format, args);
 			va_end(args);
 
-			uint32_t end = array::size(b);
+			size_t end = array::size(b);
 			array::resize(b, end + n + 1);
 			
 			va_start(args, format);
 			return b;
 		}
 
-		Buffer & tab(Buffer &b, uint32_t column)
+		Buffer & tab(Buffer &b, size_t column)
 		{
-			uint32_t current_column = 0;
-			uint32_t i = array::size(b) - 1;
-			while (i != 0xffffffffu && b[i] != '\n' && b[i] != '\r') {
+			size_t current_column = 0;
+			size_t i = array::size(b) - 1;
+			while (i != SIZE_MAX && b[i] != '\n' && b[i] != '\r') {
 				++current_column;
 				--i;
 			}
 			return b;
 		}
 
-		Buffer & repeat(Buffer &b, uint32_t count, char c)
+		Buffer & repeat(Buffer &b, size_t count, char c)
 		{
-			for (uint32_t i=0; i<count; ++i)
+			for (size_t i=0; i<count; ++i)
 				array::push_back(b, c);
 			return b;
 		}
 	}
-}
+}

File string_stream.h

 		Buffer & printf(Buffer &b, const char *format, ...);
 
 		/// Pushes the raw data to the stream.
-		Buffer & push(Buffer &b, const char *data, uint32_t n);
+		Buffer & push(Buffer &b, const char *data, size_t n);
 
 		/// Pads the stream with spaces until it is aligned at the specified column.
 		/// Can be used to column align data. (Assumes each char is 1 space wide,
 		/// i.e. does not work with UTF-8 data.)
-		Buffer & tab(Buffer &b, uint32_t column);
+		Buffer & tab(Buffer &b, size_t column);
 
 		/// Adds the specified number of c to the stream.
-		Buffer & repeat(Buffer &b, uint32_t count, char c);
+		Buffer & repeat(Buffer &b, size_t count, char c);
 
 		/// Returns the stream as a C-string. There will always be a \0 character
 		/// at the end of the returned string. You don't have to explicitly add it
 			return string_stream_internal::printf_small(b, "%01llx", i);
 		}
 
-		inline Buffer & push(Buffer &b, const char *data, uint32_t n)
+		inline Buffer & push(Buffer &b, const char *data, size_t n)
 		{
 			unsigned int end = array::size(b);
 			array::resize(b, end + n);
 			return array::begin(b);
 		}
 	}
-}
+}

File temp_allocator.h

 	///
 	/// Memory allocated with a TempAllocator does not have to be deallocated. It is
 	/// automatically deallocated when the TempAllocator is destroyed.
-	template <int BUFFER_SIZE>
+	template <size_t BUFFER_SIZE>
 	class TempAllocator : public Allocator
 	{
 	public:
 		TempAllocator(Allocator &backing = memory_globals::default_scratch_allocator());
 		virtual ~TempAllocator();
 
-		virtual void *allocate(uint32_t size, uint32_t align = DEFAULT_ALIGN);
+		virtual void *allocate(size_t size, size_t align = DEFAULT_ALIGN);
 		
 		/// Deallocation is a NOP for the TempAllocator. The memory is automatically
 		/// deallocated when the TempAllocator is destroyed.
 		virtual void deallocate(void *) {}
 
 		/// Returns SIZE_NOT_TRACKED.
-		virtual uint32_t allocated_size(void *) {return SIZE_NOT_TRACKED;}
+		virtual size_t allocated_size(void *) {return SIZE_NOT_TRACKED;}
 
 		/// Returns SIZE_NOT_TRACKED.
-		virtual uint32_t total_allocated() {return SIZE_NOT_TRACKED;}
+		virtual size_t total_allocated() {return SIZE_NOT_TRACKED;}
 
 	private:
 		char _buffer[BUFFER_SIZE];	//< Local stack buffer for allocations.
 	// Inline function implementations
 	// ---------------------------------------------------------------
 
-	template <int BUFFER_SIZE>
+	template <size_t BUFFER_SIZE>
 	TempAllocator<BUFFER_SIZE>::TempAllocator(Allocator &backing) : _backing(backing), _chunk_size(4*1024)
 	{
 		_p = _start = _buffer;
 		_p += sizeof(void *);
 	}
 
-	template <int BUFFER_SIZE>
+	template <size_t BUFFER_SIZE>
 	TempAllocator<BUFFER_SIZE>::~TempAllocator()
 	{
 		void *p = *(void **)_buffer;
 		}
 	}
 
-	template <int BUFFER_SIZE>
-	void *TempAllocator<BUFFER_SIZE>::allocate(uint32_t size, uint32_t align)
+	template <size_t BUFFER_SIZE>
+	void *TempAllocator<BUFFER_SIZE>::allocate(size_t size, size_t align)
 	{
 		_p = (char *)memory::align_forward(_p, align);
 		if ((int)size > _end - _p) {
-			uint32_t to_allocate = sizeof(void *) + size + align;
+			size_t to_allocate = sizeof(void *) + size + align;
 			if (to_allocate < _chunk_size)
 				to_allocate = _chunk_size;
 			_chunk_size *= 2;
 		_p += size;
 		return result;
 	}
-}
+}
 #pragma once
 
+#define __STDC_LIMIT_MACROS
 #include <stdint.h>
+#include <stddef.h>
+
+#define SIZE_BITS (8*sizeof(size_t))
 
 #ifndef alignof
 	#define alignof(x) __alignof(x)
-#endif
+#endif

File unit_test.cpp

 			v2 = v;
 			ASSERT(v2[0] == 3);
 			
-			ASSERT(array::end(v) - array::begin(v) == array::size(v));
+			ASSERT(array::end(v) == array::begin(v) + array::size(v));
 			ASSERT(*array::begin(v) == 3);
 			array::pop_back(v);
 			ASSERT(array::empty(v));
 	test_string_stream();
 	test_queue();
 	return 0;
-}
+}