Basic data types

Basix defines a type nat, meaning “natural integers”, that corresponds to unsigned int within most architecture. Yet no assumption on the size of nat is made for the sake of portability.

The standard ouput stream is mmout, the standard error stream is mmerr, and the standard input is mmin.

1.Strings

Strings are implemented in the class string provided by string.hpp.

 string s = "Hello"; mmout << s << "\n";

Memory allocation is done in a way so that you can write the following piece of code with essentially no lack of efficiency:

 // Remove all \ in s string foo (const string& s) { nat i, n= N(s); string r; for (i=0; i < n; i++) if (s[i] != '\') r << s[i]; return r; }

2.Lists

Lists are implemented in the template class list provided by list.hpp. Usual operations are available from list_sort.hpp.

 list x (1, 2, 3); list y (seq (1, 5)); mmout << "x n= " << x << "\n"; mmout << "y = " << y << "\n"; mmout << "x*y = " << (x*y) << "\n"; mmout << "x==y = " << (x==y) << "\n"; mmout << "x!=y = " << (x!=y) << "\n"; mmout << "x… = " << iterate (x) << "\n";

3.Balanced tree

Balanced tree are implemented in the class chain provided by chain.hpp. Usage is similar to the one of the lists.

4.Heaps

Ordered heaps are provided by heap.hpp.

5.Pairs, triples, tuples

Pairs are provided by pair, and triples in triple.hpp. Tuples are provided by tuple.hpp.

6.Vectors

Arrays are provides by vector.hpp.

 #define C double vector u = vec (C (5), C (7), C (9)); vector v = vec (C (2), C (3), C (5)); mmout << "u = " << u << "\n"; mmout << "v = " << v << "\n"; v *= u;

For efficiency reasons, vectors are indeed parametrized by an abstration layer, that is defined in vector_naive.hpp. For instance vectors of int with fixed size 10 can be obtained as follows:

 vector > x (3);

7.Tables

Hash tables are defined in table.hpp.

 pair x1 (1, 2), x2 (7, 7); table t (seq (x1, x2)); table u (0); u= 8; u= 7; u= 6; u= 5; mmout << "t = " << t << "\n"; mmout << "u = " << u << "\n"; reset (u, 3);

8.Iterators

Iterators are defined in iterator.hpp.

 iterator it1; mmout << "it1 = " << it1 << "\n"; iterator it2 = seq (1, 2, 3); mmout << "it2 = " << it2 << "\n"; iterator it3 = range_iterator (0, 100); list l ("a", "b"); iterator it; for (it = iterate (l); busy (it); ++it) mmout << *it << "\n";

All non-atomic structures have iterators.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License. If you don't have this file, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.