Menu

[r12]: / trunk / libtop_engine / psearch_pattern.h  Maximize  Restore  History

Download this file

252 lines (185 with data), 6.2 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
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
#ifndef PSEARCH_PATTERN_H_
#define PSEARCH_PATTERN_H_
#include "psearch_core.h"
namespace psearch {
/////////////////////////////////////////////////////////////////////////////////////////
// class Pattern
//
// Contains 3 set of associated nodes:
// o nodes defining the pattern's neccessairy and sufficient criteria (c1 nodes)
// o nodes defining the pattern's neccessairy criteria (c2 nodes; c2 includes c1 nodes.)
// o nodes explicitly excluded from pattern - negated nodes.
/////////////////////////////////////////////////////////////////////////////////////////
class Pattern: public PSBase
{
public:
inline Pattern(PSearchDB * db_p, index_type index):
PSBase(db_p, index),
m_weight(0),
m_c1_nodes(),
m_c2_nodes(),
m_negated_nodes(),
m_is_active(true),
m_rule_index()
{};
inline pattern_index_type
get_pattern_index()const
{
return this;
};
inline bool
is_active() const
{
return m_is_active;
};
inline unsigned int
get_weight() const
{
return m_weight;
};
// this consider only nodes (not negated_nodes)
inline bool
is_c1_node(node_index_type node_index)const
{
return m_c1_nodes.find(node_index) != m_c1_nodes.end();
};
// which includes c1 nodes.
inline bool
is_c2_node(node_index_type node_index)const
{
return m_c2_nodes.find(node_index) != m_c2_nodes.end();
};
// based on negated_node
inline bool
is_negated_by_node(node_index_type node_index)const
{
return m_negated_nodes.find(node_index) != m_negated_nodes.end();
};
inline node_const_iterator_type
get_c1_nodes_begin()const
{
return m_c1_nodes.begin();
};
inline node_const_iterator_type
get_c1_nodes_end()const
{
return m_c1_nodes.end();
};
inline node_set_const_iterator
get_c1_nodes_iterator()const
{
return node_set_const_iterator(get_c1_nodes_begin(), get_c1_nodes_end());
};
inline node_const_iterator_type
get_c2_nodes_begin()const
{
return m_c2_nodes.begin();
};
inline node_const_iterator_type
get_c2_nodes_end()const
{
return m_c2_nodes.end();
};
inline node_set_const_iterator
get_c2_nodes_iterator()const
{
return node_set_const_iterator(get_c2_nodes_begin(), get_c2_nodes_end());
};
inline node_const_iterator_type
get_negated_nodes_begin()const
{
return m_negated_nodes.begin();
};
inline node_const_iterator_type
get_negated_nodes_end()const
{
return m_negated_nodes.end();
};
inline node_set_const_iterator
get_negated_nodes_iterator()const
{
return node_set_const_iterator(get_negated_nodes_begin(), get_negated_nodes_end());
};
inline rule_index_type
get_rule_index()const
{
return m_rule_index;
};
protected:
inline void
set_active(bool b)
{
m_is_active = b;
};
inline void
set_weight(unsigned int weight)
{
m_weight = weight;
};
inline void
add_c1_node(node_index_type node_index)
{
if(!node_index) return;
m_c1_nodes.insert(node_index);
m_c2_nodes.insert(node_index);
};
inline void
add_c2_node(node_index_type node_index)
{
if(!node_index) return;
m_c2_nodes.insert(node_index);
};
inline void
add_negated_node(node_index_type node_index)
{
if(!node_index) return;
m_negated_nodes.insert(node_index);
};
inline void
remove_c1_node(node_index_type node_index)
{
m_c1_nodes.erase(node_index);
m_c2_nodes.erase(node_index);
};
inline void
remove_c2_node(node_index_type node_index)
{
m_c2_nodes.erase(node_index);
};
inline void
remove_negated_node(node_index_type node_index)
{
m_negated_nodes.erase(node_index);
};
inline void
remove_all_nodes()
{
m_c1_nodes.clear();
m_c2_nodes.clear();
m_negated_nodes.clear();
};
inline void
set_rule_index(rule_index_type rule_index)
{
m_rule_index = rule_index;
};
private:
friend class PSearchDB;
friend class Rule;
friend class Category;
friend std::ostream& operator<<(std::ostream& out, Pattern const& pattern);
friend std::ostream& operator<<(std::ostream& out, pattern_index_type pattern_index);
unsigned int m_weight;
node_set_type m_c1_nodes;
node_set_type m_c2_nodes;
node_set_type m_negated_nodes;
bool m_is_active;
rule_index_type m_rule_index;
};
inline std::ostream& operator<<(std::ostream& out, pattern_index_type pattern_index)
{
out << *pattern_index;
return out;
};
}; /* psearch namespace */
#endif /*PSEARCH_PATTERN_H_*/
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.