Questions tagged [set-intersection]

The intersection of two or more sets consists of the elements that those sets all have in common.

Set intersection is a mathematical operation defined upon sets.
The intersection of two or more sets is defined as the set of those elements that are present in all sets.

For example, let A = { 2, 3, 4 } and B = { 2, 4, 5 }.
The intersection of A and B is what the set of elements that A and B have in common: { 2, 4 }.
The symbol for intersection is ∩, so in our example we would write A ∩ B = { 2, 4 }

276 questions
7
votes
2 answers

How to compute intersection of N sorted sets?

The example below shows how to compute the intersection of two sets. Does the STL provide tools that allow to do this not only for 2 but for N sets? #include #include #include int main() { std::vector v1…
Gilfoyle
  • 3,282
  • 3
  • 47
  • 83
7
votes
2 answers

jq: select when any value is in array

Given the input json [ {"title": "first line"}, {"title": "second line"}, {"title": "third line"} ] How can we extract only the titles that contain keywords that are listed in a second "filter" array. Using a shell variable here for…
Bernard
  • 16,149
  • 12
  • 63
  • 66
7
votes
2 answers

Probability of the Union of Three or More Sets

Consider the following sets of probabilities (the three events are NOT mutually exclusive): 0.05625 success, 0.94375 failure 0.05625 success, 0.94375 failure 0.05625 success, 0.94375 failure How do I compute the probability of at least one event…
landroni
  • 2,902
  • 1
  • 32
  • 39
7
votes
1 answer

Python: Finding corresponding indices for an intersection of two lists

This is somewhat related to a question I asked not too long ago today. I am taking the intersection of two lists as follows: inter = set(NNSRCfile['datetimenew']).intersection(catdate) The two components that I am taking the intersection of…
user1620716
  • 1,463
  • 6
  • 17
  • 26
6
votes
2 answers

Efficient code to do set operations with bigz-class values?

The current release of the package gmp does not support set operations such as intersect, setdiff , etc. I'm doing some work with number sequences (see OEIS for examples) and need to handle large collections of large integers. I'm currently…
Carl Witthoft
  • 20,573
  • 9
  • 43
  • 73
6
votes
3 answers

Is there a zero-copy way to find the intersection of an arbitrary number of sets?

Here is a simple example demonstrating what I'm trying to do: use std::collections::HashSet; fn main() { let mut sets: Vec> = vec![]; let mut set = HashSet::new(); set.insert('a'); set.insert('b'); …
TechnoSam
  • 578
  • 1
  • 8
  • 23
6
votes
3 answers

Extract intersection list from upset object

I'm making some comparisons with UpSetR, and I'd like to save the lists of elements that fall into each intersection. Is this possible? I can't find it anywhere... It would be pretty tedious to do it manually (many lists), and since they're…
Matteo
  • 265
  • 5
  • 16
6
votes
5 answers

Finding the intersection of two circles

I'm trying to find the intersections between two circles in Python(using Matplotlib) but can't get any values back. I'm doing this by creating lists of X's and Y's for each individual circle(Matplotlib takes the first argument as X values and the…
dawed1999
  • 335
  • 1
  • 3
  • 11
6
votes
3 answers

unable to apply std::set_intersection on different types of structs with a common field

I am trying to use use std::set_intersection to find common elements between 2 completely different types of data structures that have a common binding 'name' field. I looked at the following enter link description here but it seems to force me…
johnco3
  • 2,401
  • 4
  • 35
  • 67
5
votes
1 answer

Computing set intersection and set difference of the records of two files with hadoop

Sorry for cross-posting this on the hadoop user mailing list and here, but this is getting an urgent matter for me. My problem is as follows: I have two input files, and I want to determine a) The number of lines which only occur in file 1 b) The…
raven_arkadon
  • 390
  • 1
  • 5
  • 11
5
votes
1 answer

Why is finding the intersection of integer sets faster with a Vec compared to BTreeSet?

I need to find out how many integers are present in both of two given sets, fast. The sets are written to only once but this operation will be performed many times with different pairs of sets. The sets contain 5-30 integers and the largest of these…
HelloImRandom
  • 97
  • 2
  • 6
5
votes
3 answers

Intersection of N sorted integer arrays with limit

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,…
Misha Moroshko
  • 166,356
  • 226
  • 505
  • 746
5
votes
1 answer

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

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…
Arman
  • 4,566
  • 10
  • 45
  • 66
5
votes
5 answers

Adding percents to Venn Diagrams in R

I am trying to add percentages to each section of my Venn Diagram. I have tried using paste to concatenate the circle titles with the percentages. However, unfortunately, this does not completely work, for it only provides the percentages for each…
user3209543
  • 185
  • 1
  • 2
  • 6
5
votes
6 answers

Python custom set intersection

So, there exists an easy way to calculate the intersection of two sets via set.intersection(). However, I have the following problem: class Person(Object): def __init__(self, name, age): …
Ben Stott
  • 2,218
  • 17
  • 23
1 2
3
18 19