CppAD: A C++ Algorithmic Differentiation Package  20171217
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
local/optimize/hash_code.hpp
Go to the documentation of this file.
1 # ifndef CPPAD_LOCAL_OPTIMIZE_HASH_CODE_HPP
2 # define CPPAD_LOCAL_OPTIMIZE_HASH_CODE_HPP
3 
4 /* --------------------------------------------------------------------------
5 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell
6 
7 CppAD is distributed under multiple licenses. This distribution is under
8 the terms of the
9  Eclipse Public License Version 1.0.
10 
11 A copy of this license is included in the COPYING file of this distribution.
12 Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
13 -------------------------------------------------------------------------- */
14 /*!
15 \file local/optimize/hash_code.hpp
16 CppAD hashing utility.
17 */
18 
19 
20 // BEGIN_CPPAD_LOCAL_OPTIMIZE_NAMESPACE
21 namespace CppAD { namespace local { namespace optimize {
22 /*!
23 Specialized hash code for a CppAD operator and its arguments
24 (used during optimization).
25 
26 \param op
27 is the operator that we are computing a hash code for.
28 
29 \param num_arg
30 number of elements of arg to include in the hash code
31 (num_arg <= 3).
32 
33 \param arg
34 is a vector of length num_arg
35 containing the corresponding argument indices for this operator.
36 
37 \return
38 is a hash code that is between zero and CPPAD_HASH_TABLE_SIZE - 1.
39 */
40 
41 inline size_t optimize_hash_code(
42  OpCode op ,
43  size_t num_arg ,
44  const addr_t* arg )
45 {
46  // there is only one case where num_arg == 3
47  CPPAD_ASSERT_UNKNOWN( op == ErfOp || num_arg <= 2 );
48  CPPAD_ASSERT_UNKNOWN( num_arg <= 3 );
49  size_t sum = size_t(op);
50  for(size_t i = 0; i < num_arg; i++)
51  sum += size_t(arg[i]);
52  //
53  return sum % CPPAD_HASH_TABLE_SIZE;
54 }
55 
56 } } } // END_CPPAD_LOCAL_OPTIMIZE_NAMESPACE
57 
58 # endif
CPPAD_TAPE_ADDR_TYPE addr_t
Definition: declare_ad.hpp:44
size_t optimize_hash_code(OpCode op, size_t num_arg, const addr_t *arg)
Specialized hash code for a CppAD operator and its arguments (used during optimization).
OpCode
Type used to distinguish different AD&lt; Base &gt; atomic operations.
Definition: op_code.hpp:49
#define CPPAD_ASSERT_UNKNOWN(exp)
Check that exp is true, if not terminate execution.
#define CPPAD_HASH_TABLE_SIZE
the codes retruned by hash_code are between zero and CPPAD_HASH_TABLE_SIZE minus one.
Definition: base_hash.hpp:82