From a3c57a5077e824f33d7320a3fd68bb5e9529a2f4 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Wed, 2 Mar 2016 18:11:33 -0500 Subject: [PATCH] bitSet: add logical_and()/_or() Basic logical operations for tests where a temporary can be avoided. --- src/misc/bitSet.cpp | 14 ++++++++++++++ src/misc/pv/bitSet.h | 11 ++++++++--- testApp/misc/testBitSet.cpp | 26 +++++++++++++++++++++++++- 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/src/misc/bitSet.cpp b/src/misc/bitSet.cpp index 596ad11..930b470 100644 --- a/src/misc/bitSet.cpp +++ b/src/misc/bitSet.cpp @@ -196,6 +196,20 @@ namespace epics { namespace pvData { return words.size() * BITS_PER_WORD; } + bool BitSet::logical_and(const BitSet& set) const + { + size_t nwords = std::min(words.size(), set.words.size()); + for(size_t i=0; iAND of this target bit set with the + * Performs a bitwise AND of this target bit set with the * argument bit set. This bit set is modified so that each bit in it * has the value @c true if and only if it both initially * had the value @c true and the corresponding bit in the @@ -179,7 +184,7 @@ namespace epics { namespace pvData { BitSet& operator&=(const BitSet& set); /** - * Performs a logical OR of this bit set with the bit set + * Performs a bitwise OR of this bit set with the bit set * argument. This bit set is modified so that a bit in it has the * value @c true if and only if it either already had the * value @c true or the corresponding bit in the bit set @@ -190,7 +195,7 @@ namespace epics { namespace pvData { BitSet& operator|=(const BitSet& set); /** - * Performs a logical XOR of this bit set with the bit set + * Performs a bitwise XOR of this bit set with the bit set * argument. This bit set is modified so that a bit in it has the * value @c true if and only if one of the following * statements holds: diff --git a/testApp/misc/testBitSet.cpp b/testApp/misc/testBitSet.cpp index a44591d..5370699 100644 --- a/testApp/misc/testBitSet.cpp +++ b/testApp/misc/testBitSet.cpp @@ -164,6 +164,29 @@ static void testOperators() testOk(toString(b3) == "{1}", "%s == {1}", toString(b3).c_str()); } +static void testLogical() +{ + BitSet A, B; + + testOk1(!A.logical_and(B)); + testOk1(!A.logical_or(B)); + + A.set(41); + + testOk1(!A.logical_and(B)); + testOk1(A.logical_or(B)); + + A.set(42); + + testOk1(!A.logical_and(B)); + testOk1(A.logical_or(B)); + + B.set(41); + + testOk1(A.logical_and(B)); + testOk1(A.logical_or(B)); +} + static void tofrostring(const BitSet& in, const char *expect, size_t elen, int byteOrder) { { @@ -271,9 +294,10 @@ static void testSerialize() MAIN(testBitSet) { - testPlan(79); + testPlan(87); testGetSetClearFlip(); testOperators(); + testLogical(); testSerialize(); return testDone(); }