Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[1991be]: src / include / compiler / NodeFactory.h Maximize Restore History

Download this file

NodeFactory.h    71 lines (59 with data), 2.0 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#ifndef NODE_FACTORY_H_
#define NODE_FACTORY_H_
#include <vector>
#include <cfloat>
namespace jags {
class Node;
/**
* @short Fuzzy less than function for doubles
*
* Gives an ordering for doubles allowing for some numerical
* tolerance. Values that are "nearly equal" are considered to be
* equal.
*/
inline bool lt(double value1, double value2)
{
return value1 < value2 - 16 * DBL_EPSILON;
}
/**
* @short Fuzzy less than function for arrays of doubles
*
* Gives an ordering for two arrays of doubles of the same length.
* Values that are numerically "nearly equal" are considered to
* be equal.
*/
bool lt(double const *value1, double const *value2, unsigned int length);
/**
* @short Fuzzy less than function for Nodes
*
* Gives an ordering for Nodes that is arbitrary, but reproducible
* within the same process. This is all that is required by the
* various Node factories.
*
* In this ordering fixed nodes come before non-fixed nodes. Fixed
* nodes are ordered within themselves using the fuzzy less than
* operator for their values. Non-fixed nodes are sorted by their
* pointer values (which gives an arbitrary, but strict ordering).
*/
bool lt(Node const *node1, Node const *node2);
/**
* @short Fuzzy less than function for vectors of Nodes
*
* Extends the fuzzy less than operator for Nodes to vectors of
* Nodes. Vectors are first sorted by length, then an element-wise
* comparison of each Node in the vector.
*/
bool lt(std::vector<Node const *> const &par1,
std::vector<Node const *> const &par2);
/**
* Template that constructs a function object from any of the
* above less than functions.
*/
template<typename T> struct fuzzy_less
{
bool operator()(T const &arg1, T const &arg2) const {
return lt(arg1, arg2);
}
};
} /* namespace jags */
#endif /* NODE_FACTORY_H_ */