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

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; } |

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

list<int> x (1, 2, 3); list<int> 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"; |

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

Ordered heaps are provided by `heap.hpp`.

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

Arrays are provides by `vector.hpp`.

#define C double vector<C> u = vec (C (5), C (7), C (9)); vector<C> 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<C, vector_fixed<vector_naive, fixed_value<nat,10> > x (3); |

Hash tables are defined in `table.hpp`.

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

Iterators are defined in `iterator.hpp`.

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

All non-atomic structures have iterators.

© 2007 Joris van der Hoeven, Grégoire Lecerf

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.