FAQ Database Discussion Community


multiple intersection of lists in R

r,list,set-intersection
I have 4 lists a <- list(1,2,3,4) b <- list(5,6,7,8) c <- list(7,9,0) d <- list(12,14) I would like to know which of the lists have elements in common. In this example, lists b and c have the element 7 in common. A brute force approach would be to take...

Finding the intersect of two arrays in Fortran

arrays,fortran,fortran90,fortran95,set-intersection
I'm trying to generate the intersect of two 1-D arrays in Fortran. The intent is to use this intersection as a mask in maxloc so that I can pull the max few elements from one array into another (behavior analogous to repeated root removal in a max heap). Currently I...

What is the Pythonic way to iterate over set intersection and exclusions?

python,dictionary,set,iteration,set-intersection
set_of_A_key and set_of_B_keyare two set of keys of dictionary dict_A and dict_B. I want operate over the dictionary values for the keys in the following three sets: (set_of_A_key & set_of_B_key), (set_of_A_key - set_of_B_key) and (set_of_B_key - set_of_A_key) What is the pythonic way to do this? This one is elegant with...

C++: How to use set_intersection on two vectors containing user-defined structs?

c++,vector,set-intersection
I have two vectors full of structs that are very simple: typedef struct{ //three vertex ids uint a,b,c; } Face; I'm currently trying to run set_intersection like so: set_intersection(listOfFaces1.begin(),listOfFaces1.end(),listOfFaces2.begin(),listOfFaces2.end(), back_inserter(facesToDelete)); I'm guessing I need to overwrite some comparator somehow? But I'm not sure how to go about defining equality between...

Intersection of N sorted integer arrays with limit

javascript,arrays,algorithm,intersection,set-intersection
Given N sorted arrays of integers (no duplicates), I'd like to calculate the first limit integers in their intersection. For example, given the following arrays: [2, 5, 7, 8, 10, 12, 13, 15, 20, 24] [3, 4, 5, 6, 9, 10, 11, 17, 20] [1, 2, 3, 5, 6, 10,...

Computing efficiently intersection of n sets

algorithm,data-structures,time-complexity,set-intersection
I have n sets identified by setId and each one could contain an arbitrary number of elements that is a pair (elementId, priority). My algorithm should take in input two setId, and give in output a set containing the first m elements which are in the intersection of the two...