CPLib.Bits
Defined in cp-library@0.15.3
ビット操作に関するユーティリティ
Values
namespace CPLib.Bits
bit_check
Type: [a : CPLib.Bits::Bits, a : Std::Eq, a : Std::One, a : Std::Zero] Std::I64 -> a -> Std::Bool
第iビットが立っているかを調べる
制約:0 <= i < ビット幅
Parameters
i: ビット位置x: 対象のビット列
bit_clear
Type: [a : CPLib.Bits::Bits, a : Std::One] Std::I64 -> a -> a
第iビットを消す
制約:0 <= i < ビット幅
Parameters
i: ビット位置x: 対象のビット列
bit_combinations
Type: Std::I64 -> Std::I64 -> CPLib.Bits::BitCombinationIterator
高々nビットの数のうち、ちょうどmビットが立っているものを昇順で列挙するイテレータ
制約:0 <= n <= 62
Parameters
n: ビット数m: 立っているビット数
Examples
assert_eq(|_|"", bit_combinations(3, 2).to_array, [0b011, 0b101, 0b110])
bit_flip
Type: [a : CPLib.Bits::Bits, a : Std::One] Std::I64 -> a -> a
第iビットを反転する
制約:0 <= i < ビット幅
Parameters
i: ビット位置x: 対象のビット列
bit_set
Type: [a : CPLib.Bits::Bits, a : Std::One] Std::I64 -> a -> a
第iビットを立てる
制約:0 <= i < ビット幅
Parameters
i: ビット位置x: 対象のビット列
bit_subsets
Type: Std::I64 -> CPLib.Bits::BitSubsetIterator
ビット列の部分集合を降順で列挙するイテレータ
全体集合から始まり、空集合までを列挙する
制約:set >= 0
Parameters
set: 全体集合
Examples
assert_eq(|_|"", bit_subsets(0b101).to_array, [0b101, 0b100, 0b001, 0b000])
to_string_bits
Type: [a : CPLib.Bits::Bits, a : Std::Eq, a : Std::One, a : Std::Zero] Std::I64 -> a -> Std::String
ビット列を0と1の文字列として表示する
制約:0 <= n <= ビット幅
Parameters
n: 下位からnビットのみを表示するx: 対象のビット列
namespace CPLib.Bits::Bits
and
Type: [a : CPLib.Bits::Bits] a -> a -> a
Trait member of CPLib.Bits::Bits
not
Type: [a : CPLib.Bits::Bits] a -> a
Trait member of CPLib.Bits::Bits
or
Type: [a : CPLib.Bits::Bits] a -> a -> a
Trait member of CPLib.Bits::Bits
popcount
Type: [a : CPLib.Bits::Bits] a -> Std::I64
Trait member of CPLib.Bits::Bits
ビット表現における1の個数を数える
Parameters
x: 対象のビット列
shl
Type: [a : CPLib.Bits::Bits] Std::I64 -> a -> a
Trait member of CPLib.Bits::Bits
shr
Type: [a : CPLib.Bits::Bits] Std::I64 -> a -> a
Trait member of CPLib.Bits::Bits
xor
Type: [a : CPLib.Bits::Bits] a -> a -> a
Trait member of CPLib.Bits::Bits
Types and aliases
namespace CPLib.Bits
BitCombinationIterator
Defined as: type BitCombinationIterator = unbox struct { ...fields... }
BitSubsetIterator
Defined as: type BitSubsetIterator = unbox struct { ...fields... }
Traits and aliases
namespace CPLib.Bits
trait a : Bits
method and
Type: a -> a -> a
method or
Type: a -> a -> a
method xor
Type: a -> a -> a
method not
Type: a -> a
method shl
Type: Std::I64 -> a -> a
method shr
Type: Std::I64 -> a -> a
method popcount
Type: a -> Std::I64
ビット表現における1の個数を数える
Parameters
x: 対象のビット列