Class: Aerospike::Exp::Bit
- Inherits:
-
Object
- Object
- Aerospike::Exp::Bit
- Defined in:
- lib/aerospike/exp/exp_bit.rb
Overview
Bit expression generator. See Aerospike::Exp.
The bin expression argument in these methods can be a reference to a bin or the result of another expression. Expressions that modify bin values are only used for temporary expression evaluation and are not permanently applied to the bin. Bit modify expressions the blob bin’s value.
Offset orientation is left-to-right. Negative offsets are supported. If the offset is negative, the offset starts backwards from end of the bitmap. If an offset is out of bounds, a parameter error will be returned.
Class Method Summary collapse
-
.add(bit_offset, bit_size, value, signed, bit_overflow_action, bin, policy: CDT::BitPolicy::DEFAULT) ⇒ Object
Create expression that adds value to byte[] bin starting at bit_offset for bit_size and returns byte[].
-
.and(bit_offset, bit_size, value, bin, policy: CDT::BitPolicy::DEFAULT) ⇒ Object
Create expression that performs bitwise “and” on value and byte[] bin at bit_offset for bit_size and returns byte[].
-
.count(bit_offset, bit_size, bin) ⇒ Object
Create expression that returns integer count of set bits from byte[] bin starting at bit_offset for bit_size.
-
.get(bit_offset, bit_size, bin) ⇒ Object
Create expression that returns bits from byte[] bin starting at bit_offset for bit_size.
-
.get_int(bit_offset, bit_size, signed, bin) ⇒ Object
Create expression that returns integer from byte[] bin starting at bit_offset for bit_size.
-
.insert(byte_offset, value, bin, policy: CDT::BitPolicy::DEFAULT) ⇒ Object
Create expression that inserts value bytes into byte[] bin at byte_offset and returns byte[].
-
.lscan(bit_offset, bit_size, value, bin) ⇒ Object
Create expression that returns integer bit offset of the first specified value bit in byte[] bin starting at bit_offset for bit_size.
-
.lshift(bit_offset, bit_size, shift, bin, policy: CDT::BitPolicy::DEFAULT) ⇒ Object
Create expression that shifts left byte[] bin starting at bit_offset for bit_size and returns byte[].
-
.not(bit_offset, bit_size, bin, policy: CDT::BitPolicy::DEFAULT) ⇒ Object
Create expression that negates byte[] bin starting at bit_offset for bit_size and returns byte[].
-
.or(bit_offset, bit_size, value, bin, policy: CDT::BitPolicy::DEFAULT) ⇒ Object
Create expression that performs bitwise “or” on value and byte[] bin at bit_offset for bit_size and returns byte[].
-
.remove(byte_offset, byte_size, bin, policy: CDT::BitPolicy::DEFAULT) ⇒ Object
Create expression that removes bytes from byte[] bin at byte_offset for byte_size and returns byte[].
-
.resize(byte_size, resize_flags, bin, policy: CDT::BitPolicy::DEFAULT) ⇒ Object
Create expression that resizes byte[] to byte_size according to resize_flags (See CDT::BitResizeFlags) and returns byte[].
-
.rscan(bit_offset, bit_size, value, bin) ⇒ Object
Create expression that returns integer bit offset of the last specified value bit in byte[] bin starting at bit_offset for bit_size.
-
.rshift(bit_offset, bit_size, shift, bin, policy: CDT::BitPolicy::DEFAULT) ⇒ Object
Create expression that shifts right byte[] bin starting at bit_offset for bit_size and returns byte[].
-
.set(bit_offset, bit_size, value, bin, policy: CDT::BitPolicy::DEFAULT) ⇒ Object
Create expression that sets value on byte[] bin at bit_offset for bit_size and returns byte[].
-
.set_int(bit_offset, bit_size, value, bin, policy: CDT::BitPolicy::DEFAULT) ⇒ Object
Create expression that sets value to byte[] bin starting at bit_offset for bit_size and returns byte[].
-
.subtract(bit_offset, bit_size, value, signed, bit_overflow_action, bin, policy: CDT::BitPolicy::DEFAULT) ⇒ Object
Create expression that subtracts value from byte[] bin starting at bit_offset for bit_size and returns byte[].
-
.xor(bit_offset, bit_size, value, bin, policy: CDT::BitPolicy::DEFAULT) ⇒ Object
Create expression that performs bitwise “xor” on value and byte[] bin at bit_offset for bit_size and returns byte[].
Class Method Details
.add(bit_offset, bit_size, value, signed, bit_overflow_action, bin, policy: CDT::BitPolicy::DEFAULT) ⇒ Object
Create expression that adds value to byte[] bin starting at bit_offset for bit_size and returns byte[]. BitSize must be <= 64. Signed indicates if bits should be treated as a signed number. If add overflows/underflows, BitOverflowAction is used.
bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101] bit_offset = 24 bit_size = 16 value = 128 signed = false bin result = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b10000101]
194 195 196 197 |
# File 'lib/aerospike/exp/exp_bit.rb', line 194 def self.add(bit_offset, bit_size, value, signed, bit_overflow_action, bin, policy: CDT::BitPolicy::DEFAULT) bytes = pack_math(ADD, policy, bit_offset, bit_size, value, signed, bit_overflow_action) add_write(bin, bytes) end |
.and(bit_offset, bit_size, value, bin, policy: CDT::BitPolicy::DEFAULT) ⇒ Object
Create expression that performs bitwise “and” on value and byte[] bin at bit_offset for bit_size and returns byte[].
bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101] bit_offset = 23 bit_size = 9 value = [0b00111100, 0b10000000] bin result = [0b00000001, 0b01000010, 0b00000010, 0b00000000, 0b00000101]
140 141 142 143 |
# File 'lib/aerospike/exp/exp_bit.rb', line 140 def self.and(bit_offset, bit_size, value, bin, policy: CDT::BitPolicy::DEFAULT) bytes = Exp.pack(nil, AND, bit_offset, bit_size, value, policy.flags) add_write(bin, bytes) end |
.count(bit_offset, bit_size, bin) ⇒ Object
Create expression that returns integer count of set bits from byte[] bin starting at bit_offset for bit_size.
bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101] bit_offset = 20 bit_size = 4 returns 2
Examples
# Bin "a" bit count <= 2
Exp.le(BitExp.count(Exp.val(0), Exp.val(5), Exp.blobBin("a")), Exp.val(2))
257 258 259 260 |
# File 'lib/aerospike/exp/exp_bit.rb', line 257 def self.count(bit_offset, bit_size, bin) bytes = Exp.pack(nil, COUNT, bit_offset, bit_size) add_read(bin, bytes, Exp::Type::INT) end |
.get(bit_offset, bit_size, bin) ⇒ Object
Create expression that returns bits from byte[] bin starting at bit_offset for bit_size.
bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101] bit_offset = 9 bit_size = 5 returns [0b10000000]
Examples
# Bin "a" bits = [0b10000000]
Exp.eq(
BitExp.get(Exp.val(9), Exp.val(5), Exp.blobBin("a")),
Exp.val(new byte[] {(byte)0b10000000}))
241 242 243 244 |
# File 'lib/aerospike/exp/exp_bit.rb', line 241 def self.get(bit_offset, bit_size, bin) bytes = Exp.pack(nil, GET, bit_offset, bit_size) add_read(bin, bytes, Exp::Type::BLOB) end |
.get_int(bit_offset, bit_size, signed, bin) ⇒ Object
Create expression that returns integer from byte[] bin starting at bit_offset for bit_size. Signed indicates if bits should be treated as a signed number.
bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101] bit_offset = 8 bit_size = 16 signed = false returns 16899
Examples
# getInt(a) == 16899
Exp.eq(BitExp.getInt(Exp.val(8), Exp.val(16), false, Exp.blobBin("a")), Exp.val(16899))
319 320 321 322 |
# File 'lib/aerospike/exp/exp_bit.rb', line 319 def self.get_int(bit_offset, bit_size, signed, bin) bytes = pack_get_int(bit_offset, bit_size, signed) add_read(bin, bytes, Exp::Type::INT) end |
.insert(byte_offset, value, bin, policy: CDT::BitPolicy::DEFAULT) ⇒ Object
Create expression that inserts value bytes into byte[] bin at byte_offset and returns byte[].
bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101] byte_offset = 1 value = [0b11111111, 0b11000111] bin result = [0b00000001, 0b11111111, 0b11000111, 0b01000010, 0b00000011, 0b00000100, 0b00000101]
Examples
# Insert bytes into bin "a" and compare bit count
Exp.eq(
BitExp.count(Exp.val(0), Exp.val(3),
BitExp.insert(BitPolicy.Default, Exp.val(1), Exp.val(bytes), Exp.blobBin("a"))),
Exp.val(2))
61 62 63 64 |
# File 'lib/aerospike/exp/exp_bit.rb', line 61 def self.insert(byte_offset, value, bin, policy: CDT::BitPolicy::DEFAULT) bytes = Exp.pack(nil, INSERT, byte_offset, value, policy.flags) add_write(bin, bytes) end |
.lscan(bit_offset, bit_size, value, bin) ⇒ Object
Create expression that returns integer bit offset of the first specified value bit in byte[] bin starting at bit_offset for bit_size.
bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101] bit_offset = 24 bit_size = 8 value = true returns 5
Examples
# lscan(a) == 5
Exp.eq(BitExp.lscan(Exp.val(24), Exp.val(8), Exp.val(true), Exp.blobBin("a")), Exp.val(5))
279 280 281 282 |
# File 'lib/aerospike/exp/exp_bit.rb', line 279 def self.lscan(bit_offset, bit_size, value, bin) bytes = Exp.pack(nil, LSCAN, bit_offset, bit_size, value) add_read(bin, bytes, Exp::Type::INT) end |
.lshift(bit_offset, bit_size, shift, bin, policy: CDT::BitPolicy::DEFAULT) ⇒ Object
Create expression that shifts left byte[] bin starting at bit_offset for bit_size and returns byte[].
bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101] bit_offset = 32 bit_size = 8 shift = 3 bin result = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00101000]
165 166 167 168 |
# File 'lib/aerospike/exp/exp_bit.rb', line 165 def self.lshift(bit_offset, bit_size, shift, bin, policy: CDT::BitPolicy::DEFAULT) bytes = Exp.pack(nil, LSHIFT, bit_offset, bit_size, shift, policy.flags) add_write(bin, bytes) end |
.not(bit_offset, bit_size, bin, policy: CDT::BitPolicy::DEFAULT) ⇒ Object
Create expression that negates byte[] bin starting at bit_offset for bit_size and returns byte[].
bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101] bit_offset = 25 bit_size = 6 bin result = [0b00000001, 0b01000010, 0b00000011, 0b01111010, 0b00000101]
152 153 154 155 |
# File 'lib/aerospike/exp/exp_bit.rb', line 152 def self.not(bit_offset, bit_size, bin, policy: CDT::BitPolicy::DEFAULT) bytes = Exp.pack(nil, NOT, bit_offset, bit_size, policy.flags) add_write(bin, bytes) end |
.or(bit_offset, bit_size, value, bin, policy: CDT::BitPolicy::DEFAULT) ⇒ Object
Create expression that performs bitwise “or” on value and byte[] bin at bit_offset for bit_size and returns byte[].
bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101] bit_offset = 17 bit_size = 6 value = [0b10101000] bin result = [0b00000001, 0b01000010, 0b01010111, 0b00000100, 0b00000101]
112 113 114 115 |
# File 'lib/aerospike/exp/exp_bit.rb', line 112 def self.or(bit_offset, bit_size, value, bin, policy: CDT::BitPolicy::DEFAULT) bytes = Exp.pack(nil, OR, bit_offset, bit_size, value, policy.flags) add_write(bin, bytes) end |
.remove(byte_offset, byte_size, bin, policy: CDT::BitPolicy::DEFAULT) ⇒ Object
Create expression that removes bytes from byte[] bin at byte_offset for byte_size and returns byte[].
bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101] byte_offset = 2 byte_size = 3 bin result = [0b00000001, 0b01000010]
Examples
# Remove bytes from bin "a" and compare bit count
Exp.eq(
BitExp.count(Exp.val(0), Exp.val(3),
BitExp.remove(BitPolicy.Default, Exp.val(2), Exp.val(3), Exp.blobBin("a"))),
Exp.val(2))
79 80 81 82 |
# File 'lib/aerospike/exp/exp_bit.rb', line 79 def self.remove(byte_offset, byte_size, bin, policy: CDT::BitPolicy::DEFAULT) bytes = Exp.pack(nil, REMOVE, byte_offset, byte_size, policy.flags) add_write(bin, bytes) end |
.resize(byte_size, resize_flags, bin, policy: CDT::BitPolicy::DEFAULT) ⇒ Object
Create expression that resizes byte[] to byte_size according to resize_flags (See CDT::BitResizeFlags) and returns byte[].
bin = [0b00000001, 0b01000010]
byte_size = 4
resize_flags = 0
returns [0b00000001, 0b01000010, 0b00000000, 0b00000000]
Examples
# Resize bin "a" and compare bit count
Exp.eq(
BitExp.count(Exp.val(0), Exp.val(3),
BitExp.resize(BitPolicy.Default, Exp.val(4), 0, Exp.blobBin("a"))),
Exp.val(2))
43 44 45 46 |
# File 'lib/aerospike/exp/exp_bit.rb', line 43 def self.resize(byte_size, resize_flags, bin, policy: CDT::BitPolicy::DEFAULT) bytes = Exp.pack(nil, RESIZE, byte_size, policy.flags, resize_flags) add_write(bin, bytes) end |
.rscan(bit_offset, bit_size, value, bin) ⇒ Object
Create expression that returns integer bit offset of the last specified value bit in byte[] bin starting at bit_offset for bit_size. Example:
bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101] bit_offset = 32 bit_size = 8 value = true returns 7
Examples
# rscan(a) == 7
Exp.eq(BitExp.rscan(Exp.val(32), Exp.val(8), Exp.val(true), Exp.blobBin("a")), Exp.val(7))
302 303 304 305 |
# File 'lib/aerospike/exp/exp_bit.rb', line 302 def self.rscan(bit_offset, bit_size, value, bin) bytes = Exp.pack(nil, RSCAN, bit_offset, bit_size, value) add_read(bin, bytes, Exp::Type::INT) end |
.rshift(bit_offset, bit_size, shift, bin, policy: CDT::BitPolicy::DEFAULT) ⇒ Object
Create expression that shifts right byte[] bin starting at bit_offset for bit_size and returns byte[].
bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101] bit_offset = 0 bit_size = 9 shift = 1 bin result = [0b00000000, 0b11000010, 0b00000011, 0b00000100, 0b00000101]
178 179 180 181 |
# File 'lib/aerospike/exp/exp_bit.rb', line 178 def self.rshift(bit_offset, bit_size, shift, bin, policy: CDT::BitPolicy::DEFAULT) bytes = Exp.pack(nil, RSHIFT, bit_offset, bit_size, shift, policy.flags) add_write(bin, bytes) end |
.set(bit_offset, bit_size, value, bin, policy: CDT::BitPolicy::DEFAULT) ⇒ Object
Create expression that sets value on byte[] bin at bit_offset for bit_size and returns byte[].
bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101] bit_offset = 13 bit_size = 3 value = [0b11100000] bin result = [0b00000001, 0b01000111, 0b00000011, 0b00000100, 0b00000101]
Examples
# Set bytes in bin "a" and compare bit count
Exp.eq(
BitExp.count(Exp.val(0), Exp.val(3),
BitExp.set(BitPolicy.Default, Exp.val(13), Exp.val(3), Exp.val(bytes), Exp.blobBin("a"))),
Exp.val(2))
98 99 100 101 |
# File 'lib/aerospike/exp/exp_bit.rb', line 98 def self.set(bit_offset, bit_size, value, bin, policy: CDT::BitPolicy::DEFAULT) bytes = Exp.pack(nil, SET, bit_offset, bit_size, value, policy.flags) add_write(bin, bytes) end |
.set_int(bit_offset, bit_size, value, bin, policy: CDT::BitPolicy::DEFAULT) ⇒ Object
Create expression that sets value to byte[] bin starting at bit_offset for bit_size and returns byte[]. BitSize must be <= 64.
bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101] bit_offset = 1 bit_size = 8 value = 127 bin result = [0b00111111, 0b11000010, 0b00000011, 0b0000100, 0b00000101]
224 225 226 227 |
# File 'lib/aerospike/exp/exp_bit.rb', line 224 def self.set_int(bit_offset, bit_size, value, bin, policy: CDT::BitPolicy::DEFAULT) bytes = Exp.pack(nil, SET_INT, bit_offset, bit_size, value, policy.flags) add_write(bin, bytes) end |
.subtract(bit_offset, bit_size, value, signed, bit_overflow_action, bin, policy: CDT::BitPolicy::DEFAULT) ⇒ Object
Create expression that subtracts value from byte[] bin starting at bit_offset for bit_size and returns byte[]. BitSize must be <= 64. Signed indicates if bits should be treated as a signed number. If add overflows/underflows, BitOverflowAction is used.
bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101] bit_offset = 24 bit_size = 16 value = 128 signed = false bin result = [0b00000001, 0b01000010, 0b00000011, 0b0000011, 0b10000101]
210 211 212 213 |
# File 'lib/aerospike/exp/exp_bit.rb', line 210 def self.subtract(bit_offset, bit_size, value, signed, bit_overflow_action, bin, policy: CDT::BitPolicy::DEFAULT) bytes = pack_math(SUBTRACT, policy, bit_offset, bit_size, value, signed, bit_overflow_action) add_write(bin, bytes) end |
.xor(bit_offset, bit_size, value, bin, policy: CDT::BitPolicy::DEFAULT) ⇒ Object
Create expression that performs bitwise “xor” on value and byte[] bin at bit_offset for bit_size and returns byte[].
bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101] bit_offset = 17 bit_size = 6 value = [0b10101100] bin result = [0b00000001, 0b01000010, 0b01010101, 0b00000100, 0b00000101]
126 127 128 129 |
# File 'lib/aerospike/exp/exp_bit.rb', line 126 def self.xor(bit_offset, bit_size, value, bin, policy: CDT::BitPolicy::DEFAULT) bytes = Exp.pack(nil, XOR, bit_offset, bit_size, value, policy.flags) add_write(bin, bytes) end |