VectorBag is a vector-based implementation of BagInterface.
More...
#include <VectorBag.h>
|
| int | getCurrentSize () const |
| | Gets the current number of entries in this bag. More...
|
| |
| bool | isEmpty () const |
| | Sees whether this bag is empty. More...
|
| |
| bool | add (const ItemType &newEntry) |
| | Adds a new entry to this bag. More...
|
| |
| bool | remove (const ItemType &anEntry) |
| | Removes one occurrence of a given entry from this bag, if possible. More...
|
| |
| void | clear () |
| | Removes all entries from this bag. More...
|
| |
| bool | contains (const ItemType &anEntry) const |
| | Tests whether this bag contains a given entry. More...
|
| |
| int | getFrequencyOf (const ItemType &anEntry) const |
| | Counts the number of times a given entry appears in bag. More...
|
| |
| vector< ItemType > | toVector () const |
| | Empties and then f ills a given vector with all entries that are in this bag. More...
|
| |
| VectorBag< ItemType > | operator+ (VectorBag< ItemType > anotherBag) |
| | Creates a new bag that combines the contents of this bag and a second given bag without affecting the original two bags. More...
|
| |
| VectorBag< ItemType > | operator* (VectorBag< ItemType > anotherBag) |
| | Creates a new bag that contains those objects that occur in both this bag and a second given bag without affecting the original two bags. More...
|
| |
| VectorBag< ItemType > | operator- (VectorBag< ItemType > anotherBag) |
| | Creates a new bag of objects that would be left in this bag after removing those that also occur in a second given bag without affecting the original two bags. More...
|
| |
template<class ItemType>
class VectorBag< ItemType >
VectorBag is a vector-based implementation of BagInterface.
◆ add()
template<class ItemType >
| bool VectorBag< ItemType >::add |
( |
const ItemType & |
newEntry | ) |
|
|
virtual |
Adds a new entry to this bag.
- Postcondition
- If successful, newEntry is stored in the bag and the count of items in the bag has increased by 1.
- Parameters
-
| newEntry | The object to be added as a new entry. |
- Returns
- True if addition was successful, or false if not.
Implements BagInterface< ItemType >.
◆ clear()
template<class ItemType >
Removes all entries from this bag.
- Postcondition
- Bag contains no items, and the count of items is 0.
Implements BagInterface< ItemType >.
◆ contains()
template<class ItemType >
| bool VectorBag< ItemType >::contains |
( |
const ItemType & |
anEntry | ) |
const |
|
virtual |
Tests whether this bag contains a given entry.
- Parameters
-
| anEntry | The entry to locate. |
- Returns
- True if bag contains anEntry, or false otherwise.
Implements BagInterface< ItemType >.
◆ getCurrentSize()
template<class ItemType >
| int VectorBag< ItemType >::getCurrentSize |
( |
| ) |
const |
|
virtual |
Gets the current number of entries in this bag.
- Returns
- The integer number of entries currently in the bag.
Implements BagInterface< ItemType >.
◆ getFrequencyOf()
template<class ItemType >
| int VectorBag< ItemType >::getFrequencyOf |
( |
const ItemType & |
anEntry | ) |
const |
|
virtual |
Counts the number of times a given entry appears in bag.
- Parameters
-
| anEntry | The entry to be counted. |
- Returns
- The number of times anEntry appears in the bag.
Implements BagInterface< ItemType >.
◆ isEmpty()
template<class ItemType >
| bool VectorBag< ItemType >::isEmpty |
( |
| ) |
const |
|
virtual |
◆ operator*()
template<class ItemType >
Creates a new bag that contains those objects that occur in both this bag and a second given bag without affecting the original two bags.
- Parameters
-
- Returns
- A bag that is the intersection of the two bags.
◆ operator+()
template<class ItemType >
Creates a new bag that combines the contents of this bag and a second given bag without affecting the original two bags.
Note that we can't call this operation "<code>union</code>", since "<code>union</code>" is a reserved word.
- Parameters
-
- Returns
- A bag that is the union of the two bags.
◆ operator-()
template<class ItemType >
Creates a new bag of objects that would be left in this bag after removing those that also occur in a second given bag without affecting the original two bags.
- Parameters
-
- Returns
- A bag that is the difference of the two bags.
◆ remove()
template<class ItemType >
| bool VectorBag< ItemType >::remove |
( |
const ItemType & |
anEntry | ) |
|
|
virtual |
Removes one occurrence of a given entry from this bag, if possible.
- Postcondition
- If successful, anEntry has been removed from the bag and the count of items in the bag has decreased by 1.
- Parameters
-
| anEntry | The entry to be removed. |
- Returns
- True if removal was successful, or false if not.
Implements BagInterface< ItemType >.
◆ toVector()
template<class ItemType >
| vector< ItemType > VectorBag< ItemType >::toVector |
( |
| ) |
const |
|
virtual |
Empties and then f ills a given vector with all entries that are in this bag.
- Returns
- A vector containing all the entries in the bag.
Implements BagInterface< ItemType >.
The documentation for this class was generated from the following files: