get_num_on_bits(), get_next_higher_different_bit(), etc.
This commit is contained in:
parent
e3d121c4f7
commit
89059472ee
|
|
@ -400,46 +400,6 @@ set_word(WordType value) {
|
|||
_word = value;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: BitMask::invert_in_place
|
||||
// Access: Published
|
||||
// Description: Inverts all the bits in the BitMask. This is
|
||||
// equivalent to mask = ~mask.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class WType, int nbits>
|
||||
INLINE void BitMask<WType, nbits>::
|
||||
invert_in_place() {
|
||||
_word = ~_word;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: BitMask::has_bits_in_common
|
||||
// Access: Published
|
||||
// Description: Returns true if this BitMask has any "one" bits in
|
||||
// common with the other one, false otherwise.
|
||||
//
|
||||
// This is equivalent to (mask & other) != 0, but may be
|
||||
// faster. (Actually, it should only be faster in the
|
||||
// BitArray case, but this method is provided for the
|
||||
// benefit of generic programming algorithms).
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class WType, int nbits>
|
||||
INLINE bool BitMask<WType, nbits>::
|
||||
has_bits_in_common(const BitMask<WType, nbits> &other) const {
|
||||
return (_word & other._word) != 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: BitMask::clear
|
||||
// Access: Published
|
||||
// Description: Sets all the bits in the BitMask off.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class WType, int nbits>
|
||||
INLINE void BitMask<WType, nbits>::
|
||||
clear() {
|
||||
_word = 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: BitMask::get_num_on_bits
|
||||
// Access: Published
|
||||
|
|
@ -565,6 +525,46 @@ get_next_higher_different_bit(int low_bit) const {
|
|||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: BitMask::invert_in_place
|
||||
// Access: Published
|
||||
// Description: Inverts all the bits in the BitMask. This is
|
||||
// equivalent to mask = ~mask.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class WType, int nbits>
|
||||
INLINE void BitMask<WType, nbits>::
|
||||
invert_in_place() {
|
||||
_word = ~_word;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: BitMask::has_bits_in_common
|
||||
// Access: Published
|
||||
// Description: Returns true if this BitMask has any "one" bits in
|
||||
// common with the other one, false otherwise.
|
||||
//
|
||||
// This is equivalent to (mask & other) != 0, but may be
|
||||
// faster. (Actually, it should only be faster in the
|
||||
// BitArray case, but this method is provided for the
|
||||
// benefit of generic programming algorithms).
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class WType, int nbits>
|
||||
INLINE bool BitMask<WType, nbits>::
|
||||
has_bits_in_common(const BitMask<WType, nbits> &other) const {
|
||||
return (_word & other._word) != 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: BitMask::clear
|
||||
// Access: Published
|
||||
// Description: Sets all the bits in the BitMask off.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class WType, int nbits>
|
||||
INLINE void BitMask<WType, nbits>::
|
||||
clear() {
|
||||
_word = 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: BitMask::output
|
||||
// Access: Published
|
||||
|
|
|
|||
|
|
@ -425,6 +425,136 @@ set_range_to(bool value, int low_bit, int size) {
|
|||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DoubleBitMask::get_num_on_bits
|
||||
// Access: Published
|
||||
// Description: Returns the number of bits that are set to 1 in the
|
||||
// mask.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class BMType>
|
||||
INLINE int DoubleBitMask<BMType>::
|
||||
get_num_on_bits() const {
|
||||
return _lo.get_num_on_bits() + _hi.get_num_on_bits();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DoubleBitMask::get_num_off_bits
|
||||
// Access: Published
|
||||
// Description: Returns the number of bits that are set to 0 in the
|
||||
// mask.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class BMType>
|
||||
INLINE int DoubleBitMask<BMType>::
|
||||
get_num_off_bits() const {
|
||||
return _lo.get_num_off_bits() + _hi.get_num_off_bits();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DoubleBitMask::get_lowest_on_bit
|
||||
// Access: Published
|
||||
// Description: Returns the index of the lowest 1 bit in the mask.
|
||||
// Returns -1 if there are no 1 bits.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class BMType>
|
||||
INLINE int DoubleBitMask<BMType>::
|
||||
get_lowest_on_bit() const {
|
||||
int result = _lo.get_lowest_on_bit();
|
||||
if (result == -1) {
|
||||
result = _hi.get_lowest_on_bit();
|
||||
if (result != -1) {
|
||||
result += half_bits;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DoubleBitMask::get_lowest_off_bit
|
||||
// Access: Published
|
||||
// Description: Returns the index of the lowest 0 bit in the mask.
|
||||
// Returns -1 if there are no 0 bits.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class BMType>
|
||||
INLINE int DoubleBitMask<BMType>::
|
||||
get_lowest_off_bit() const {
|
||||
int result = _lo.get_lowest_off_bit();
|
||||
if (result == -1) {
|
||||
result = _hi.get_lowest_off_bit();
|
||||
if (result != -1) {
|
||||
result += half_bits;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DoubleBitMask::get_highest_on_bit
|
||||
// Access: Published
|
||||
// Description: Returns the index of the highest 1 bit in the mask.
|
||||
// Returns -1 if there are no 1 bits.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class BMType>
|
||||
INLINE int DoubleBitMask<BMType>::
|
||||
get_highest_on_bit() const {
|
||||
int result = _hi.get_highest_on_bit();
|
||||
if (result == -1) {
|
||||
result = _lo.get_highest_on_bit();
|
||||
} else {
|
||||
result += half_bits;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DoubleBitMask::get_highest_off_bit
|
||||
// Access: Published
|
||||
// Description: Returns the index of the highest 0 bit in the mask.
|
||||
// Returns -1 if there are no 0 bits.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class BMType>
|
||||
INLINE int DoubleBitMask<BMType>::
|
||||
get_highest_off_bit() const {
|
||||
int result = _hi.get_highest_off_bit();
|
||||
if (result == -1) {
|
||||
result = _lo.get_highest_off_bit();
|
||||
} else {
|
||||
result += half_bits;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DoubleBitMask::get_next_higher_different_bit
|
||||
// Access: Published
|
||||
// Description: Returns the index of the next bit in the mask, above
|
||||
// low_bit, whose value is different that the value of
|
||||
// low_bit. Returns low_bit again if all bits higher
|
||||
// than low_bit have the same value.
|
||||
//
|
||||
// This can be used to quickly iterate through all of
|
||||
// the bits in the mask.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class BMType>
|
||||
INLINE int DoubleBitMask<BMType>::
|
||||
get_next_higher_different_bit(int low_bit) const {
|
||||
if (low_bit > half_bits) {
|
||||
return _hi.get_next_higher_different_bit(low_bit - half_bits) + half_bits;
|
||||
}
|
||||
int result = _lo.get_next_higher_different_bit(low_bit);
|
||||
if (result != low_bit) {
|
||||
return result;
|
||||
}
|
||||
if (_lo.get_bit(low_bit)) {
|
||||
result = _hi.get_lowest_off_bit();
|
||||
} else {
|
||||
result = _hi.get_lowest_on_bit();
|
||||
}
|
||||
if (result == -1) {
|
||||
return low_bit;
|
||||
}
|
||||
return result + half_bits;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DoubleBitMask::invert_in_place
|
||||
// Access: Published
|
||||
|
|
|
|||
|
|
@ -76,6 +76,14 @@ PUBLISHED:
|
|||
INLINE void clear_range(int low_bit, int size);
|
||||
INLINE void set_range_to(bool value, int low_bit, int size);
|
||||
|
||||
INLINE int get_num_on_bits() const;
|
||||
INLINE int get_num_off_bits() const;
|
||||
INLINE int get_lowest_on_bit() const;
|
||||
INLINE int get_lowest_off_bit() const;
|
||||
INLINE int get_highest_on_bit() const;
|
||||
INLINE int get_highest_off_bit() const;
|
||||
INLINE int get_next_higher_different_bit(int low_bit) const;
|
||||
|
||||
INLINE void invert_in_place();
|
||||
INLINE bool has_bits_in_common(const DoubleBitMask<BMType> &other) const;
|
||||
INLINE void clear();
|
||||
|
|
|
|||
Loading…
Reference in New Issue