template<class element_t> class adevs_bag

A bag stores an unordered collection of elements.

Inheritance:


Public Methods

[more] 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
[more] adevs_bag(const adevs_bag<element_t>& src)
Creates a copy of the bag.
[more]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.
[more]int getSize() const
Returns the number of elements in the bag.
[more]int getCapacity() const
Returns the amount of space available for storing elements (this is always greater than getSize())
[more]void enlarge(int adjustment)
Adds the specified capacity to the bag
[more]element_t& operator[](int index)
Returns a reference to the object stored at the index
[more]const element_t& get(int index) const
Returns a constant reference to the element stored at the index
[more]element_t& get(int index)
Returns a reference to the element stored at the index
[more]void swap(int i, int j)
Swap the elements at index i and index j
[more]void append(const adevs_bag<element_t>& src)
Append the items in the source bag to the end of this bag
[more]virtual void removeAll()
Remove all elements from the bag
[more]virtual void add(const element_t& e)
Add an element to the end of the bag (ie, at index getSize())
[more]virtual void remove(int index)
Removes the element at the indicated index.
[more]void erase(const element_t& e)
Find and remove the first element equal to e.
[more]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.
o 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

o adevs_bag(const adevs_bag<element_t>& src)
Creates a copy of the bag. Element copying is done via the assignment operator.

oconst 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.

oint getSize() const
Returns the number of elements in the bag. The last index is at getSize()-1.

oint getCapacity() const
Returns the amount of space available for storing elements (this is always greater than getSize())

ovoid enlarge(int adjustment)
Adds the specified capacity to the bag

oelement_t& operator[](int index)
Returns a reference to the object stored at the index

oconst element_t& get(int index) const
Returns a constant reference to the element stored at the index

oelement_t& get(int index)
Returns a reference to the element stored at the index

ovoid swap(int i, int j)
Swap the elements at index i and index j

ovoid append(const adevs_bag<element_t>& src)
Append the items in the source bag to the end of this bag

ovirtual void removeAll()
Remove all elements from the bag

ovirtual void add(const element_t& e)
Add an element to the end of the bag (ie, at index getSize())

ovirtual 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.

ovoid erase(const element_t& e)
Find and remove the first element equal to e. Equality is determined with the == operator.

ovirtual ~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++.