Go to the previous, next section.
Bag classes maintain unbounded collections of items potentially containing duplicate elements.
These are currently implemented in several ways, differing in representation strategy, algorithmic efficiency, and appropriateness for various tasks. (Listed next to each are average (followed by worst-case, if different) time complexities for [a] adding, [f] finding (via seek, contains), [d] deleting elements).
XPBags
OXPBags
SLBags
OSLBags
SplayBags
VHBags
CHBags
The implementations differ in whether their constructors
require an argument to specify their initial capacity. Initial
capacities are required for plex and hash table based Bags. If none is
given DEFAULT_INITIAL_CAPACITY
(from `<T>defs.h') is used.
Bags support the following operations, for some class Bag
,
instances a
and b
, Pix ind
, and base
element x
. Since all implementations are virtual derived classes
of the <T>Bag
class, it is possible to mix and match operations
across different implementations, although, as usual, operations
are generally faster when the particular classes are specified
in functions operating on Bags.
Pix-based operations are more fully described in the section on Pixes. See section Pseudo-indexes
Bag a; or Bag a(int initial_size)
a.empty()
a.length()
ind = a.add(x)
a.del(x)
a.remove(x)
a.clear()
a.contains(x)
a.nof(x)
a(ind)
int = a.first()
a.next(ind)
ind = a.seek(x. Pix from = 0)
Go to the previous, next section.