|
Gustaaf Brooijmans
Fermilab, MS # 357 Tel: +1 (630) 840 4269 |
If you've come this far, you know that at level 3 we are trying to avoid using the containers provided by the c++ standard library (vector, list , map, queue) etc. The reason for this is that most of these make heavy use of dynamic memory allocation, a process which can often be very (cpu-) time consuming. However, we frequently need the functionality provided by these containers, so we have developed our own. The following is a list of the containers for level 3 tools:
l3vector offers all the methods std::vector offers, like size(), resize(), reserve(), operator[ ], etc., but only 2 constructors: the default constructor and
l3vector also offers an internal counter (to be used if one desires an l3vector with a predetermined number of elements but a variable number actually used). To use this counter effectively, the following methods are available:
1) Usage as in std::vector:
In this case, you can use push_back etc. and l3end() will point to the same place as end().
!!! Note!!! If you use resize(n) on this l3vector, you _need_ to issue a set_count(n) too!!!
The following methods deal with the internal counter automatically (these are in fact all the std::vector methods except for resize(size_type n)):
void
push_back(const T& x);
void
pop_back();
iterator
insert(iterator position);
iterator
insert(iterator position, const T& x);
void
insert(iterator position, size_type n, const T& x);
iterator
erase(iterator position);
iterator
erase(iterator first, iterator last);
void
clear();
2) Usage for which the l3end() feature was created:
You probably want to use something like
l3vector<int> mytest(100,true);
and fill elements using the [] operator, keeping
track of everything using increment_count(), decrement_count(), and reset_count.
If you've used push_back(x), that pushes back at the end of the vector
(in the example above it creates element 101). You may want use that
when reaching the end (although it's more likely you'd use resize()).
Using push_back will increment the count automatically.
!!! In this case, resize(n) should _not_ be
accompanied by set_count(n), that would defeat the purpose of the scheme!!!!
Example code using these features can be found
in
l3types_t.cpp, in package l3utilities
versions v00-01-28 and higher.
Note that it is the user's responsibility
to increment and reset the counter, and verify that it does not
go beyond the vector's size.
Note that all users of l3vector are encouraged to use l3end() rather than end()!
l3string behaves exactly like std::string.
l3map offers all the methods std::map offers, but only has the
default constructor. If you would like to use a map but need to store
a large number of elements which are not indexed by l3strings (for
that see below), please contact me.
This map is meant for large maps (i.e. with many,many elements) which
are indexed by string. An example of how to use this map, also
illustrating most associated methods, can be found in l3stringhashmap_t.cpp
That's it for now. If you need another container, feel free to ask for it.
As usual, comments, questions? -> contact
me.
| Main Page | Next Episode |