home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cset21v1.zip / IBMCPP / IBMCLASS / IASRTSET.C < prev    next >
Text File  |  1993-09-22  |  3KB  |  84 lines

  1. /*******************************************************************************
  2. *                                                                              *
  3. * COPYRIGHT:                                                                   *
  4. *   IBM C/C++ Tools Version 2.01 - Collection Class Library                    *
  5. *   Licensed Materials - Property of IBM                                       *
  6. *   (C) Copyright IBM Corporation 1992, 1993                                   *
  7. *   All Rights Reserved                                                        *
  8. *   US Government Users Restricted Rights - Use, duplication, or disclosure    *
  9. *   restricted by GSA ADP Schedule Contract with IBM Corp.                     *
  10. *                                                                              *
  11. *******************************************************************************/
  12.  
  13. template < class Element >
  14. INumber IASortedSet < Element >::
  15. numberOfOccurrences (Element const& element) const
  16. { if (contains (element))
  17.     return 1;
  18.   else
  19.     return 0;
  20. }
  21.  
  22. template < class Element >
  23. IBoolean IASortedSet < Element >::
  24. locateNext (Element const&, ICursor& cursor) const
  25. { elementAt (cursor); // just for precondition checking
  26.   cursor.invalidate ();
  27.   return False;
  28. }
  29.  
  30. template < class Element >
  31. INumber IASortedSet < Element >::
  32. removeAllOccurrences (Element const& element)
  33. { if (remove (element))
  34.     return 1;
  35.   else
  36.     return 0;
  37. }
  38.  
  39. template < class Element >
  40. IBoolean IASortedSet < Element >::
  41. operator == (IASortedSet < Element > const& collection) const
  42. { if (numberOfElements () != collection.numberOfElements ())
  43.     return False;
  44.  
  45.   return containsAllFrom (collection);
  46.  
  47. }
  48.  
  49. template < class Element >
  50. IBoolean IASortedSet < Element >::
  51. operator != (IASortedSet < Element > const& collection) const
  52. { return ! operator == (collection);
  53. }
  54.  
  55. template < class Element >
  56. long IASortedSet < Element >::
  57. compare (IASortedSet < Element > const& collection,
  58.          long (*comparisonFunction) (Element const&, Element const&)) const
  59. { long result = 0;
  60.   ICursor *thisCursor = newCursor ();
  61.   ICursor *collectionCursor = collection.newCursor ();
  62.  
  63.   for (thisCursor->setToFirst (), collectionCursor->setToFirst ();
  64.        result == 0 && thisCursor->isValid () && collectionCursor->isValid ();
  65.        thisCursor->setToNext (), collectionCursor->setToNext ()) {
  66.     result = (*comparisonFunction) (this->elementAt (*thisCursor),
  67.                                       collection.elementAt (*collectionCursor));
  68.   }
  69.  
  70.   if (result == 0) {
  71.     if (thisCursor->isValid () && ! collectionCursor->isValid ())
  72.       result = 1;
  73.     else if (! thisCursor->isValid () && collectionCursor->isValid ())
  74.       result = -1;
  75.     else {
  76.     }
  77.   }
  78.   delete thisCursor;
  79.   delete collectionCursor;
  80.  
  81.   return result;
  82. }
  83.  
  84.