54 lines
1.5 KiB
Go
54 lines
1.5 KiB
Go
package engine
|
|
|
|
// bitAnd 按位与
|
|
// 支持多个操作数,返回所有操作数按位与的结果
|
|
func (e *AggregationEngine) bitAnd(operand interface{}, data map[string]interface{}) int64 {
|
|
arr, ok := operand.([]interface{})
|
|
if !ok || len(arr) < 2 {
|
|
return 0
|
|
}
|
|
|
|
result := toInt64(e.evaluateExpression(data, arr[0]))
|
|
for i := 1; i < len(arr); i++ {
|
|
result &= toInt64(e.evaluateExpression(data, arr[i]))
|
|
}
|
|
return result
|
|
}
|
|
|
|
// bitOr 按位或
|
|
// 支持多个操作数,返回所有操作数按位或的结果
|
|
func (e *AggregationEngine) bitOr(operand interface{}, data map[string]interface{}) int64 {
|
|
arr, ok := operand.([]interface{})
|
|
if !ok || len(arr) < 2 {
|
|
return 0
|
|
}
|
|
|
|
result := toInt64(e.evaluateExpression(data, arr[0]))
|
|
for i := 1; i < len(arr); i++ {
|
|
result |= toInt64(e.evaluateExpression(data, arr[i]))
|
|
}
|
|
return result
|
|
}
|
|
|
|
// bitXor 按位异或
|
|
// 支持多个操作数,返回所有操作数按位异或的结果
|
|
func (e *AggregationEngine) bitXor(operand interface{}, data map[string]interface{}) int64 {
|
|
arr, ok := operand.([]interface{})
|
|
if !ok || len(arr) < 2 {
|
|
return 0
|
|
}
|
|
|
|
result := toInt64(e.evaluateExpression(data, arr[0]))
|
|
for i := 1; i < len(arr); i++ {
|
|
result ^= toInt64(e.evaluateExpression(data, arr[i]))
|
|
}
|
|
return result
|
|
}
|
|
|
|
// bitNot 按位非
|
|
// 一元操作符,返回操作数的按位非
|
|
func (e *AggregationEngine) bitNot(operand interface{}, data map[string]interface{}) int64 {
|
|
val := toInt64(e.evaluateExpression(data, operand))
|
|
return ^val
|
|
}
|