set-intersection

Find intersection sets between list of sets

拜拜、爱过 提交于 2019-12-23 16:24:33
问题 The following question is on python 3.6. Suppose I have lists of sets, for example L1 = [{2,7},{2,7,8},{2,3,6,7},{1,2,4,5,7}] L2 = [{3,6},{1,3,4,6,7},{2,3,5,6,8}] L3 = [{2,5,7,8},{1,2,3,5,7,8}, {2,4,5,6,7,8}] I need to find all the intersection sets between each element of L1, L2, and L3. E.g.: {2,7}.intersection({3,6}).intersection({2,5,7,8})= empty {2,7}.intersection({3,6}).intersection({1,2,3,5,7,8})= empty {2,7}.intersection({3,6}).intersection({2,4,5,6,7,8})= empty {2,7}.intersection({1

How do I check if one vector is a subset of another?

◇◆丶佛笑我妖孽 提交于 2019-12-21 03:32:53
问题 Currently, I think my best option is to use std::set_intersection, and then check if the size of the smaller input is the same as the number of elements filled by set_intersection. Is there a better solution? 回答1: Try this: if (std::includes(set_one.begin(), set_one.end(), set_two.begin(), set_two.end())) { // ... } About includes(). The includes() algorithm compares two sorted sequences and returns true if every element in the range [start2, finish2) is contained in the range [start1,

Best way to find the intersection of multiple sets?

血红的双手。 提交于 2019-12-16 22:21:41
问题 I have a list of sets: setlist = [s1,s2,s3...] I want s1 ∩ s2 ∩ s3 ... I can write a function to do it by performing a series of pairwise s1.intersection(s2) , etc. Is there a recommended, better, or built-in way? 回答1: From Python version 2.6 on you can use multiple arguments to set.intersection(), like u = set.intersection(s1, s2, s3) If the sets are in a list, this translates to: u = set.intersection(*setlist) where *a_list is list expansion Note that set.intersection is not a static method

R: How to efficiently find out whether data.frame A is contained in data.frame B?

核能气质少年 提交于 2019-12-13 15:06:20
问题 In order to find out whether data frame df.a is a subset of data frame df.b I did the following: df.a <- data.frame( x=1:5, y=6:10 ) df.b <- data.frame( x=1:7, y=6:12 ) inds.x <- as.integer( lapply( df.a$x, function(x) which(df.b$x == x) )) inds.y <- as.integer( lapply( df.a$y, function(y) which(df.b$y == y) )) identical( inds.x, inds.y ) The last line gave TRUE , hence df.a is contained in df.b . Now I wonder whether there is a more elegant - and possibly more efficient - way to answer this

Union of All Intersecting Sets

浪子不回头ぞ 提交于 2019-12-13 14:09:32
问题 Given a list of objects with multiple attributes I need to find the list of sets created by a union of all intersecting subsets. Specifically these are Person objects, each with many attributes. I need to create a list of 'master' sets based on a handful of unique identifiers such as SSN, DLN, etc. For instance, if Person A and Person B have the same SSN they create a set i. Then if Person B and C have the same DLN, they create a set ii. Person D and E have the same SSN but it (and all other

Boost.MultiIndex: How to make an effective set intersection?

隐身守侯 提交于 2019-12-12 11:13:25
问题 assume that we have a data1 and data2 . How can I intersect them with std::set_intersect() ? struct pID { int ID; unsigned int IDf;// postition in the file pID(int id,const unsigned int idf):ID(id),IDf(idf){} bool operator<(const pID& p)const { return ID<p.ID;} }; struct ID{}; struct IDf{}; typedef multi_index_container< pID, indexed_by< ordered_unique< tag<IDf>, BOOST_MULTI_INDEX_MEMBER(pID,unsigned int,IDf)>, ordered_non_unique< tag<ID>,BOOST_MULTI_INDEX_MEMBER(pID,int,ID)> > > pID_set; ID

Another Scala CanBuildFrom issue: a collection enrichment operator that wraps another of a different type

会有一股神秘感。 提交于 2019-12-11 03:48:43
问题 User Régis Jean-Gilles gracefully answered my previous question where I was struggling with CanBuildFrom and enrichment functions (aka "pimp my library" or "enrich my library"): Creating an implicit function that wraps map() in Scala with the right type: Not for the faint at heart But this time I've got an even more complicated issue. I have a function to implement variations on intersectWith , for intersecting collections by their keys. I've managed to make them work like proper collection

PHP: array_uintersect() unexpected behaviour

99封情书 提交于 2019-12-10 19:08:11
问题 Test script $i = 0; array_uintersect(['foo', 'bar'], ['baz', 'qux'], function($a, $b) use (&$i) { print_r([$a, $b, $i++]); }); Actual Result Array ( [0] => bar [1] => foo [2] => 0 ) Array ( [0] => qux [1] => baz [2] => 1 ) Array ( [0] => bar [1] => qux [2] => 2 ) Array ( [0] => bar [1] => foo [2] => 3 ) Expected Result Array ( [0] => foo [1] => baz [2] => 0 ) Array ( [0] => bar [1] => qux [2] => 1 ) In other words, what I am expecting to be passed to the callback is the current element of the

set_intersection for two different types of sets

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-10 13:22:45
问题 Is there any way to do std::set_intersection on two different types of sets? I have two sets: std::set<X1> l_set1; std::set<X2> l_set2; I'm able to define some comparator for them that checks if X1 and X2 are equal. struct sample_comparer { bool operator()(const &X1 p_left, const &X2 p_right) { return p_left == p_right; } }; Now, I try to do a set intersection on those two sets: std::set<X1> l_intersect; std::set_intersection(l_set1.begin(), l_set1.end(), l_set2.begin(), l_set2.end(), std:

Trying to understand “except all” in sql query

别等时光非礼了梦想. 提交于 2019-12-10 03:45:03
问题 I came across this example and I don't understand what it means. (SELECT drinker FROM Frequents) EXCEPT ALL (SELECT drinker FROM Likes); relations: Frequents(drinker, bar), Likes(drinker, beer) What does the ALL do in this case? How is the result different from the query below? (SELECT drinker FROM Frequents) EXCEPT (SELECT drinker FROM Likes); 回答1: The SQL EXCEPT operator takes the distinct rows of one query and returns the rows that do not appear in a second result set. The EXCEPT ALL