More helper functions
authorbdemsky <bdemsky@uci.edu>
Mon, 11 Sep 2017 23:51:30 +0000 (16:51 -0700)
committerbdemsky <bdemsky@uci.edu>
Mon, 11 Sep 2017 23:51:30 +0000 (16:51 -0700)
src/ASTAnalyses/Encoding/encodinggraph.cc
src/ASTAnalyses/Encoding/encodinggraph.h
src/Collections/structs.h

index 8d34d47..8fe908a 100644 (file)
@@ -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; i<size; i++) {
+               uint64_t val=s->getElement(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;
+}
index e44ccfd..4057dd2 100644 (file)
@@ -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
index d5d6f5e..2a85eae 100644 (file)
@@ -27,6 +27,7 @@ typedef Hashset<Boolean *, uintptr_t, PTRSHIFT> HashsetBoolean;
 typedef Hashset<Element *, uintptr_t, PTRSHIFT> HashsetElement;
 typedef SetIterator<Boolean *, uintptr_t, PTRSHIFT> SetIteratorBoolean;
 typedef Hashset<uint64_t, uint64_t, 0> Hashset64Int;
+typedef SetIterator<uint64_t, uint64_t, 0> SetIterator64Int;
 
 
 typedef Hashtable<OrderNode *, HashsetOrderNode *, uintptr_t, PTRSHIFT> HashtableNodeToNodeSet;