Top   Types   Functions   Classes   Options   Index   Sources 

Announce


Download
Documentation
Design Goals
To use it, you need
To contribute to Erwin, you additionally need
Features
Tools
Basic Library
All Data Structures
Some Idioms To Give an Impression:
Implemented Data Structures

Erwin Library

The Erwin library is a data structure template library for C and C++.

To avoid the C++ template mechanism (it should work for C, too), a Perl script generates C files that are compiled into a library.

The library is heavily used by projects of our research group and in commercial applications. It can be included in other libraries or in applications, works as a C and/or C++ and runs under Unix and Windows.

The implemented data types are vectors (dynamic array) and lists both of arbitrary element types and hash tables (maps) of arbitrary key and value types. The implementation is very efficient and also provides a sophisticated, easy to learn interface with a lot of useful functions, e.g. fprintf-like printing into vectors of char.

Download

http://www.theiling.de/downloads/?name=erwin

Documentation

http://www.theiling.de/refman/erwin2/

http://www.theiling.de/erwin-html/ (old version)

Design Goals

It is not designed to do the following: - be a pure C++ library not using #define

Wrt. the above goals it aims to be the ultimate implementation. :-) To achieve the goals, an instantiation mechanism is used for each data structure.

The library currently has over 60,000 lines of code where around 30,000 are for the data structures themselves, the rest for customisation, instantiation and configuration tools.

To use it, you need

To contribute to Erwin, you additionally need

Features

Tools

untemplatize

this generates template instantiations for the data structures

erwin-cgen

a simple tool for extracting documentation from source files. It is adapted to Erwin template files. In the basic mode, it can extract documentation without relying on hot characters marking relevant comments, so you can possibly generate HTML docu from packages where no-one thought about docu when it was kicked off.

Further, this script can help you generate C++ interfaces more NULL safe and more type-safe.

Finally, it can generate a C interface for a C++ library.

assert.pl

generates macros in a form similar to GTKs g_return_val_if_fail. Only this provides a lot of features, e.g. printing variables in case of an error. These macros even work in the Linux kernel.

makesymbol.pl

extracts identifiers of the form sym_... from source code and generates an include file for use with a symbol table implementation. This way, you can use hashed strings (=symbols) natively in C and C++.

Basic Library

All Data Structures

Some Idioms To Give an Impression:

C++: Dynamic String class:

FILE *f= fopen (VChar().format ("%s.txt", argv[0]), "rt");

Quotation:

FILE *f= popen (
    VChar().format (FO_QUOTE_SHELL, "find . -name %s.txt", argv[0]), "r");

Iterators:

map_forall (m, k, v) {
    ...
}

map_forall_keys_sorted_by_values (m, k) {
    ...
}

vector_forall_values_ptr (v, k) {
    ...
}

Implemented Data Structures

vector

Automatically resized, arbitrary length arrays.

Some Special Features:

map

hash tables

list

singly or doubly linked, with an element counter (faster) or without (smaller).

Please note that vectors are generally more efficient than lists. The only exception being O(1) deletion without changing the order of the list. Almost anything else is slower with lists. That's the reason why this is the youngest data structure.

pvector, pmap, plist

wrappers around vector, map, list: a data structure header file that uses another, full implementation to implement the same structure for different types. A generated header file contains only trampoline routines encapsulating the necessary casts to invoke the corresponding functions of the real data structure implementation. E.g. to implement

vector oType='unsigned *'

an existing data structure

vector oType='int *'

can be used without any byte of code to be generated.

I had a lot of other data structures in mind, but either were they easy and fast to implement for a given purpose (e.g. union-find), or they had too many shades to be implemented generically (e.g. trees).

BTW: The name 'Erwin' comes from German 'Erweiterung' (extension) plus another syllable 'in' to make it sound good. This name has a long tradition. :-)

Index

Stoppt die Vorratsdatenspeicherung
November 26th, 2007
Comments? Suggestions? Corrections? You can drop me a line.
zpentrabvagiktu@theiling.de
Schwerpunktpraxis