bit_set.h
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C头文件 代码 · 共 381 行 · 第 1/2 页
H
381 行
#undef ENVELOPE_VERTICAL
#undef ENVELOPE_AMPERSAND
#undef ENVELOPE_MINUS
#undef ENVELOPE_CARET
#undef CoolLetter
#undef CoolEnvelope
// operator= -- Assignment from an envelope back to real set
// Input: envelope reference
// Output: Bit_Set reference with contents in envelope being swapped over
inline CoolBit_Set& CoolBit_Set::operator= (CoolBit_SetE& env){
env.shallow_swap((CoolBit_SetE*)this, &env); // same physical layout
return *this;
}
// reset -- Reset the current position index
// Input: None
// Output: None
void CoolBit_Set::reset () {
this->curpos = INVALID; // Invalidate current position
}
// value -- Return "position" of element at current position
// Input: None
// Output: Position of element in Set
inline int CoolBit_Set::value () {
#if ERROR_CHECKING
if (this->curpos == INVALID) // If INVALID current position
this->value_error (); // Raise exception
#endif
return (int) this->curpos;
}
// current_position () -- Return current position state
// Input: None
// Output: Reference to current position state
inline CoolBit_Set::IterState& CoolBit_Set::current_position () {
return this->curpos;
}
// is_empty -- Return value indicating whether set contains any elements
// Input: None
// Output: TRUE/FALSE
inline Boolean CoolBit_Set::is_empty () const {
return ((this->length() == 0) ? TRUE : FALSE);
}
// operator~ -- Return complement of a set
// Input: None
// Output: Bit Set object containing complement of this set
inline CoolBit_SetE CoolBit_Set::operator~ () {
return (this->operator- ());
}
// // operator| -- Return the union of two sets, that is all elements in each set
// // Input: Reference to a bit set
// // Output: New Bit Set object containing union of two sets
//
// inline CoolBit_Set CoolBit_Set::operator| (const CoolBit_Set& b) {
// CoolBit_Set result(*this);
// return result.operator|=(b);
// }
//
//
// // operator- -- Return the difference of two sets, that is all elements in the
// // the first set that are not in the second
// // Input: Reference to bit set
// // Output: New Bit Set object containing union of two sets
//
// inline CoolBit_Set CoolBit_Set::operator- (const CoolBit_Set& b) {
// CoolBit_Set result(*this);
// return result.operator-=(b);
// }
//
//
// // operator^ -- Return the exclusive-OR of two sets, that is all elements in
// // the first set that are not in the second and all elements in
// // the second set that are not in the first
// // Input: Reference to bit set
// // Output: New Bit Set object containing XOR of two sets
//
// inline CoolBit_Set CoolBit_Set::operator^ (const CoolBit_Set& b) {
// CoolBit_Set result(*this);
// return result.operator^=(b);
// }
//
//
// // operator& -- Return the intersection of two sets, that is all elements that
// // are in both sets
// // Input: Reference to Bit Set object
// // Output: New Bit Set object containing intersection of two sets
//
// inline CoolBit_Set CoolBit_Set::operator& (const CoolBit_Set& b) {
// CoolBit_Set result(*this);
// return result.operator&=(b);
// }
// set_union -- Determine the union of two sets
// Input: Reference to a Bit Set object
// Output: None
inline void CoolBit_Set::set_union (const CoolBit_Set& b) {
this->operator|= (b);
}
// set_difference -- Determine the difference of two sets
// Input: Reference to a Bit Set object
// Output: None
inline void CoolBit_Set::set_difference (const CoolBit_Set& b) {
this->operator-= (b);
}
// set_xor -- Determine the exclusive-OR of two sets
// Input: Reference to a Bit Set object
// Output: None
inline void CoolBit_Set::set_xor (const CoolBit_Set& b) {
this->operator^= (b);
}
// set_intersection -- Determine the intersection of two sets
// Input: Reference to a Bit Set object
// Output: None
inline void CoolBit_Set::set_intersection (const CoolBit_Set& b) {
this->operator&= (b);
}
// operator!= -- Return logical result of not equal comparison test
// Input: Reference to another Bit Set object
// Output: Boolean TRUE/FALSE
inline Boolean operator!= (const CoolBit_Set& b1, const CoolBit_Set& b2){
return (!(b1 == b2));
}
// capacity -- Return maximum number of elements object can hold
// Input: None
// Output: Integer value of maximum number of elements
inline int CoolBit_Set::capacity () const {
return (this->size * BS_BITSPERBYTE); // Maximum number of elements
}
// operator[] -- Return value of specified element
// Input: Element to return value (really, it's just an integer value
// Output: None
inline Boolean CoolBit_Set::operator[] (int n) const {
#if ERROR_CHECKING
if (n >= this->size * BS_BITSPERBYTE) // If bit out of range
this->bracket_error (n); // Raise exception
#endif
return((this->data[BS_BYTE_NUMBER(n)]>>(BS_BYTE_OFFSET(n))) & 0x01);
}
// operator<< -- Overload the output operator for Bit Set objects
// Input: Reference to stream, pointer to Bit Set object
// Output: Reference to stream
inline ostream& operator<< (ostream& os, const CoolBit_Set* b) {
return operator<< (os, *b);
}
#endif // End #ifdef of CoolBit_SetH
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?