### IASortedBag

  A sorted bag is an ordered collection of zero or more elements with no key. Both element equality and multiple elements are supported.

### IASortedBag - Member Functions and Data by Group

### Constructors & Destructor

You can construct and destruct objects of this class.

~IASortedBag

      public:
      ~IASortedBag()

  Removes all elements from the collection. Destructors are called for all elements contained in the collection and for elements that have been constructed in advance.

  Side Effects

  All cursors of the collection become undefined.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

IASortedBag

  You can construct and destruct objects of this class.

  Overload 1

      public:
      IASortedBag(INotifier&)

  Use this constructor to create a collection with support for notification.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

  Overload 2

      protected:
      IASortedBag(IASortedBag < Element > const&)

  Constructs a collection. The collection is unbounded and is initially empty.
  Note: The collection constructor does not define whether any elements are constructed when the collection is constructed. For some classes, the element's default constructor may be invoked when the collection's constructor is invoked. This happens if a tabular or a diluted sequence implementation variant is used for a collection. The element's default constructor is used to allocate the required storage and initialize the elements. Therefore, a default constructor must be available for elements in such cases.

  Exception

  IOutOfMemory

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

  Overload 3

      protected:
      IASortedBag()

  The default constructor.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

### Comparison

Use these members to compare a collection with a given collection.

compare

      public:
      long
        compare( IASortedBag < Element > const&,
                 long ( * comparisonFunction ) ( Element const & ,
                 Element const & ) ) const

  Compares the collection with the given collection. Comparison yields <0 if the collection is less than the given collection, 0 if the collection is equal to the given collection, and >0 if the collection is greater than the given collection. Comparison is defined by the first pair of corresponding elements, in both collections, that are not equal. If such a pair exists, the collection with the greater element is the greater one. Otherwise, the collection with more elements is the greater one.
  Note:

  1. The given comparison function must return a result according to the following rules:
     >0
       if (element1 > element2)
     0
       if (element1 == element2)
     <0
       if (element1 < element2)
  2. For elements of type char*, IACollection::compare is not locale-sensitive by default. Because it uses strcmp() and not strcoll(), it compares the binary values representing the characters, and is not based on the LC_COLLATE category of the current locale. Its results are reliable only for code pages and character sets in which the collating sequence matches the sequence of binary representations. If you need a comparison based on the LC_COLLATE cateogory, then you must implement your own compare() function as described in Using Separate Functions:elink. in the Class Library User's Guide.

  Return Value

  Returns the result of the collection comparison.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

### Miscellaneous

Use these members to perform miscellaneous functions.

addDifference

      public:
      virtual void
        addDifference( IASortedBag < Element > const&,
                       IASortedBag < Element > const& )

  Creates the difference between the two given collections, and adds this difference to the collection. The contents of the added elements, not the pointers to those elements, are copied.

  For a definition of the difference between two collections, see IACollection::differenceWith

  Preconditions

  Because the elements are added one by one, the following preconditions are tested for each individual addition.

  - If the collection is bounded and unique, the element or key must exist or (numberOfElements() < maxNumberOfElements()).
  - If the collection is bounded and nonunique, (numberOfElements() < maxNumberOfElements()).
  - If the collection is a map or a sorted map and contains an element with the same key as the given element, this element must be equal to the given element.

  Side Effects

  If any elements were added, all cursors of this collection become undefined.

  Exceptions

  - IOutOfMemory
  - IFullException, if the collection is bounded
  - IKEyAlreadyExistsException, if the collection is a map or a sorted map

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

addIntersection

      public:
      virtual void
        addIntersection( IASortedBag < Element > const&,
                         IASortedBag < Element > const& )

  Creates the intersection of the two given collections, and adds this intersection to the collection. The contents of the added elements, not the pointers to those elements, are copied.

  For a definition of the intersection of two collections, see IACollection::intersectionWith.

  Preconditions

  Because the elements are added one by one, the following preconditions are tested for each individual addition.

  - If the collection is bounded and unique, the element or key must exist or (numberOfElements() < maxNumberOfElements()).
  - If the collection is bounded and nonunique, (numberOfElements() < maxNumberOfElements()).
  - If the collection is a map or a sorted map and contains an element with the same key as the given element, this element must be equal to the given element.

  Side Effects

  If any elements were added, all cursors of this collection become undefined.

  Exceptions

  - IOutOfMemory
  - IFullException, if the collection is bounded
  - IKeyAlreadyException, if the collection is a map or a sorted map

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

addUnion

      public:
      virtual void
        addUnion( IASortedBag < Element > const&,
                  IASortedBag < Element > const& )

  Creates the union of the two given collections, and adds this union to the collection. The contents of the added elements, not the pointers to those elements, are copied.

  For a definition of the union of two collections, see IACollection::unionWith.

  Preconditions

  Because the elements are added one by one, the following preconditions are tested for each individual addition.

  - If the collection is bounded and unique, the element or key must exist or (numberOfElements() < maxNumberOfElements()).
  - If the collection is bounded and nonunique, (numberOfElements() < maxNumberOfElements()).
  - If the collection is a map or a sorted map and contains an element with the same key as the given element, this element must be equal to the given element.

  Side Effects

  If any elements were added, all cursors of this collection become undefined.

  Exceptions

  - IOutOfMemory
  - IFullException, if the collection is bounded
  - IKeyAlreadyException, if the collection is a map or a sorted map

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

differenceWith

      public:
      virtual void differenceWith(IASortedBag < Element > const&)

  Makes the collection the difference between the collection and the given collection. The difference of A and B (A minus B) is the set of elements that are contained in A but not in B.

  The following rule applies for bags with duplicate elements: If bag P contains the element X m times and bag Q contains the element X n times, the difference of P and Q contains the element X m-n times if m > n, and zero times if m<=n.

  Side Effects

  If any elements were removed, all cursors of this collection become undefined.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

intersectionWith

      public:
      virtual void
        intersectionWith( IASortedBag < Element > const& )

  Makes the collection the intersection of the collection and the given collection. The intersection of A and B is the set of elements that is contained in both A and B.

  The following rule applies for bags with duplicate elements: If bag P contains the element X m times and bag Q contains the element X n times, the intersection of P and Q contains the element X MIN(m,n): times.

  Side Effects

  If any elements were removed, all cursors of this collection become undefined.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

numberOfDifferentElements

      public:
      INumber numberOfDifferentElements() const

  Returns the number of different elements in the collection.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

operator !=

      public:
      bool operator !=(IASortedBag < Element > const&) const

  Returns true if the given collection is not equal to the collection. For a definition of equality for collections, see IACollection::operator ==

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

operator ==

      public:
      bool operator ==(IASortedBag < Element > const&) const

  Returns true if the given collection is equal to the collection. Two collections are equal if the number of elements in each collection is the same, and if the condition for the collection is described in the following list:

  Unique Elements
    If the collections have unique elements, any element that occurs in one collection must occur in the other collection.
  Non-Unique Elements
    If an element has n occurrences in one collection, it must have exactly n occurrences in the other collection.
  Sequential
    The ordering of the elements is the same for both collections.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

setToNextDifferentElement

      public:
      bool setToNextDifferentElement(ICursor&) const

  Sets the cursor to the next element in the collection in iteration order with a key different from the key of the element pointed to by the given cursor. If no such element exists, the given cursor is no longer valid.

  Preconditions

  The cursor must belong to the collection and must point to an element of the collection.

  Return Value

  Returns true if a subsequent element was found whose key is different from the current key.

  Exception

  ICursorInvalidException

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

unionWith

      public:
      virtual void unionWith(IASortedBag < Element > const&)

  Makes the collection the union of the collection and the given collection. The union of A and B is the set of elements that are members of A or B or both.

  The following rule applies for bags with duplicate elements: If bag P contains the element X m times and bag Q contains the element X n times, the union of P and Q contains the element X m+n times.

  Preconditions

  Because the elements from the given collection are added to the collection one by one, the following preconditions are tested for each individual add operation :

  - If the collection is bounded and unique, the element or key must exist or (numberOfElements() < maxNumberOfElements()).
  - If the collection is bounded and nonunique, (numberOfElements() < maxNumberOfElements()).
  - If the collection is a map or a sorted map and contains an element with the same key as the given element, this element must be equal to the given element.

  Side Effects

  If any elements were added to the collection, all cursors of this collection become undefined.

  Exceptions

  - IOutOfMemory
  - IFullException, if the collection is bounded
  - IKeyAlreadyException, if the collection is a map or a sorted map

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

### IASortedBag - Inherited Member Functions and Data

#### Inherited Public Functions

  IACollection

  -     virtual ~IACollection()

  -     virtual bool add(Element const&, ICursor&)

  -     virtual bool add(Element const&)

  -     virtual void addAllFrom(IACollection < Element > const&)

  -     void adoptStreamer(IACollectionStreamer*)

  -     bool
          allElementsDo( bool ( * applicatorFunction ) ( Element&,
                         void * ) , void* additionalArgument = 0 )

  -     bool allElementsDo(IApplicator < Element >&)

  -     bool
          allElementsDo( bool ( * applicatorFunction ) ( Element const&,
                         void * ) , void* additionalArgument = 0 ) const

  -     bool allElementsDo(IConstantApplicator < Element >&) const

  -     Element const& any() const

  -     Element const& anyElement() const

  -     virtual void copy(IACollection < Element > const&)

  -     INotifier& disableNotification()

  -     Element& elementAt(ICursor const&)

  -     Element const& elementAt(ICursor const&) const

  -     INotifier& enableNotification(bool = true)

  -     IACollection(INotifier&)

  -     bool isBounded() const

  -     bool isConsistent() const

  -     bool isEmpty() const

  -     bool isEnabledForNotification() const

  -     bool isFull() const

  -     INumber maxNumberOfElements() const

  -     virtual ICursor* newCursor() const

  -     ICursor* newMngCursor() const

  -     INotifier& notifier()

  -     INotifier const& notifier() const

  -     INotifier& notifyObservers(INotificationEvent const&)

  -     INumber numberOfElements() const

  -     virtual void operator <<=(IDataStream&)

  -     virtual void operator >>=(IDataStream&)

  -     operator INotifier &() const

  -     virtual INumber
          removeAll( bool ( * predicateFunction ) ( Element const&,
                     void * ) , void* additionalArgument = 0 )

  -     virtual INumber removeAll()

  -     virtual void removeAt(ICursor&)

  -     virtual void replaceAt(ICursor const&, Element const&)

  -     bool setToFirst(ICursor&) const

  -     bool setToNext(ICursor&) const

  IAOrderedCollection

  -     ~IAOrderedCollection()

  -     Element const& elementAtPosition(IPosition) const

  -     Element const& first() const

  -     Element const& firstElement() const

  -     IAOrderedCollection(INotifier&)

  -     bool isFirst(ICursor const&) const

  -     bool isFirstAt(ICursor const&) const

  -     bool isLast(ICursor const&) const

  -     bool isLastAt(ICursor const&) const

  -     Element const& last() const

  -     Element const& lastElement() const

  -     IPosition position(ICursor const&) const

  -     IPosition positionAt(ICursor const&) const

  -     virtual void removeAtPosition(IPosition)

  -     virtual void removeFirst()

  -     virtual void removeLast()

  -     bool setToLast(ICursor&) const

  -     void setToPosition(IPosition, ICursor&) const

  -     bool setToPrevious(ICursor&) const

  IASortedCollection

  -     ~IASortedCollection()

  -     IASortedCollection(INotifier&)

#### Inherited Public Data

  - None

#### Inherited Protected Functions

  IACollectionBase

  -     ~IACollectionBase()

  -     static ICursorImpl const& CrsrImplOf(ICursor const& cursor)

  -     static ICursorImpl& CrsrImplOf(ICursor& cursor)

  -     IACollectionBase()

  -     IACollectionBase(IACollectionBase const&)

  -     static ICursor* InterfaceFor(ICursorImpl* cursor)

  IACollection

  -     IACollection()

  -     IACollection(IACollection < Element > const&)

  -     static Implementation&
          ImplOf( IACollection < Element > const& )

  IAOrderedCollection

  -     IAOrderedCollection(IAOrderedCollection < Element > const&)

  -     IAOrderedCollection()

  IASortedCollection

  -     IASortedCollection(IASortedCollection < Element > const&)

  -     IASortedCollection()

#### Inherited Protected Data

  - None