ton3-core
Version:
TON low-level API tools
38 lines • 1.04 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Mask = void 0;
class Mask {
constructor(mask) {
this._value = mask instanceof Mask
? mask.value
: mask;
this._hashIndex = Mask.countSetBits(this._value);
this._hashCount = this._hashIndex + 1;
}
get value() {
return this._value;
}
get level() {
return 32 - Math.clz32(this._value);
}
get hashIndex() {
return this._hashIndex;
}
get hashCount() {
return this._hashCount;
}
isSignificant(level) {
const result = level === 0 || (this._value >> (level - 1)) % 2 !== 0;
return result;
}
apply(level) {
return new Mask(this._value & ((1 << level) - 1));
}
static countSetBits(n) {
n = n - ((n >> 1) & 0x55555555);
n = (n & 0x33333333) + ((n >> 2) & 0x33333333);
return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
}
}
exports.Mask = Mask;
//# sourceMappingURL=mask.js.map