3 Commits 77f7e97b95 ... 411fdc950f

Author SHA1 Message Date
  namark 411fdc950f Psyched myself over a silly typo in smolen. 5 months ago
  namark d9e0765d3c Minor improvements. 5 months ago
  namark 270a9cc6ad Clarified some comments. 5 months ago

+ 11 - 13
source/simple/compress/bits.hpp

@@ -131,29 +131,27 @@ namespace simple::compress
 		using value_type = T;
 		static constexpr std::size_t capacity = std::numeric_limits<value_type>::digits;
 
-		constexpr bool insert(bool bit) noexcept
+		constexpr bool full() const noexcept { return count == capacity; }
+		constexpr bool empty() const noexcept { return count == 0; }
+
+		constexpr void insert(bool bit) noexcept
 		{
-			if(count != capacity)
-			{
-				++count;
-				value >>= 1;
-				value |= value_type{bit} << (capacity - 1);
-				return true;
-			}
-			else
-				return false;
+			assert(not full());
+			++count;
+			value >>= 1;
+			value |= value_type{bit} << (capacity - 1);
 		}
 
-		constexpr bits& operator=(const T& x)
+		constexpr bits& operator=(const T& x) noexcept
 		{
 			// TODO: assert x has no junk outside of count
 			value = x;
 			return *this;
 		}
 
-		constexpr bool operator==(const bits& other) const
+		constexpr bool operator==(const bits& other) const noexcept
 		{ return value == other.value && count == other.count; }
-		constexpr bool operator!=(const bits& other) const
+		constexpr bool operator!=(const bits& other) const noexcept
 		{ return not ((*this) == other); }
 	};
 

+ 1 - 1
source/simple/compress/hash_table.hpp

@@ -39,7 +39,7 @@ namespace simple::compress
 			return row(*this,key);
 		}
 
-		auto insert(const Key& key, const Value& value)
+		void insert(const Key& key, const Value& value)
 		{
 			row(*this,key).push_back(value);
 			++size_;

+ 2 - 2
source/simple/compress/huffman.hpp

@@ -151,7 +151,7 @@ namespace simple::compress
 	{
 		using key_type = std::make_unsigned_t<underlying_type_t<typename std::iterator_traits<It>::value_type>>;
 		small_table<key_type, std::size_t> counter{};
-		small_table<key_type, bits<>> code{}; // TODO smaller key, smaller bits
+		small_table<key_type, bits<>> code{}; // TODO smaller key -> less bits
 		std::conditional_t<bit_count(key_type{}) <= 13,
 			static_vector<std::pair<key_type,key_type>, (1 << bit_count(key_type{}))>,
 			std::vector<std::pair<key_type,key_type>>
@@ -183,7 +183,7 @@ namespace simple::compress
 			if(0 == minmin[1].second)
 				break;
 
-			// FIXME handle insert fail
+			// FIXME handle code length overflow
 			code[minmin[0].first].insert(0);
 			code[minmin[1].first].insert(1);
 			for(auto& [symbol, parent] : hierarchy)

+ 1 - 0
unit_tests/dct.cpp

@@ -111,6 +111,7 @@ int main()
 	DCT_1(1025, [&](auto x) { return std::cos(tau*x); });
 	DCT_1(2049, [&](auto x) { return std::sin(tau*x) + std::cos(tau*x*2); });
 	DCT_1(2049, [&](auto x) { return std::sin(tau*x) + std::cos(tau*x); });
+	DCT_1(2049, [&](auto x) { return std::sin(tau*x)/2; });
 	DCT_1(2049, [&](auto x) { return std::sin(tau*x); });
 	DCT_1(2049, [&](auto x) { return std::cos(tau*x); });