Added negation for single argument
This commit is contained in:
@@ -2,10 +2,27 @@
|
||||
#define _AL_FUNCTION_HPP
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
|
||||
#include <limits>
|
||||
#include <string>
|
||||
|
||||
|
||||
uint32_t ones = 0b11111111111111111111111111111111;
|
||||
|
||||
uint32_t mask_1 = 0b01010101010101010101010101010101;
|
||||
uint32_t remains_1 = 0b00000000000000000000000000000001;
|
||||
uint32_t shift_1 = 1;
|
||||
uint32_t mask_2 = 0b00110011001100110011001100110011;
|
||||
uint32_t remains_2 = 0b00000000000000000000000000000011;
|
||||
uint32_t shift_2 = 2;
|
||||
uint32_t mask_3 = 0b00001111000011110000111100001111;
|
||||
uint32_t remains_3 = 0b00000000000000000000000000001111;
|
||||
uint32_t shift_3 = 4;
|
||||
uint32_t mask_4 = 0b00000000111111110000000011111111;
|
||||
uint32_t remains_4 = 0b00000000000000000000000011111111;
|
||||
uint32_t shift_4 = 8;
|
||||
|
||||
template<class STORAGE, size_t VALUES_COUNT>
|
||||
class Function {
|
||||
public:
|
||||
@@ -59,6 +76,41 @@ class Function {
|
||||
return _function_values == other._function_values;
|
||||
}
|
||||
|
||||
Function var_negation(STORAGE var_index) {
|
||||
// var_index should be in 1..VARS_COUNT
|
||||
STORAGE mask, remains, shift;
|
||||
switch (var_index) {
|
||||
case 1:
|
||||
mask = mask_1;
|
||||
remains = remains_1;
|
||||
shift = shift_1;
|
||||
break;
|
||||
case 2:
|
||||
mask = mask_2;
|
||||
remains = remains_2;
|
||||
shift = shift_2;
|
||||
break;
|
||||
case 3:
|
||||
mask = mask_3;
|
||||
remains = remains_3;
|
||||
shift = shift_3;
|
||||
break;
|
||||
case 4:
|
||||
mask = mask_4;
|
||||
remains = remains_4;
|
||||
shift = shift_3;
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
|
||||
}
|
||||
|
||||
STORAGE first_part = (_function_values & (~mask)) >> shift;
|
||||
STORAGE second_part = (_function_values & mask) << shift;
|
||||
return Function(first_part | second_part);
|
||||
|
||||
}
|
||||
|
||||
STORAGE value() const {
|
||||
return _function_values;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user