home *** CD-ROM | disk | FTP | other *** search
- /* Copyright (c) IBM Corp. 1992 */
-
-
- template < class Element, class Key >
- INumber IASortedMap < Element, Key >::
- numberOfOccurrences (Element const& element) const
- { if (contains (element))
- return 1;
- else
- return 0;
- }
-
- template < class Element, class Key >
- Boolean IASortedMap < Element, Key >::
- locateNext (Element const&, ICursor& cursor) const
- { cursor.invalidate ();
- return False;
- }
-
- template < class Element, class Key >
- INumber IASortedMap < Element, Key >::
- removeAllOccurrences (Element const& element)
- { if (remove (element))
- return 1;
- else
- return 0;
- }
-
- template < class Element, class Key >
- Boolean IASortedMap < Element, Key >::
- operator == (IASortedMap < Element, Key > const& collection) const
- { return this->containsAllFrom (collection) &&
- collection.containsAllFrom (*this);
- }
-
- template < class Element, class Key >
- Boolean IASortedMap < Element, Key >::
- operator != (IASortedMap < Element, Key > const& collection) const
- { return ! operator == (collection);
- }
-
- template < class Element, class Key >
- void IASortedMap < Element, Key >::
- unionWith (IASortedMap < Element, Key > const& collection)
- { addAllFrom (collection);
- }
-
- template < class Element, class Key >
- void IASortedMap < Element, Key >::
- intersectionWith (IASortedMap < Element, Key > const& collection)
- { IAEqualityCollection < Element > const* env = &collection;
- removeAll (IAEqualityCollection < Element >::isNotContained, &env);
- }
-
- template < class Element, class Key >
- void IASortedMap < Element, Key >::
- differenceWith (IASortedMap < Element, Key > const& collection)
- { IAEqualityCollection < Element > const* env = &collection;
- removeAll (IAEqualityCollection < Element >::isContained, &env);
- }
-
- template < class Element, class Key >
- void IASortedMap < Element, Key >::
- addUnion (IASortedMap < Element, Key > const& collection1,
- IASortedMap < Element, Key > const& collection2)
- { addAllFrom (collection1);
- addAllFrom (collection2);
- }
-
- template < class Element, class Key >
- void IASortedMap < Element, Key >::
- addIntersection (IASortedMap < Element, Key > const& collection1,
- IASortedMap < Element, Key > const& collection2)
- { ICursor *cursor = collection1.newCursor ();
- forCursor (*cursor) {
- if (collection2.contains (collection1.elementAt (*cursor)))
- add (collection1.elementAt (*cursor));
- }
- delete cursor;
- }
-
- template < class Element, class Key >
- void IASortedMap < Element, Key >::
- addDifference (IASortedMap < Element, Key > const& collection1,
- IASortedMap < Element, Key > const& collection2)
- { ICursor *cursor = collection1.newCursor ();
- forCursor (*cursor) {
- if (! collection2.contains (collection1.elementAt (*cursor)))
- add (collection1.elementAt (*cursor));
- }
- delete cursor;
- }
-
- template < class Element, class Key >
- INumber IASortedMap < Element, Key >::
- numberOfElementsWithKey (Key const& key) const
- { if (containsElementWithKey (key))
- return 1;
- else
- return 0;
- }
-
- template < class Element, class Key >
- Boolean IASortedMap < Element, Key >::
- locateNextElementWithKey (Key const&, ICursor& cursor) const
- { cursor.invalidate ();
- return False;
- }
-
- template < class Element, class Key >
- INumber IASortedMap < Element, Key >::
- removeAllElementsWithKey (Key const& key)
- { if (removeElementWithKey (key))
- return 1;
- else
- return 0;
- }
-
- template < class Element, class Key >
- INumber IASortedMap < Element, Key >::
- numberOfDifferentKeys () const
- { return numberOfElements ();
- }
-
- template < class Element, class Key >
- Boolean IASortedMap < Element, Key >::
- setToNextWithDifferentKey (ICursor& cursor) const
- { return setToNext (cursor);
- }
-
- template < class Element, class Key >
- long IASortedMap < Element, Key >::
- compare (IASortedMap < Element, Key > const& collection,
- long (*comparisonFunction) (Element const&, Element const&)) const
- { long result = 0;
- ICursor *thisCursor = newCursor ();
- ICursor *collectionCursor = collection.newCursor ();
-
- for (thisCursor->setToFirst (), collectionCursor->setToFirst ();
- result == 0 && thisCursor->isValid () && collectionCursor->isValid ();
- thisCursor->setToNext (), collectionCursor->setToNext ()) {
- result = (*comparisonFunction) (this->elementAt (*thisCursor),
- collection.elementAt (*collectionCursor));
- }
-
- if (result == 0) {
- if (thisCursor->isValid () && ! collectionCursor->isValid ())
- result = 1;
- else if (! thisCursor->isValid () && collectionCursor->isValid ())
- result = -1;
- else {
- }
- }
- delete thisCursor;
- delete collectionCursor;
-
- return result;
- }
-