template<class element_t> class adevs_bag
A bag stores an unordered collection of elements.
Inheritance:
Public Methods
-
adevs_bag(int capacity = 20)
-
Capacity is the initial memory set aside to hold elements
When the adevs_bag becomes full, its capacity is increased to
capacity*2 slots
-
adevs_bag(const adevs_bag<element_t>& src)
-
Creates a copy of the bag.
-
const adevs_bag<element_t> & operator=(const adevs_bag<element_t>& src)
-
Sets the contents of this bag to be the same as the contents of the source
bag.
-
int getSize() const
- Returns the number of elements in the bag.
-
int getCapacity() const
-
Returns the amount of space available for storing elements (this is
always greater than getSize())
-
void enlarge(int adjustment)
- Adds the specified capacity to the bag
-
element_t& operator[](int index)
- Returns a reference to the object stored at the index
-
const element_t& get(int index) const
- Returns a constant reference to the element stored at the index
-
element_t& get(int index)
- Returns a reference to the element stored at the index
-
void swap(int i, int j)
- Swap the elements at index i and index j
-
void append(const adevs_bag<element_t>& src)
- Append the items in the source bag to the end of this bag
-
virtual void removeAll()
- Remove all elements from the bag
-
virtual void add(const element_t& e)
- Add an element to the end of the bag (ie, at index getSize())
-
virtual void remove(int index)
-
Removes the element at the indicated index.
-
void erase(const element_t& e)
-
Find and remove the first element equal to e.
-
virtual ~adevs_bag()
-
Destructor
Documentation
A bag stores an unordered collection of elements. It supports
indexed access to the elements (via the [] operator), addition of
new elements, and the removal of elements. The element type must support
the assignment and equality operators.
New elements are appended to the end of the bag.
When an element is removed, the last element of the bag fills
the vacant slot, thereby avoiding holes in the indexing.
- adevs_bag(int capacity = 20)
-
Capacity is the initial memory set aside to hold elements
When the adevs_bag becomes full, its capacity is increased to
capacity*2 slots
- adevs_bag(const adevs_bag<element_t>& src)
-
Creates a copy of the bag. Element copying is done via the assignment operator.
- const adevs_bag<element_t> & operator=(const adevs_bag<element_t>& src)
-
Sets the contents of this bag to be the same as the contents of the source
bag. Element copying is done via the assignment operator.
- int getSize() const
- Returns the number of elements in the bag. The last index is at getSize()-1.
- int getCapacity() const
-
Returns the amount of space available for storing elements (this is
always greater than getSize())
- void enlarge(int adjustment)
- Adds the specified capacity to the bag
- element_t& operator[](int index)
- Returns a reference to the object stored at the index
- const element_t& get(int index) const
- Returns a constant reference to the element stored at the index
- element_t& get(int index)
- Returns a reference to the element stored at the index
- void swap(int i, int j)
- Swap the elements at index i and index j
- void append(const adevs_bag<element_t>& src)
- Append the items in the source bag to the end of this bag
- virtual void removeAll()
- Remove all elements from the bag
- virtual void add(const element_t& e)
- Add an element to the end of the bag (ie, at index getSize())
- virtual void remove(int index)
-
Removes the element at the indicated index. If this creates a hole
in the bag indexing, the hole is filled by moving the element at
getSize()-1.
- void erase(const element_t& e)
-
Find and remove the first element equal to e. Equality is determined with
the == operator.
- virtual ~adevs_bag()
-
Destructor
- Direct child classes:
- adevs_set
Alphabetic index HTML hierarchy of classes or Java
This page was generated with the help of DOC++.