5520709be9360f6cfa61685d09ff89a117d00d0b
[satune.git] / src / ASTAnalyses / Encoding / subgraph.h
1 #ifndef SUBGRAPH_H
2 #define SUBGRAPH_H
3 #include "classlist.h"
4 #include "structs.h"
5 #include "graphstructs.h"
6
7 class NodeValuePair {
8  public:
9  NodeValuePair(EncodingNode *n, uint64_t val) : node(n), value(val) {}
10         EncodingNode *node;
11         uint64_t value;
12 };
13
14 class EncodingValue {
15  public:
16         void merge(EncodingValue *value);
17         uint64_t value;
18         HashsetEncodingNode nodes;
19 };
20
21 uint hashNodeValuePair(NodeValuePair *nvp);
22 bool equalsNodeValuePair(NodeValuePair *nvp1, NodeValuePair *nvp2);
23
24 typedef Hashtable<NodeValuePair *, EncodingValue *, uintptr_t, 4, hashNodeValuePair, equalsNodeValuePair> NVPMap;
25
26 class EncodingSubGraph {
27  public:
28         EncodingSubGraph();
29         void addNode(EncodingNode *n);
30         SetIteratorEncodingNode * nodeIterator();
31         void encode();
32         
33         CMEMALLOC;
34  private:
35         uint estimateNewSize(EncodingNode *n);
36         uint estimateNewSize(EncodingSubGraph *sg);
37         void traverseValue(EncodingNode *node, uint64_t value);
38
39         
40         HashsetEncodingNode nodes;
41         NVPMap map;
42         uint encodingSize;
43         uint numElements;
44
45         friend class EncodingGraph;
46 };
47
48 #endif