summaryrefslogtreecommitdiff
path: root/sfx2
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2016-01-11 14:33:00 +0100
committerStephan Bergmann <sbergman@redhat.com>2016-01-11 14:33:00 +0100
commit753b516cae68a5ac09c6389b9e8cd8a52e40ae11 (patch)
treeadbb42ed5459889e261004a2a9376aedfc6a4347 /sfx2
parent3ee66e306cf0ca9c2b56de26c28e8130d7b72f64 (diff)
Merge BitSet into IndexBitSet (and remove unused parts)
Change-Id: I8cab0aac2f67b88936e4bed459dd43b08429b136
Diffstat (limited to 'sfx2')
-rw-r--r--sfx2/inc/bitset.hxx126
-rw-r--r--sfx2/source/bastyp/bitset.cxx215
2 files changed, 20 insertions, 321 deletions
diff --git a/sfx2/inc/bitset.hxx b/sfx2/inc/bitset.hxx
index 67651e1a15bc..d3f3b281ca1f 100644
--- a/sfx2/inc/bitset.hxx
+++ b/sfx2/inc/bitset.hxx
@@ -19,131 +19,27 @@
#ifndef INCLUDED_SFX2_INC_BITSET_HXX
#define INCLUDED_SFX2_INC_BITSET_HXX
-class BitSet
+class IndexBitSet
{
private:
- void CopyFrom( const BitSet& rSet );
sal_uInt16 nBlocks;
sal_uInt16 nCount;
sal_uInt32* pBitmap;
-public:
- BitSet operator<<( sal_uInt16 nOffset ) const;
- BitSet operator>>( sal_uInt16 nOffset ) const;
- static sal_uInt16 CountBits(sal_uInt32 nBits);
- bool operator!() const;
- BitSet();
- BitSet( const BitSet& rOrig );
- ~BitSet();
- BitSet& operator=( const BitSet& rOrig );
- BitSet& operator=( sal_uInt16 nBit );
- BitSet operator|( const BitSet& rSet ) const;
- BitSet operator|( sal_uInt16 nBit ) const;
- BitSet& operator|=( const BitSet& rSet );
- BitSet& operator|=( sal_uInt16 nBit );
- BitSet operator-( const BitSet& rSet ) const;
- BitSet operator-( sal_uInt16 nId ) const;
- BitSet& operator-=( const BitSet& rSet );
- BitSet& operator-=( sal_uInt16 nBit );
- BitSet operator&( const BitSet& rSet ) const;
- BitSet& operator&=( const BitSet& rSet );
- BitSet operator^( const BitSet& rSet ) const;
- BitSet operator^( sal_uInt16 nBit ) const;
- BitSet& operator^=( const BitSet& rSet );
- BitSet& operator^=( sal_uInt16 nBit );
- bool Contains( sal_uInt16 nBit ) const;
- bool operator==( const BitSet& rSet ) const;
- bool operator!=( const BitSet& rSet ) const;
-};
-
-// returns sal_True if the set is empty
-inline bool BitSet::operator!() const
-{
- return nCount == 0;
-}
-
-// creates the union of two bitset
-inline BitSet BitSet::operator|( const BitSet& rSet ) const
-{
- return BitSet(*this) |= rSet;
-}
-
-// creates the union of a bitset with a single bit
-inline BitSet BitSet::operator|( sal_uInt16 nBit ) const
-{
- return BitSet(*this) |= nBit;
-}
-
-// creates the asymetric difference
-inline BitSet BitSet::operator-( const BitSet& ) const
-{
- return BitSet();
-}
-
-// creates the asymetric difference with a single bit
-inline BitSet BitSet::operator-( sal_uInt16 ) const
-{
- return BitSet();
-}
-
-// removes the bits contained in rSet
-inline BitSet& BitSet::operator-=( const BitSet& )
-{
- return *this;
-}
-
-// creates the intersection with another bitset
-inline BitSet BitSet::operator&( const BitSet& ) const
-{
- return BitSet();
-}
-
-// intersects with another bitset
-inline BitSet& BitSet::operator&=( const BitSet& )
-{
- return *this;
-}
-
-// creates the symetric difference with another bitset
-inline BitSet BitSet::operator^( const BitSet& ) const
-{
- return BitSet();
-}
-
-// creates the symetric difference with a single bit
-inline BitSet BitSet::operator^( sal_uInt16 ) const
-{
- return BitSet();
-}
-
-// builds the symetric difference with another bitset
-inline BitSet& BitSet::operator^=( const BitSet& )
-{
- return *this;
-}
-
-#ifdef BITSET_READY
-// builds the symetric difference with a single bit
-inline BitSet& BitSet::operator^=( sal_uInt16 )
-{
- // crash!!!
- return BitSet();
-}
-#endif
+ IndexBitSet& operator|=( sal_uInt16 nBit );
+ IndexBitSet& operator-=( sal_uInt16 nBit );
+ bool Contains( sal_uInt16 nBit ) const;
-// determines if the bitsets aren't equal
-inline bool BitSet::operator!=( const BitSet& rSet ) const
-{
- return !( *this == rSet );
-}
+ IndexBitSet(IndexBitSet &) = delete;
+ void operator =(IndexBitSet) = delete;
-class IndexBitSet : private BitSet
-{
public:
- sal_uInt16 GetFreeIndex();
- void ReleaseIndex(sal_uInt16 i){*this-=i;}
-};
+ IndexBitSet();
+ ~IndexBitSet();
+ sal_uInt16 GetFreeIndex();
+ void ReleaseIndex(sal_uInt16 i){*this-=i;}
+};
#endif
diff --git a/sfx2/source/bastyp/bitset.cxx b/sfx2/source/bastyp/bitset.cxx
index c36de4977ac5..39cba96d7cd5 100644
--- a/sfx2/source/bastyp/bitset.cxx
+++ b/sfx2/source/bastyp/bitset.cxx
@@ -23,151 +23,10 @@
#include <string.h>
#include <limits.h>
-#include <algorithm>
-
-
-// add nOffset to each bit-value in the set
-
-BitSet BitSet::operator<<( sal_uInt16 nOffset ) const
-{
- // create a work-copy, return it if nothing to shift
- BitSet aSet(*this);
- if ( nOffset == 0 )
- return aSet;
-
- // compute the shiftment in long-words and bits
- sal_uInt16 nBlockDiff = nOffset / 32;
- sal_uInt32 nBitValDiff = nOffset % 32;
-
- // compute the new number of bits
- for ( sal_uInt16 nBlock = 0; nBlock < nBlockDiff; ++nBlock )
- aSet.nCount = aSet.nCount - CountBits( *(aSet.pBitmap+nBlock) );
- aSet.nCount = aSet.nCount -
- CountBits( *(aSet.pBitmap+nBlockDiff) >> (32-nBitValDiff) );
-
- // shift complete long-words
- sal_uInt16 nTarget, nSource;
- for ( nTarget = 0, nSource = nBlockDiff;
- (nSource+1) < aSet.nBlocks;
- ++nTarget, ++nSource )
- *(aSet.pBitmap+nTarget) =
- ( *(aSet.pBitmap+nSource) << nBitValDiff ) |
- ( *(aSet.pBitmap+nSource+1) >> (32-nBitValDiff) );
-
- // shift the remainder (if in total minor 32 bits, only this)
- *(aSet.pBitmap+nTarget) = *(aSet.pBitmap+nSource) << nBitValDiff;
-
- // determine the last used block
- while ( *(aSet.pBitmap+nTarget) == 0 )
- --nTarget;
-
- // shorten the block-array
- if ( nTarget < aSet.nBlocks )
- {
- sal_uInt32* pNewMap = new sal_uInt32[nTarget];
- memcpy( pNewMap, aSet.pBitmap, 4 * nTarget );
- delete [] aSet.pBitmap;
- aSet.pBitmap = pNewMap;
- aSet.nBlocks = nTarget;
- }
-
- return aSet;
-}
-
-
-
-// subtracts nOffset from each bit-value in the set
-
-BitSet BitSet::operator>>( sal_uInt16 ) const
-{
- return BitSet();
-}
-
-
-
-// internal code for operator= and copy-ctor
-
-void BitSet::CopyFrom( const BitSet& rSet )
-{
- nCount = rSet.nCount;
- nBlocks = rSet.nBlocks;
- if ( rSet.nBlocks )
- {
- pBitmap = new sal_uInt32[nBlocks];
- memcpy( pBitmap, rSet.pBitmap, 4 * nBlocks );
- }
- else
- pBitmap = nullptr;
-}
-
-
-
-// creates an empty bitset
-
-BitSet::BitSet()
-{
- nCount = 0;
- nBlocks = 0;
- pBitmap = nullptr;
-}
-
-
-
-// creates a copy of bitset rOrig
-
-BitSet::BitSet( const BitSet& rOrig )
-{
- CopyFrom(rOrig);
-}
-
-
-
-// frees the storage
-
-BitSet::~BitSet()
-{
- delete [] pBitmap;
-}
-
-
-
-// assignment from another bitset
-
-BitSet& BitSet::operator=( const BitSet& rOrig )
-{
- if ( this != &rOrig )
- {
- delete [] pBitmap;
- CopyFrom(rOrig);
- }
- return *this;
-}
-
-
-
-// assignment from a single bit
-
-BitSet& BitSet::operator=( sal_uInt16 nBit )
-{
- delete [] pBitmap;
-
- nBlocks = nBit / 32;
- sal_uInt32 nBitVal = 1L << (nBit % 32);
- nCount = 1;
-
- pBitmap = new sal_uInt32[nBlocks + 1];
- memset( pBitmap, 0, 4 * (nBlocks + 1) );
-
- *(pBitmap+nBlocks) = nBitVal;
-
- return *this;
-}
-
-
// creates the asymetric difference with another bitset
-BitSet& BitSet::operator-=(sal_uInt16 nBit)
+IndexBitSet& IndexBitSet::operator-=(sal_uInt16 nBit)
{
sal_uInt16 nBlock = nBit / 32;
sal_uInt32 nBitVal = 1L << (nBit % 32);
@@ -184,47 +43,9 @@ BitSet& BitSet::operator-=(sal_uInt16 nBit)
return *this;
}
-
-
-// unites with the bits of rSet
-
-BitSet& BitSet::operator|=( const BitSet& rSet )
-{
- sal_uInt16 nMax = std::min(nBlocks, rSet.nBlocks);
-
- // expand the bitmap
- if ( nBlocks < rSet.nBlocks )
- {
- sal_uInt32 *pNewMap = new sal_uInt32[rSet.nBlocks];
- memset( pNewMap + nBlocks, 0, 4 * (rSet.nBlocks - nBlocks) );
-
- if ( pBitmap )
- {
- memcpy( pNewMap, pBitmap, 4 * nBlocks );
- delete [] pBitmap;
- }
- pBitmap = pNewMap;
- nBlocks = rSet.nBlocks;
- }
-
- // add the bits blocks by block
- for ( sal_uInt16 nBlock = 0; nBlock < nMax; ++nBlock )
- {
- // compute number of additional bits
- sal_uInt32 nDiff = ~*(pBitmap+nBlock) & *(rSet.pBitmap+nBlock);
- nCount = nCount + CountBits(nDiff);
-
- *(pBitmap+nBlock) |= *(rSet.pBitmap+nBlock);
- }
-
- return *this;
-}
-
-
-
// unites with a single bit
-BitSet& BitSet::operator|=( sal_uInt16 nBit )
+IndexBitSet& IndexBitSet::operator|=( sal_uInt16 nBit )
{
sal_uInt16 nBlock = nBit / 32;
sal_uInt32 nBitVal = 1L << (nBit % 32);
@@ -256,7 +77,7 @@ BitSet& BitSet::operator|=( sal_uInt16 nBit )
// determines if the bit is set (may be the only one)
-bool BitSet::Contains( sal_uInt16 nBit ) const
+bool IndexBitSet::Contains( sal_uInt16 nBit ) const
{
sal_uInt16 nBlock = nBit / 32;
sal_uInt32 nBitVal = 1L << (nBit % 32);
@@ -266,34 +87,16 @@ bool BitSet::Contains( sal_uInt16 nBit ) const
return ( nBitVal & *(pBitmap+nBlock) ) == nBitVal;
}
-
-
-// determines if the bitsets are equal
-
-bool BitSet::operator==( const BitSet& rSet ) const
+IndexBitSet::IndexBitSet()
{
- if ( nBlocks != rSet.nBlocks )
- return false;
-
- sal_uInt16 nBlock = nBlocks;
- while ( nBlock-- > 0 )
- if ( *(pBitmap+nBlock) != *(rSet.pBitmap+nBlock) )
- return false;
-
- return true;
+ nCount = 0;
+ nBlocks = 0;
+ pBitmap = nullptr;
}
-// counts the number of 1-bits in the parameter
-// Wegner/Kernighan/Ritchie method
-sal_uInt16 BitSet::CountBits(sal_uInt32 nBits)
+IndexBitSet::~IndexBitSet()
{
- sal_uInt32 nCount = 0;
- while (nBits)
- {
- nBits &= nBits - 1; // clear the least significant bit set
- ++nCount;
- }
- return nCount;
+ delete [] pBitmap;
}
sal_uInt16 IndexBitSet::GetFreeIndex()