Skip to content

Commit

Permalink
Rename word size function to bitsize_to_wordsize
Browse files Browse the repository at this point in the history
  • Loading branch information
smlu committed Dec 6, 2023
1 parent e42d326 commit fcf0814
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 58 deletions.
6 changes: 3 additions & 3 deletions include/ack/bigint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ namespace ack {
size_t zn = xn;
const bool success = z.buf_.alloc(zn);
assert(success);
if (!success ) {
if ( !success ) {
z.clear();
return;
}
Expand Down Expand Up @@ -1934,7 +1934,7 @@ namespace ack {
static constexpr void shl(bigint& y, const bigint& x, std::size_t shift_bit)
{
size_t xn = x.size();
size_t yn = xn + get_word_size_from_bitsize(shift_bit); /*(shift_bit + word_bit_size - 1) / word_bit_size;*/
size_t yn = xn + bitsize_to_wordsize(shift_bit); /*(shift_bit + word_bit_size - 1) / word_bit_size;*/

[[maybe_unused]] const bool success = y.buf_.alloc(yn);
assert(success);
Expand Down Expand Up @@ -2529,7 +2529,7 @@ namespace ack {
* The maximum size of a fixed_bigint can be 512 bits for all ECC & RSA operations.
*/
template<std::size_t MaxBitSize>
using fixed_bigint = bigint<fixed_word_buffer<get_word_size_from_bitsize(MaxBitSize)>>;
using fixed_bigint = bigint<fixed_word_buffer<bitsize_to_wordsize(MaxBitSize)>>;

template <typename>
struct is_bigint : std::false_type {};
Expand Down
11 changes: 5 additions & 6 deletions include/ack/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ namespace ack {

private:
buffer_base() = default;

friend derived_type;
};

Expand All @@ -77,7 +76,7 @@ namespace ack {

constexpr bool alloc(size_t n)
{
if (n > N) {
if ( n > N ) {
return false;
}
size_ = n;
Expand Down Expand Up @@ -111,19 +110,19 @@ namespace ack {

constexpr void swap(fixed_buffer& rhs)
{
std::swap(data_, rhs.data_);
std::swap(size_, rhs.size_);
std::swap( data_, rhs.data_ );
std::swap( size_, rhs.size_ );
}

constexpr const T& operator[](size_t n) const
{
check(n < size_, "fixed_buffer:operator[]: overflow");
check( n < size_, "fixed_buffer:operator[]: overflow" );
return data_[n];
}

constexpr T& operator[](size_t n)
{
check(n < size_, "fixed_buffer:operator[]: overflow");
check( n < size_, "fixed_buffer:operator[]: overflow" );
return data_[n];
}

Expand Down
2 changes: 1 addition & 1 deletion include/ack/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace ack {
using hash384 = eosio::fixed_bytes<48>;
using hash512 = eosio::checksum512;

static constexpr size_t word_bit_size = sizeof(word_t) * 8;
inline constexpr size_t word_bit_size = sizeof(word_t) * 8;

inline bytes make_bytes(const bytes_view& data) {
return bytes{ data.begin(), data.end() };
Expand Down
2 changes: 1 addition & 1 deletion include/ack/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ namespace ack {
* @param bitsize - the number of bits
* @return the number of words needed to store the given number of bits
*/
inline constexpr std::size_t get_word_size_from_bitsize(std::size_t bitsize) {
inline constexpr std::size_t bitsize_to_wordsize(std::size_t bitsize) {
return (bitsize + word_bit_size - 1) / word_bit_size;
}

Expand Down
94 changes: 47 additions & 47 deletions tests/include/ack/tests/utils_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,53 +17,53 @@ namespace ack::tests {
static_assert( sizeof( word_t ) == 4 );

// bitsize
REQUIRE_EQUAL( get_word_size_from_bitsize(0), 0 )
REQUIRE_EQUAL( get_word_size_from_bitsize(1), 1 )
REQUIRE_EQUAL( get_word_size_from_bitsize(8), 1 )
REQUIRE_EQUAL( get_word_size_from_bitsize(9), 1 )
REQUIRE_EQUAL( get_word_size_from_bitsize(16), 1 )
REQUIRE_EQUAL( get_word_size_from_bitsize(17), 1 )
REQUIRE_EQUAL( get_word_size_from_bitsize(24), 1 )
REQUIRE_EQUAL( get_word_size_from_bitsize(25), 1 )
REQUIRE_EQUAL( get_word_size_from_bitsize(31), 1 )
REQUIRE_EQUAL( get_word_size_from_bitsize(32), 1 )
REQUIRE_EQUAL( get_word_size_from_bitsize(33), 2 )
REQUIRE_EQUAL( get_word_size_from_bitsize(48), 2 )
REQUIRE_EQUAL( get_word_size_from_bitsize(49), 2 )
REQUIRE_EQUAL( get_word_size_from_bitsize(64), 2 )
REQUIRE_EQUAL( get_word_size_from_bitsize(65), 3 )
REQUIRE_EQUAL( get_word_size_from_bitsize(96), 3 )
REQUIRE_EQUAL( get_word_size_from_bitsize(97), 4 )
REQUIRE_EQUAL( get_word_size_from_bitsize(127), 4 )
REQUIRE_EQUAL( get_word_size_from_bitsize(128), 4 )
REQUIRE_EQUAL( get_word_size_from_bitsize(129), 5 )
REQUIRE_EQUAL( get_word_size_from_bitsize(160), 5 )
REQUIRE_EQUAL( get_word_size_from_bitsize(161), 6 )
REQUIRE_EQUAL( get_word_size_from_bitsize(192), 6 )
REQUIRE_EQUAL( get_word_size_from_bitsize(193), 7 )
REQUIRE_EQUAL( get_word_size_from_bitsize(224), 7 )
REQUIRE_EQUAL( get_word_size_from_bitsize(225), 8 )
REQUIRE_EQUAL( get_word_size_from_bitsize(255), 8 )
REQUIRE_EQUAL( get_word_size_from_bitsize(256), 8 )
REQUIRE_EQUAL( get_word_size_from_bitsize(257), 9 )
REQUIRE_EQUAL( get_word_size_from_bitsize(288), 9 )
REQUIRE_EQUAL( get_word_size_from_bitsize(289), 10 )
REQUIRE_EQUAL( get_word_size_from_bitsize(320), 10 )
REQUIRE_EQUAL( get_word_size_from_bitsize(321), 11 )
REQUIRE_EQUAL( get_word_size_from_bitsize(352), 11 )
REQUIRE_EQUAL( get_word_size_from_bitsize(353), 12 )
REQUIRE_EQUAL( get_word_size_from_bitsize(383), 12 )
REQUIRE_EQUAL( get_word_size_from_bitsize(384), 12 )
REQUIRE_EQUAL( get_word_size_from_bitsize(385), 13 )
REQUIRE_EQUAL( get_word_size_from_bitsize(416), 13 )
REQUIRE_EQUAL( get_word_size_from_bitsize(417), 14 )
REQUIRE_EQUAL( get_word_size_from_bitsize(448), 14 )
REQUIRE_EQUAL( get_word_size_from_bitsize(449), 15 )
REQUIRE_EQUAL( get_word_size_from_bitsize(480), 15 )
REQUIRE_EQUAL( get_word_size_from_bitsize(481), 16 )
REQUIRE_EQUAL( get_word_size_from_bitsize(511), 16 )
REQUIRE_EQUAL( get_word_size_from_bitsize(512), 16 )
REQUIRE_EQUAL( get_word_size_from_bitsize(513), 17 )
REQUIRE_EQUAL( bitsize_to_wordsize(0), 0 )
REQUIRE_EQUAL( bitsize_to_wordsize(1), 1 )
REQUIRE_EQUAL( bitsize_to_wordsize(8), 1 )
REQUIRE_EQUAL( bitsize_to_wordsize(9), 1 )
REQUIRE_EQUAL( bitsize_to_wordsize(16), 1 )
REQUIRE_EQUAL( bitsize_to_wordsize(17), 1 )
REQUIRE_EQUAL( bitsize_to_wordsize(24), 1 )
REQUIRE_EQUAL( bitsize_to_wordsize(25), 1 )
REQUIRE_EQUAL( bitsize_to_wordsize(31), 1 )
REQUIRE_EQUAL( bitsize_to_wordsize(32), 1 )
REQUIRE_EQUAL( bitsize_to_wordsize(33), 2 )
REQUIRE_EQUAL( bitsize_to_wordsize(48), 2 )
REQUIRE_EQUAL( bitsize_to_wordsize(49), 2 )
REQUIRE_EQUAL( bitsize_to_wordsize(64), 2 )
REQUIRE_EQUAL( bitsize_to_wordsize(65), 3 )
REQUIRE_EQUAL( bitsize_to_wordsize(96), 3 )
REQUIRE_EQUAL( bitsize_to_wordsize(97), 4 )
REQUIRE_EQUAL( bitsize_to_wordsize(127), 4 )
REQUIRE_EQUAL( bitsize_to_wordsize(128), 4 )
REQUIRE_EQUAL( bitsize_to_wordsize(129), 5 )
REQUIRE_EQUAL( bitsize_to_wordsize(160), 5 )
REQUIRE_EQUAL( bitsize_to_wordsize(161), 6 )
REQUIRE_EQUAL( bitsize_to_wordsize(192), 6 )
REQUIRE_EQUAL( bitsize_to_wordsize(193), 7 )
REQUIRE_EQUAL( bitsize_to_wordsize(224), 7 )
REQUIRE_EQUAL( bitsize_to_wordsize(225), 8 )
REQUIRE_EQUAL( bitsize_to_wordsize(255), 8 )
REQUIRE_EQUAL( bitsize_to_wordsize(256), 8 )
REQUIRE_EQUAL( bitsize_to_wordsize(257), 9 )
REQUIRE_EQUAL( bitsize_to_wordsize(288), 9 )
REQUIRE_EQUAL( bitsize_to_wordsize(289), 10 )
REQUIRE_EQUAL( bitsize_to_wordsize(320), 10 )
REQUIRE_EQUAL( bitsize_to_wordsize(321), 11 )
REQUIRE_EQUAL( bitsize_to_wordsize(352), 11 )
REQUIRE_EQUAL( bitsize_to_wordsize(353), 12 )
REQUIRE_EQUAL( bitsize_to_wordsize(383), 12 )
REQUIRE_EQUAL( bitsize_to_wordsize(384), 12 )
REQUIRE_EQUAL( bitsize_to_wordsize(385), 13 )
REQUIRE_EQUAL( bitsize_to_wordsize(416), 13 )
REQUIRE_EQUAL( bitsize_to_wordsize(417), 14 )
REQUIRE_EQUAL( bitsize_to_wordsize(448), 14 )
REQUIRE_EQUAL( bitsize_to_wordsize(449), 15 )
REQUIRE_EQUAL( bitsize_to_wordsize(480), 15 )
REQUIRE_EQUAL( bitsize_to_wordsize(481), 16 )
REQUIRE_EQUAL( bitsize_to_wordsize(511), 16 )
REQUIRE_EQUAL( bitsize_to_wordsize(512), 16 )
REQUIRE_EQUAL( bitsize_to_wordsize(513), 17 )

// char
REQUIRE_EQUAL( get_word_size<char>(0), 0 )
Expand Down

0 comments on commit fcf0814

Please sign in to comment.