set.h
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C头文件 代码 · 共 437 行 · 第 1/2 页
H
437 行
template <class Type>
inline void CoolSet<Type>::set_union (const CoolSet<Type>& b) {
this->operator|= (b);
}
// set_difference -- Determine the difference of two sets
// Input: Reference to a Bit Set object
// Output: None
template <class Type>
inline void CoolSet<Type>::set_difference (const CoolSet<Type>& b) {
this->operator-= (b);
}
// set_xor -- Determine the exclusive-OR of two sets
// Input: Reference to a Bit Set object
// Output: None
template <class Type>
inline void CoolSet<Type>::set_xor (const CoolSet<Type>& b) {
this->operator^= (b);
}
// set_intersection -- Determine the intersection of two sets
// Input: Reference to a Bit Set object
// Output: None
template <class Type>
inline void CoolSet<Type>::set_intersection (const CoolSet<Type>& b) {
this->operator&= (b);
}
// operator!= -- Return logical result of not equal comparison test
// Input: Reference to another Bit Set object
// Output: Boolean TRUE/FALSE
template <class Type>
inline Boolean CoolSet<Type>::operator!= (const CoolSet<Type>& b) const {
return (!(this->operator== (b)));
}
// Set_hash -- Set the hash function for this instance
// Input: Pointer to hash function
// Output: None
template <class Type>
inline void CoolSet<Type>::set_hash (register long (*h) (const Type&)) {
this->h_function = h;
}
//
// // operator| -- Return the union of two sets, that is all elements in each set
// // Input: Reference to a set
// // Output: New Set object containing union of two sets
//
// template <class Type> CoolSet {
// inline CoolSet<Type> operator| (const CoolSet<Type>& s1, const CoolSet<Type>& s2) {
// CoolSet<Type> result(s1); // Temporary variable
// result.operator|=(s2); // Mutate temp with union
// return result; // Return resulting union
// }}
//
//
// // operator- -- Return the difference of two sets, that is all elements in
// // the first set that are not in the second
// // Input: Reference to a set
// // Output: New CoolSet object containing difference of two sets
//
// template <class Type> CoolSet{
// inline CoolSet<Type> operator- (const CoolSet<Type>& s1, const CoolSet<Type>& s2) {
// CoolSet<Type> result(s1); // Temporary variable
// result.operator-=(s2); // Mutate temp with difference
// return result; // Return resulting union
// }}
//
//
// // 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 set
// // Output: New CoolSet object containing XOR of two sets
//
// template <class Type> CoolSet {
// inline CoolSet<Type> operator^ (const CoolSet<Type>& s1, const CoolSet<Type>& s2) {
// CoolSet<Type> result(s1); // Temporary variable
// result.operator^=(s2); // Mutate temp with xor
// return result; // Return resulting xor
// }}
//
//
// // operator& -- Return the intersection of two sets, that is all elements that
// // are in both sets
// // Input: Reference to CoolSet object
// // Output: New CoolSet object containing intersection of two sets
//
// template <class Type> CoolSet {
// inline CoolSet<Type> operator& (const CoolSet<Type>& s1, const CoolSet<Type>& s2) {
// CoolSet<Type> result(s1); // Temporary variable
// result.operator&=(s2); // Mutate with intersection
// return result; // Return resulting intersection
// }}
// next_intersection -- Position at the next intersection of two Sets.
// Input: Reference to CoolSet object
// Output: TRUE/FALSE, current position updated
template <class Type>
Boolean CoolSet<Type>::next_intersection (CoolSet<Type>& s) {
if (this->curpos != INVALID && TRAVERSED(this->curpos)) // Traversed already?
return FALSE; // Indicate no more elements
while (this->next () == TRUE) { // While there are elements
if (BUCKET_NUMBER(this->curpos) >= s.get_bucket_count())
return FALSE; // Return failure status
if (s.find(this->value()) == TRUE) // If element in 2nd set
return TRUE; // Return success status
}
this->curpos = INVALID; // Invalidate current position
return FALSE; // Return failure status
}
// next_union -- Position at the next union of two Sets.
// Input: Reference to CoolSet object
// Output: TRUE/FALSE, current position updated
template <class Type>
Boolean CoolSet<Type>::next_union (CoolSet<Type>& s) {
if ((this->curpos != INVALID && !TRAVERSED(this->curpos)) ||
this->curpos == INVALID) {
if (this->next () == TRUE) // If more elements in 1st set
return TRUE; // Return success status
else // Else set traversed flag
this->curpos = SET_TRAVERSED(TRUE);
}
while (s.next () == TRUE) { // While more elements in 2nd
if (this->find(s.value()) == FALSE) { // If element not in 1st set
this->curpos |= SET_TRAVERSED(TRUE); // Reset flag zeroed by find
this->next_data = s.value(); // Refer to next piece of data
return TRUE; // Return success status
}
}
this->curpos = INVALID; // Invalidate current position
return FALSE; // Return failure status
}
// next_difference -- Position at the zero-relative integer of the next bit in
// the difference of two CoolSets.
// Input: Reference to CoolSet object
// Output: TRUE/FALSE, current position updated
template <class Type>
Boolean CoolSet<Type>::next_difference (CoolSet<Type>& s) {
if (this->curpos != INVALID && TRAVERSED(this->curpos)) // Traversed already?
return FALSE; // Indicate no more elements
while (this->next () == TRUE) { // While there are elements
if (BUCKET_NUMBER(this->curpos) >= s.get_bucket_count())
return FALSE; // Return failure status
if (s.find(this->value()) == FALSE) // If element not in 2nd set
return TRUE; // Return success status
}
this->curpos = INVALID; // Invalidate current position
return FALSE; // Return failure status
}
// next_xor -- Position at the zero-relative integer of the next bit in
// the XOR of two Sets.
// Input: Reference to CoolSet object
// Output: TRUE/FALSE, current position updated
template <class Type>
Boolean CoolSet<Type>::next_xor (CoolSet<Type>& s) {
if ((this->curpos != INVALID && !TRAVERSED(this->curpos)) ||
this->curpos == INVALID) {
if (this->next_difference (s) == TRUE) // If more elements in 1st set
return TRUE; // Return success status
else { // Else set traversed flag
this->curpos = SET_TRAVERSED(TRUE);
s.reset(); // Reset current position
}
}
if ((s.curpos != INVALID && !TRAVERSED(s.curpos)) || s.curpos == INVALID) {
this->reset(); // Reset 1st set pointer
if (s.next_difference (*this)) { // If any other elements in 2nd
this->curpos |= SET_TRAVERSED(TRUE); // Reset flag set by find
this->next_data = s.value(); // Save data for value()
return TRUE; // Return success status
}
}
this->curpos = INVALID; // Invalidate current position
return FALSE; // Return failure status
}
// operator<< -- Overload the output operator to provide a crude print
// capability for CoolSet objects
// Input: ostream reference, CoolSet pointer
// Output: None
template <class Type>
inline ostream& operator<< (ostream& os, const CoolSet<Type>* s) {
return operator<< (os, *s);
}
//## hack to workaround BC++ 3.1 Envelope bug
#undef CoolEnvelope
#endif // End of SETH
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?