Verified Commit de873b19 authored by Alberto Miranda's avatar Alberto Miranda ♨️
Browse files

Rename: is_divisible() -> is_aligned()

parent 7048a3ed
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -43,7 +43,8 @@ log2(uint64_t n) {
}

/**
 * Check whether @n is divisible by @block_size.
 * Check whether @n is aligned to a block boundary, i.e. if it is divisible by
 * @block_size.
 *
 * @note This function assumes that block_size is a power of 2.
 *
@@ -52,7 +53,7 @@ log2(uint64_t n) {
 * @returns true if @n is divisible by @block_size; false otherwise.
 */
constexpr bool
is_divisible(const uint64_t n, const size_t block_size) {
is_aligned(const uint64_t n, const size_t block_size) {
    using gkfs::utils::arithmetic::log2;
    assert(is_power_of_2(block_size));
    return !(n & ((1u << log2(block_size)) - 1));
@@ -194,7 +195,7 @@ block_count(const uint64_t offset, const size_t size, const size_t block_size) {

    return (((final_block >> log2(block_size)) -
             (first_block >> log2(block_size)) +
             !is_divisible(offset + size, block_size))) &
             !is_aligned(offset + size, block_size))) &
           mask;
}

+2 −2
Original line number Diff line number Diff line
@@ -133,7 +133,7 @@ forward_write(const string& path, const void* buf, const bool append_flag,

        // receiver of last chunk must subtract
        if(target == chnk_end_target &&
           !is_divisible(offset + write_size, gkfs::config::rpc::chunksize)) {
           !is_aligned(offset + write_size, gkfs::config::rpc::chunksize)) {
            total_chunk_size -= block_underrun(offset + write_size,
                                               gkfs::config::rpc::chunksize);
        }
@@ -311,7 +311,7 @@ forward_read(const string& path, void* buf, const off64_t offset,

        // receiver of last chunk must subtract
        if(target == chnk_end_target &&
           !is_divisible(offset + read_size, gkfs::config::rpc::chunksize)) {
           !is_aligned(offset + read_size, gkfs::config::rpc::chunksize)) {
            total_chunk_size -= block_underrun(offset + read_size,
                                               gkfs::config::rpc::chunksize);
        }
+2 −2
Original line number Diff line number Diff line
@@ -97,7 +97,7 @@ SCENARIO(" powers of 2 can be correctly detected ",
}

SCENARIO(" divisibility by powers of 2 can be correctly detected ",
         "[utils][numeric][is_divisible]") {
         "[utils][numeric][is_aligned]") {

    GIVEN(" a number and a block_size ") {

@@ -110,7 +110,7 @@ SCENARIO(" divisibility by powers of 2 can be correctly detected ",
        CAPTURE(n, block_size);

        bool expected = n % block_size == 0;
        REQUIRE(is_divisible(n, block_size) == expected);
        REQUIRE(is_aligned(n, block_size) == expected);
    }
}