#include "csolver.h"
#include "tunable.h"
#include "qsort.h"
+#include "subgraph.h"
EncodingGraph::EncodingGraph(CSolver * _solver) :
solver(_solver) {
return numEquals * min + numComparisons * lSize * rSize;
}
-EncodingSubGraph::EncodingSubGraph() :
- encodingSize(0),
- numElements(0) {
-}
-
-uint EncodingSubGraph::estimateNewSize(EncodingSubGraph *sg) {
- uint newSize=0;
- SetIteratorEncodingNode * nit = sg->nodes.iterator();
- while(nit->hasNext()) {
- EncodingNode *en = nit->next();
- uint size=estimateNewSize(en);
- if (size > newSize)
- newSize = size;
- }
- delete nit;
- return newSize;
-}
-uint EncodingSubGraph::estimateNewSize(EncodingNode *n) {
- SetIteratorEncodingEdge * eeit = n->edges.iterator();
- uint newsize=n->getSize();
- while(eeit->hasNext()) {
- EncodingEdge * ee = eeit->next();
- if (ee->left != NULL && ee->left != n && nodes.contains(ee->left)) {
- uint intersectSize = n->s->getUnionSize(ee->left->s);
- if (intersectSize > newsize)
- newsize = intersectSize;
- }
- if (ee->right != NULL && ee->right != n && nodes.contains(ee->right)) {
- uint intersectSize = n->s->getUnionSize(ee->right->s);
- if (intersectSize > newsize)
- newsize = intersectSize;
- }
- if (ee->dst != NULL && ee->dst != n && nodes.contains(ee->dst)) {
- uint intersectSize = n->s->getUnionSize(ee->dst->s);
- if (intersectSize > newsize)
- newsize = intersectSize;
- }
- }
- delete eeit;
- return newsize;
-}
-
-void EncodingSubGraph::addNode(EncodingNode *n) {
- nodes.add(n);
- uint newSize=estimateNewSize(n);
- numElements += n->elements.getSize();
- if (newSize > encodingSize)
- encodingSize=newSize;
-}
-
-SetIteratorEncodingNode * EncodingSubGraph::nodeIterator() {
- return nodes.iterator();
-}
#define ENCODINGGRAPH_H
#include "classlist.h"
#include "structs.h"
-
-uint hashEncodingEdge(EncodingEdge *edge);
-bool equalsEncodingEdge(EncodingEdge *e1, EncodingEdge *e2);
-class EncodingSubGraph;
-
-
-typedef Hashtable<EncodingEdge *, EncodingEdge *, uintptr_t, PTRSHIFT, hashEncodingEdge, equalsEncodingEdge> HashtableEdge;
-typedef Hashset<EncodingNode *, uintptr_t, PTRSHIFT> HashsetEncodingNode;
-typedef SetIterator<EncodingNode *, uintptr_t, PTRSHIFT> SetIteratorEncodingNode;
-typedef Hashset<EncodingEdge *, uintptr_t, PTRSHIFT> HashsetEncodingEdge;
-typedef SetIterator<EncodingEdge *, uintptr_t, PTRSHIFT> SetIteratorEncodingEdge;
-
-typedef Hashtable<EncodingNode *, EncodingSubGraph *, uintptr_t, PTRSHIFT> HashtableNodeToSubGraph;
+#include "graphstructs.h"
class EncodingGraph {
public:
friend class EncodingSubGraph;
};
-class EncodingSubGraph {
- public:
- EncodingSubGraph();
- void addNode(EncodingNode *n);
- SetIteratorEncodingNode * nodeIterator();
-
- CMEMALLOC;
- private:
- uint estimateNewSize(EncodingNode *n);
- uint estimateNewSize(EncodingSubGraph *sg);
-
- HashsetEncodingNode nodes;
- uint encodingSize;
- uint numElements;
-
- friend class EncodingGraph;
-};
-
enum EdgeEncodingType { EDGE_UNASSIGNED, EDGE_BREAK, EDGE_MATCH};
typedef enum EdgeEncodingType EdgeEncodingType;
--- /dev/null
+#ifndef GRAPHSTRUCTS_H
+#define GRAPHSTRUCTS_H
+#include "classlist.h"
+#include "structs.h"
+
+uint hashEncodingEdge(EncodingEdge *edge);
+bool equalsEncodingEdge(EncodingEdge *e1, EncodingEdge *e2);
+class EncodingSubGraph;
+
+
+typedef Hashtable<EncodingEdge *, EncodingEdge *, uintptr_t, PTRSHIFT, hashEncodingEdge, equalsEncodingEdge> HashtableEdge;
+typedef Hashset<EncodingNode *, uintptr_t, PTRSHIFT> HashsetEncodingNode;
+typedef SetIterator<EncodingNode *, uintptr_t, PTRSHIFT> SetIteratorEncodingNode;
+typedef Hashset<EncodingEdge *, uintptr_t, PTRSHIFT> HashsetEncodingEdge;
+typedef SetIterator<EncodingEdge *, uintptr_t, PTRSHIFT> SetIteratorEncodingEdge;
+
+typedef Hashtable<EncodingNode *, EncodingSubGraph *, uintptr_t, PTRSHIFT> HashtableNodeToSubGraph;
+#endif
--- /dev/null
+#include "subgraph.h"
+#include "encodinggraph.h"
+#include "set.h"
+
+EncodingSubGraph::EncodingSubGraph() :
+ encodingSize(0),
+ numElements(0) {
+}
+
+uint hashNodeValuePair(NodeValuePair *nvp) {
+ return (uint) (nvp->value ^ ((uintptr_t)nvp->node));
+}
+
+bool equalsNodeValuePair(NodeValuePair *nvp1, NodeValuePair *nvp2) {
+ return nvp1->value == nvp2->value && nvp1->node == nvp2->node;
+}
+
+uint EncodingSubGraph::estimateNewSize(EncodingSubGraph *sg) {
+ uint newSize=0;
+ SetIteratorEncodingNode * nit = sg->nodes.iterator();
+ while(nit->hasNext()) {
+ EncodingNode *en = nit->next();
+ uint size=estimateNewSize(en);
+ if (size > newSize)
+ newSize = size;
+ }
+ delete nit;
+ return newSize;
+}
+
+uint EncodingSubGraph::estimateNewSize(EncodingNode *n) {
+ SetIteratorEncodingEdge * eeit = n->edges.iterator();
+ uint newsize=n->getSize();
+ while(eeit->hasNext()) {
+ EncodingEdge * ee = eeit->next();
+ if (ee->left != NULL && ee->left != n && nodes.contains(ee->left)) {
+ uint intersectSize = n->s->getUnionSize(ee->left->s);
+ if (intersectSize > newsize)
+ newsize = intersectSize;
+ }
+ if (ee->right != NULL && ee->right != n && nodes.contains(ee->right)) {
+ uint intersectSize = n->s->getUnionSize(ee->right->s);
+ if (intersectSize > newsize)
+ newsize = intersectSize;
+ }
+ if (ee->dst != NULL && ee->dst != n && nodes.contains(ee->dst)) {
+ uint intersectSize = n->s->getUnionSize(ee->dst->s);
+ if (intersectSize > newsize)
+ newsize = intersectSize;
+ }
+ }
+ delete eeit;
+ return newsize;
+}
+
+void EncodingSubGraph::addNode(EncodingNode *n) {
+ nodes.add(n);
+ uint newSize=estimateNewSize(n);
+ numElements += n->elements.getSize();
+ if (newSize > encodingSize)
+ encodingSize=newSize;
+}
+
+SetIteratorEncodingNode * EncodingSubGraph::nodeIterator() {
+ return nodes.iterator();
+}
+
+void EncodingSubGraph::encode() {
+ SetIteratorEncodingNode *nodeit=nodes.iterator();
+ while(nodeit->hasNext()) {
+ EncodingNode *node=nodeit->next();
+ Set * set = node->s;
+ uint setSize = set->getSize();
+ for(uint i=0; i<setSize; i++) {
+ uint64_t val = set->getElement(i);
+ NodeValuePair nvp(node, val);
+ if (!map.contains(&nvp)) {
+ traverseValue(node, val);
+ }
+ }
+ }
+ delete nodeit;
+}
+
+void EncodingSubGraph::traverseValue(EncodingNode *node, uint64_t value) {
+
+}
--- /dev/null
+#ifndef SUBGRAPH_H
+#define SUBGRAPH_H
+#include "classlist.h"
+#include "structs.h"
+#include "graphstructs.h"
+
+class NodeValuePair {
+ public:
+ NodeValuePair(EncodingNode *n, uint64_t val) : node(n), value(val) {}
+ EncodingNode *node;
+ uint64_t value;
+};
+
+class EncodingValue {
+ public:
+ void merge(EncodingValue *value);
+ uint64_t value;
+ HashsetEncodingNode nodes;
+};
+
+uint hashNodeValuePair(NodeValuePair *nvp);
+bool equalsNodeValuePair(NodeValuePair *nvp1, NodeValuePair *nvp2);
+
+typedef Hashtable<NodeValuePair *, EncodingValue *, uintptr_t, 4, hashNodeValuePair, equalsNodeValuePair> NVPMap;
+
+class EncodingSubGraph {
+ public:
+ EncodingSubGraph();
+ void addNode(EncodingNode *n);
+ SetIteratorEncodingNode * nodeIterator();
+ void encode();
+
+ CMEMALLOC;
+ private:
+ uint estimateNewSize(EncodingNode *n);
+ uint estimateNewSize(EncodingSubGraph *sg);
+ void traverseValue(EncodingNode *node, uint64_t value);
+
+
+ HashsetEncodingNode nodes;
+ NVPMap map;
+ uint encodingSize;
+ uint numElements;
+
+ friend class EncodingGraph;
+};
+
+#endif