lib: add Set::union and Set::intersection from pep8analysis
authorAlexis Laferrière <alexis.laf@xymus.net>
Mon, 3 Feb 2014 03:43:26 +0000 (22:43 -0500)
committerAlexis Laferrière <alexis.laf@xymus.net>
Mon, 3 Feb 2014 15:21:52 +0000 (10:21 -0500)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

contrib/pep8analysis/Makefile
contrib/pep8analysis/src/flow_analysis/framework.nit
lib/standard/collection/abstract_collection.nit
lib/standard/collection/array.nit
lib/standard/collection/hash_collection.nit

index 7d05a20..d7e081e 100644 (file)
@@ -1,9 +1,9 @@
 bin/pep8analysis:
        mkdir -p bin
-       ../../bin/nitg --global -o bin/pep8analysis -I lib src/pep8analysis.nit
+       ../../bin/nitg --global -o bin/pep8analysis src/pep8analysis.nit
 
 doc/index.html:
-       ../../bin/nitdoc -I lib src/pep8analysis.nit
+       ../../bin/nitdoc src/pep8analysis.nit
 
 tests: bin/pep8analysis
        bin/pep8analysis --cfg-long tests/privat/*.pep tests/laf/*.pep tests/terrasa/*.pep
index 57444e4..a2e9e65 100644 (file)
@@ -1,5 +1,4 @@
 import cfg
-import advanced_collections
 
 class FlowAnalysis[S]
        super Visitor
index ab04618..3241920 100644 (file)
@@ -272,6 +272,25 @@ interface Set[E: Object]
                for e in self do res += res.hash
                return res
        end
+
+       # Returns the union of this set with the `other` set
+       fun union(other: Set[E]): Set[E]
+       do
+               var nhs = new_set
+               nhs.add_all self
+               nhs.add_all other
+               return nhs
+       end
+
+       # Returns the intersection of this set with the `other` set
+       fun intersection(other: Set[E]): Set[E]
+       do
+               var nhs = new_set
+               for v in self do if other.has(v) then nhs.add(v)
+               return nhs
+       end
+
+       protected fun new_set: Set[E] is abstract
 end
 
 # MapRead are abstract associative collections: `key` -> `item`.
index 5de71cd..8c3fe46 100644 (file)
@@ -424,6 +424,8 @@ class ArraySet[E: Object]
 
        # Create an empty set with a given capacity.
        init with_capacity(i: Int) do _array = new Array[E].with_capacity(i)
+
+       redef fun new_set do return new ArraySet[E]
 end
 
 # Iterators on sets implemented with arrays.
index 7f73c3b..f4a1120 100644 (file)
@@ -440,6 +440,8 @@ class HashSet[E: Object]
                init
                add_all(coll)
        end
+
+       redef fun new_set do return new HashSet[E]
 end
 
 private class HashSetNode[E: Object]