DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

set_union(C++)


set_union -- treating arrays as sets, take the union

Synopsis

   template <class T>
   T* set_union(
        const T* b1,
        const T* e1,
        const T* b2,
        const T* e2,
        T* b3
   );
   template <class T>
   T* set_union_r(
        int (*rel)(const T*,const T*),
        const T* b1,
        const T* e1,
        const T* b2,
        const T* e2,
        T* b3
   );

Assumptions


(C)
For the plain version, T::operator< defines a total ordering relation T and the array is sorted w.r.t. that relation.

(S)
For the relational version, rel defines a total ordering relation on T and the array is sorted w.r.t. that relation.

(S)
Neither of the input arrays has any repetitions.

(F)
The output array does not overlap either of the input arrays.

(M)
The output array has enough cells to hold the result.

(6)
T has operator=.

Description

These functions put elements from two sorted arrays with no repetitions into a new sorted array with no repetitions so that for every element in the original arrays there is an element in the result array that is equal to it. The pointer to the cell following the last element of the new array is returned.

   template <class T>
   T* set_union(
       const T* b1,
       const T* e1,
       const T* b2,
       const T* e2,
       T* b3
       );

Uses T::operator< to define the ordering relation.

   template <class T>
   T* set_union_r(
       int (*rel)(const T*,const T*),
       const T* b1,
       const T* e1,
       const T* b2,
       const T* e2,
       T* b3
       );

Uses rel to define the ordering relation.

Complexity

If N and M are the sizes of the two arrays, then complexity is O(N+M). At most N + M-1 tests of the ordering relation and N+M assignments are done.

Notes

All functions whose names begin with set_ treat arrays as sets (they share assumptions 1-3). These all have linear time complexity, which may unacceptable for large sets. As an alternative, consider using Set(3C++) or Bits(3C++) (if T is int).

Because a Block (see Block(3C++)) can always be used wherever an array is called for, Array Algorithms can also be used with Blocks. In fact, these two components were actually designed to be used together.

References

Array_alg(C++), Bits(C++), Block(C++), Set(C++), set_diff(C++), set_insert(C++), set_inter(C++), set_remove(C++), set_sdiff(C++)
© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 - 01 June 2005