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

  1. /* Copyright (c) IBM Corp. 1992 */
  2.  
  3.  
  4. template < class Element, class Key >
  5. INumber IAMap < Element, Key >::
  6. numberOfOccurrences (Element const& element) const
  7. { if (contains (element))
  8.     return 1;
  9.   else
  10.     return 0;
  11. }
  12.  
  13. template < class Element, class Key >
  14. Boolean IAMap < Element, Key >::
  15. locateNext (Element const&, ICursor& cursor) const
  16. { cursor.invalidate ();
  17.   return False;
  18. }
  19.  
  20. template < class Element, class Key >
  21. INumber IAMap < Element, Key >::
  22. removeAllOccurrences (Element const& element)
  23. { if (remove (element))
  24.     return 1;
  25.   else
  26.     return 0;
  27. }
  28.  
  29. template < class Element, class Key >
  30. Boolean IAMap < Element, Key >::
  31. operator == (IAMap < Element, Key > const& collection) const
  32. { return this->containsAllFrom (collection) &&
  33.      collection.containsAllFrom (*this);
  34. }
  35.  
  36. template < class Element, class Key >
  37. Boolean IAMap < Element, Key >::
  38. operator != (IAMap < Element, Key > const& collection) const
  39. { return ! operator == (collection);
  40. }
  41.  
  42. template < class Element, class Key >
  43. void IAMap < Element, Key >::
  44. unionWith (IAMap < Element, Key > const& collection)
  45. { addAllFrom (collection);
  46. }
  47.  
  48. template < class Element, class Key >
  49. void IAMap < Element, Key >::
  50. intersectionWith (IAMap < Element, Key > const& collection)
  51. { IAEqualityCollection < Element > const* env = &collection;
  52.   removeAll (IAEqualityCollection < Element >::isNotContained, &env);
  53. }
  54.  
  55. template < class Element, class Key >
  56. void IAMap < Element, Key >::
  57. differenceWith (IAMap < Element, Key > const& collection)
  58. { IAEqualityCollection < Element > const* env = &collection;
  59.   removeAll (IAEqualityCollection < Element >::isContained, &env);
  60. }
  61.  
  62. template < class Element, class Key >
  63. void IAMap < Element, Key >::
  64. addUnion (IAMap < Element, Key > const& collection1,
  65.           IAMap < Element, Key > const& collection2)
  66. { addAllFrom (collection1);
  67.   addAllFrom (collection2);
  68. }
  69.  
  70. template < class Element, class Key >
  71. void IAMap < Element, Key >::
  72. addIntersection (IAMap < Element, Key > const& collection1,
  73.                  IAMap < Element, Key > const& collection2)
  74. { ICursor *cursor = collection1.newCursor ();
  75.   forCursor (*cursor) {
  76.     if (collection2.contains (collection1.elementAt (*cursor)))
  77.       add (collection1.elementAt (*cursor));
  78.   }
  79.   delete cursor;
  80. }
  81.  
  82. template < class Element, class Key >
  83. void IAMap < Element, Key >::
  84. addDifference (IAMap < Element, Key > const& collection1,
  85.                IAMap < Element, Key > const& collection2)
  86. { ICursor *cursor = collection1.newCursor ();
  87.   forCursor (*cursor) {
  88.     if (! collection2.contains (collection1.elementAt (*cursor)))
  89.       add (collection1.elementAt (*cursor));
  90.   }
  91.   delete cursor;
  92. }
  93.  
  94. template < class Element, class Key >
  95. INumber IAMap < Element, Key >::
  96. numberOfElementsWithKey (Key const& key) const
  97. { if (containsElementWithKey (key))
  98.     return 1;
  99.   else
  100.     return 0;
  101. }
  102.  
  103. template < class Element, class Key >
  104. Boolean IAMap < Element, Key >::
  105. locateNextElementWithKey (Key const&, ICursor& cursor) const
  106. { cursor.invalidate ();
  107.   return False;
  108. }
  109.  
  110. template < class Element, class Key >
  111. INumber IAMap < Element, Key >::
  112. removeAllElementsWithKey (Key const& key)
  113. { if (removeElementWithKey (key))
  114.     return 1;
  115.   else
  116.     return 0;
  117. }
  118.  
  119. template < class Element, class Key >
  120. INumber IAMap < Element, Key >::
  121. numberOfDifferentKeys () const
  122. { return numberOfElements ();
  123. }
  124.  
  125. template < class Element, class Key >
  126. Boolean IAMap < Element, Key >::
  127. setToNextWithDifferentKey (ICursor& cursor) const
  128. { return setToNext (cursor);
  129. }
  130.  
  131.