home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional Developers Kit 1992 November / Disc01 / Disc01.mdf / cppbeta / bbxxk / iaksset.c__ / IAKSSET.C
Encoding:
Text File  |  1992-10-26  |  1.9 KB  |  70 lines

  1. /* Copyright (c) IBM Corp. 1992 */
  2.  
  3.  
  4. template < class Element, class Key >
  5. INumber IAKeySortedSet < Element, Key >::
  6. numberOfElementsWithKey (Key const& key) const
  7. { if (containsElementWithKey (key))
  8.     return 1;
  9.   else
  10.     return 0;
  11. }
  12.  
  13. template < class Element, class Key >
  14. Boolean IAKeySortedSet < Element, Key >::
  15. locateNextElementWithKey (Key const&, ICursor& cursor) const
  16. { cursor.invalidate ();
  17.   return False;
  18. }
  19.  
  20. template < class Element, class Key >
  21. INumber IAKeySortedSet < Element, Key >::
  22. removeAllElementsWithKey (Key const& key)
  23. { if (removeElementWithKey (key))
  24.     return 1;
  25.   else
  26.     return 0;
  27. }
  28.  
  29. template < class Element, class Key >
  30. INumber IAKeySortedSet < Element, Key >::
  31. numberOfDifferentKeys () const
  32. { return numberOfElements ();
  33. }
  34.  
  35. template < class Element, class Key >
  36. Boolean IAKeySortedSet < Element, Key >::
  37. setToNextWithDifferentKey (ICursor& cursor) const
  38. { return setToNext (cursor);
  39. }
  40.  
  41. template < class Element, class Key >
  42. long IAKeySortedSet < Element, Key >::
  43. compare (IAKeySortedSet < Element, Key > const& collection,
  44.          long (*comparisonFunction) (Element const&, Element const&)) const
  45. { long result = 0;
  46.   ICursor *thisCursor = newCursor ();
  47.   ICursor *collectionCursor = collection.newCursor ();
  48.  
  49.   for (thisCursor->setToFirst (), collectionCursor->setToFirst ();
  50.        result == 0 && thisCursor->isValid () && collectionCursor->isValid ();
  51.        thisCursor->setToNext (), collectionCursor->setToNext ()) {
  52.     result = (*comparisonFunction) (this->elementAt (*thisCursor),
  53.                       collection.elementAt (*collectionCursor));
  54.   }
  55.  
  56.   if (result == 0) {
  57.     if (thisCursor->isValid () && ! collectionCursor->isValid ())
  58.       result = 1;
  59.     else if (! thisCursor->isValid () && collectionCursor->isValid ())
  60.       result = -1;
  61.     else {
  62.     }
  63.   }
  64.   delete thisCursor;
  65.   delete collectionCursor;
  66.  
  67.   return result;
  68. }
  69.  
  70.