import { assert } from "../assert.js";

/**
 *
 * @param {number} a_offset
 * @param {number} b_offset
 * @param {number} byte_length
 * @returns {number}
 */
export function largest_common_alignment_uint32(a_offset, b_offset, byte_length) {

    assert.isNonNegativeInteger(a_offset, 'a_offset');
    assert.isNonNegativeInteger(b_offset, 'b_offset');
    assert.isNonNegativeInteger(byte_length, 'length');

    const mask = a_offset | b_offset | byte_length;

    if ((mask & 3) === 0) {
        // aligned on 4-byte boundary
        return 4
    } else if ((mask & 1) === 0) {
        // aligned on 2-byte boundary
        return 2;
    } else {
        // worst-case, assume 1-byte boundary
        return 1;
    }
}

