I need to improve this section of code:
***********
uint32_t to_handle = 0;
uint32_t test_const1 = Constraint3::VAL1 + Constraint3::VAL2;
uint32_t test_const2 = Constraint1::VAL2 + Constraint1::VAL4 +
Constraint1::VAL8;
uint32_t test_const3 = Constraint2::VAL1 + Constraint2::VAL2 +
Constraint2::VAL4;
for(ConstraintsContainer_t::iterator it = constraints_.begin(); it !=
constraints_.end(); ++it) {
if( ( ((*it).get<0>() & to_handle) == (*it).get<0>() ) &&
( ((*it).get<1>() & test_const2) == (*it).get<1>() ) &&
( ((*it).get<2>() & test_const3) == (*it).get<2>() ) ) {
choosen_.push_back((*it));
to_handle -= (*it).get<0>();
}
}
***********
Here are declarations:
***********
namespace Constraint1 {
typedef enum {
NONE = 0x00000000,
VAL1 = 0x00000001,
VAL2 = 0x00000002,
VAL4 = 0x00000004,
VAL8 = 0x00000008,
ALL = 0xFFFFFFFF
} Type;
}
namespace Constraint2 {
typedef enum {
NONE = 0x00000000,
VAL1 = 0x00000001,
VAL2 = 0x00000002,
VAL4 = 0x00000004,
VAL8 = 0x00000008,
ALL = 0xFFFFFFFF
} Type;
}
namespace Constraint3 {
typedef enum {
NONE = 0x00000000,
VAL1 = 0x00000001,
VAL2 = 0x00000002,
VAL4 = 0x00000004,
VAL8 = 0x00000008,
VAL16 = 0x00000010,
VAL32 = 0x00000020,
ALL = 0xFFFFFFFF
} Type;
}
typedef std::vector<boost::tuple<uint32_t, uint32_t, uint32_t> >
ConstraintsContainer_t;
ConstraintsContainer_t constraints_;
***********
The goal is to select elements from a collection by performing a
bitwise and on them.
Order of insertion in that vector matters and number of element
should reach about 100. It's currently taking about 50 microseconds
to complete this section of codes, I'd need to make it 10-20
microseconds if possible.
Here is the source code on a live workspace if it helps:
http://coliru.stacked-crooked.com/view?id=356a9d8c94bddf6721f98bbc44c7
4fec-71380fc8ea55c1ab9f744d79fff5379c
I've tryed to use boost multi_index_containers, but it'd require to
get this to work:
http://stackoverflow.com/questions/16101886/boost-multi-index-containe
r-with-composite-key-and-logical-and-comparison
Any help is appreciated, thanks in advance!
--
[ See
http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]