1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
#ifndef GOOSE_EIR_MATCH_H
#define GOOSE_EIR_MATCH_H
namespace goose::eir
{
class MatchSolution
{
public:
size_t complexity() const { return m_complexity; }
size_t numVars() const;
template< typename T >
const T* getVar( const StringId& name ) const
{
if( name == "_"_sid )
return nullptr;
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
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
|
#ifndef GOOSE_EIR_MATCH_H
#define GOOSE_EIR_MATCH_H
namespace goose::eir
{
struct MatchScore
{
size_t m_complexity = 0;
size_t m_numVars = 0;
bool operator<( const MatchScore& rhs ) const
{
if( m_complexity != rhs.m_complexity )
return m_complexity < rhs.m_complexity;
return m_numVars > rhs.m_numVars;
}
bool operator>( const MatchScore& rhs ) const
{
if( m_complexity != rhs.m_complexity )
return m_complexity > rhs.m_complexity;
return m_numVars < rhs.m_numVars;
}
};
class MatchSolution
{
public:
size_t complexity() const { return m_complexity; }
size_t numVars() const;
MatchScore score() const { return MatchScore{ m_complexity, m_pVars ? m_pVars->size() : 0 }; }
template< typename T >
const T* getVar( const StringId& name ) const
{
if( name == "_"_sid )
return nullptr;
|
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
setupVars();
m_pVars->emplace( name, forward< T >( val ) );
return true;
}
void addComplexity( uint32_t n ) { m_complexity += n; }
bool operator<( const MatchSolution& rhs ) const
{
if( m_complexity != rhs.m_complexity )
return m_complexity < rhs.m_complexity;
return numVars() > rhs.numVars();
}
bool operator>( const MatchSolution& rhs ) const
{
if( m_complexity != rhs.m_complexity )
return m_complexity > rhs.m_complexity;
return numVars() < rhs.numVars();
}
private:
void setupVars();
ptr< unordered_map< StringId, any > > m_pVars;
uint32_t m_complexity = 0; // Each matched structural element of the pattern (vector) adds 1,
// each matched literal element of the pattern adds 2
};
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
setupVars();
m_pVars->emplace( name, forward< T >( val ) );
return true;
}
void addComplexity( uint32_t n ) { m_complexity += n; }
private:
void setupVars();
ptr< unordered_map< StringId, any > > m_pVars;
uint32_t m_complexity = 0; // Each matched structural element of the pattern (vector) adds 1,
// each matched literal element of the pattern adds 2
};
|