Commits

gyulalaszlo committed d68caf1 Draft

Added hash#clear to hash functions.

Comments (0)

Files changed (2)

 		/// (The table will grow automatically when 70 % full.)
 		template<typename T> void reserve(Hash<T> &h, uint32_t size);
 
+		/// Remove all elements from the hash.
+		template<typename T> void clear(Hash<T> &h);
+
 		/// 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 *begin(const Hash<T> &h);
 			hash_internal::rehash(h, size);
 		}
 
+		template<typename T> void clear(Hash<T> &h)
+		{
+			array::clear( h._data );
+			array::clear( h._hash );
+		}
+
 		template<typename T> const typename Hash<T>::Entry *begin(const Hash<T> &h)
 		{
 			return array::begin(h._data);
 			ASSERT(hash::get(h,1000,0) == 0);
 			for (int i=0; i<100; ++i)
 				ASSERT(hash::get(h,i,0) == i*i);
+			hash::clear(h);
+			for (int i=0; i<100; ++i)
+				ASSERT(!hash::has(h,i));
 		}
 		memory_globals::shutdown();
 	}