home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cset21v1.zip / IBMCPP / IBMCLASS / IASRTMAP.C < prev    next >
Text File  |  1993-09-22  |  4KB  |  122 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, class Key >
  14. INumber IASortedMap < Element, Key >::
  15. numberOfOccurrences (Element const& element) const
  16. { if (contains (element))
  17.     return 1;
  18.   else
  19.     return 0;
  20. }
  21.  
  22. template < class Element, class Key >
  23. IBoolean IASortedMap < Element, Key >::
  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, class Key >
  31. INumber IASortedMap < Element, Key >::
  32. removeAllOccurrences (Element const& element)
  33. { if (remove (element))
  34.     return 1;
  35.   else
  36.     return 0;
  37. }
  38.  
  39. template < class Element, class Key >
  40. IBoolean IASortedMap < Element, Key >::
  41. operator == (IASortedMap < Element, Key > const& collection) const
  42. { if (numberOfElements () != collection.numberOfElements ())
  43.     return False;
  44.  
  45.   return containsAllFrom (collection);
  46.  
  47. }
  48.  
  49. template < class Element, class Key >
  50. IBoolean IASortedMap < Element, Key >::
  51. operator != (IASortedMap < Element, Key > const& collection) const
  52. { return ! operator == (collection);
  53. }
  54.  
  55. template < class Element, class Key >
  56. INumber IASortedMap < Element, Key >::
  57. numberOfElementsWithKey (Key const& key) const
  58. { if (containsElementWithKey (key))
  59.     return 1;
  60.   else
  61.     return 0;
  62. }
  63.  
  64. template < class Element, class Key >
  65. IBoolean IASortedMap < Element, Key >::
  66. locateNextElementWithKey (Key const&, ICursor& cursor) const
  67. { elementAt (cursor); // just for precondition checking
  68.   cursor.invalidate ();
  69.   return False;
  70. }
  71.  
  72. template < class Element, class Key >
  73. INumber IASortedMap < Element, Key >::
  74. removeAllElementsWithKey (Key const& key)
  75. { if (removeElementWithKey (key))
  76.     return 1;
  77.   else
  78.     return 0;
  79. }
  80.  
  81. template < class Element, class Key >
  82. INumber IASortedMap < Element, Key >::
  83. numberOfDifferentKeys () const
  84. { return numberOfElements ();
  85. }
  86.  
  87. template < class Element, class Key >
  88. IBoolean IASortedMap < Element, Key >::
  89. setToNextWithDifferentKey (ICursor& cursor) const
  90. { return setToNext (cursor);
  91. }
  92.  
  93. template < class Element, class Key >
  94. long IASortedMap < Element, Key >::
  95. compare (IASortedMap < Element, Key > const& collection,
  96.          long (*comparisonFunction) (Element const&, Element const&)) const
  97. { long result = 0;
  98.   ICursor *thisCursor = newCursor ();
  99.   ICursor *collectionCursor = collection.newCursor ();
  100.  
  101.   for (thisCursor->setToFirst (), collectionCursor->setToFirst ();
  102.        result == 0 && thisCursor->isValid () && collectionCursor->isValid ();
  103.        thisCursor->setToNext (), collectionCursor->setToNext ()) {
  104.     result = (*comparisonFunction) (this->elementAt (*thisCursor),
  105.                                       collection.elementAt (*collectionCursor));
  106.   }
  107.  
  108.   if (result == 0) {
  109.     if (thisCursor->isValid () && ! collectionCursor->isValid ())
  110.       result = 1;
  111.     else if (! thisCursor->isValid () && collectionCursor->isValid ())
  112.       result = -1;
  113.     else {
  114.     }
  115.   }
  116.   delete thisCursor;
  117.   delete collectionCursor;
  118.  
  119.   return result;
  120. }
  121.  
  122.