From: bdemsky Date: Mon, 11 Sep 2017 23:51:30 +0000 (-0700) Subject: More helper functions X-Git-Url: http://plrg.eecs.uci.edu/git/?p=satune.git;a=commitdiff_plain;h=ec6ec7fe30463171e06a2dde68a43103d469348e More helper functions --- diff --git a/src/ASTAnalyses/Encoding/encodinggraph.cc b/src/ASTAnalyses/Encoding/encodinggraph.cc index 8d34d47..8fe908a 100644 --- a/src/ASTAnalyses/Encoding/encodinggraph.cc +++ b/src/ASTAnalyses/Encoding/encodinggraph.cc @@ -222,3 +222,31 @@ void EncodingSubGraph::addNode(EncodingNode *n) { SetIteratorEncodingNode * EncodingSubGraph::nodeIterator() { return nodes.iterator(); } + +uint EncodingSubGraph::computeIntersection(Set *s) { + uint intersect=0; + uint size=s->getSize(); + for(uint i=0; igetElement(i); + if (values.contains(val)) + intersect++; + } + return intersect; +} + +uint EncodingSubGraph::computeIntersection(EncodingSubGraph *g) { + if (g->values.getSize() > values.getSize()) { + //iterator over smaller set + return g->computeIntersection(this); + } + + uint intersect=0; + SetIterator64Int * iter=g->values.iterator(); + while(iter->hasNext()) { + uint64_t val=iter->next(); + if (values.contains(val)) + intersect++; + } + delete iter; + return intersect; +} diff --git a/src/ASTAnalyses/Encoding/encodinggraph.h b/src/ASTAnalyses/Encoding/encodinggraph.h index e44ccfd..4057dd2 100644 --- a/src/ASTAnalyses/Encoding/encodinggraph.h +++ b/src/ASTAnalyses/Encoding/encodinggraph.h @@ -58,6 +58,8 @@ class EncodingSubGraph { EncodingSubGraph(); void addNode(EncodingNode *n); SetIteratorEncodingNode * nodeIterator(); + uint computeIntersection(Set *s); + uint computeIntersection(EncodingSubGraph *g); CMEMALLOC; private: @@ -88,6 +90,4 @@ class EncodingEdge { friend class EncodingGraph; }; - - #endif diff --git a/src/Collections/structs.h b/src/Collections/structs.h index d5d6f5e..2a85eae 100644 --- a/src/Collections/structs.h +++ b/src/Collections/structs.h @@ -27,6 +27,7 @@ typedef Hashset HashsetBoolean; typedef Hashset HashsetElement; typedef SetIterator SetIteratorBoolean; typedef Hashset Hashset64Int; +typedef SetIterator SetIterator64Int; typedef Hashtable HashtableNodeToNodeSet;