Base Type Requirements for Hash Coding Values

Syntax
code = hash_code(x)

Purpose
CppAD uses a table of Base type values when recording AD<Base> operations. A hashing function is used to reduce number of values stored in this table; for example, it is not necessary to store the value 3.0 every time it is used as a parameter .

Default
The default hashing function works with the set of bits that correspond to a Base value. In most cases this works well, but in some cases it does not. For example, in the base_adolc.hpp case, an adouble value can have fields that are not initialized and valgrind reported an error when these are used to form the hash code.

x
This argument has prototype       const Base& x  It is the value we are forming a hash code for.

code
The return value code has prototype       unsigned short code  It is the hash code corresponding to x . This intention is the commonly used values will have different hash codes. The hash code must satisfy       code < CPPAD_HASH_TABLE_SIZE  so that it is a valid index into the hash code table.

inline
If you define this function, it should declare it to be inline, so that you do not get multiple definitions from different compilation units.

Example
See the base_alloc hash_code and the adouble hash_code .