sets

Finding values common to all elements

I have a dataset with two columns as follows; Prod Value A 1 A 2 A 3 B 2 B 4 C 1 C 2 So I want all the rows where value is common for Prod, so in the example above only the following would be returned. A 2 B 2 C 2 Either LINQ or sql would be helpful Thanks ...

Unable to get set intersection to work

Sorry for the double post, I will update this question if I can't get things to work :) I am trying to compare two files. I will list the two file content: File 1 File 2 "d.complex.1" "d.complex.1" 1 4 5 5 48 ...

Combining table, web service data in Grails

I'm trying to figure out the best approach to display combined tables based on matching logic and input search criteria. Here is the situation: We have a table of customers stored locally. The fields of interest are ssn, first name, last name and date of birth. We also have a web service which provides the same information. Some of ...

Scheme: Detecting duplicate elements in a list

Does R6RS or Chez Scheme v7.9.4 have a library function to check if a list contains duplicate elements? Alternatively, do either have any built in functionality for sets (which dis-allow duplicate elements)? So far, I've only been able to find an example here. The problem with that is that it doesn't appear to actually be part of the ...

Linq find differences in two lists

I have two list of members like this: Before: Peter, Ken, Julia, Tom After: Peter, Robert, Julia, Tom As you can see, Ken is is out and Robert is in. What I want is to detect the changes. I want a list of what has changed in both lists. How can linq help me? ...

construct graph from python set type.

The short question, is there an off the self function to make a graph from a collection of python sets? The longer question: I have several python sets. They each overlap or some are sub sets of others. I would like to make a graph (as in nodes and edges) nodes are the elements in the sets. The edges are intersection of the sets with wei...

Minimizing the number of boxes that cover a given set of intervals

Hi, this is a question for the algorithms gurus out there :-) Let S be a set of intervals of the natural numbers that might overlap and b a box size. Assume that for each interval, the range is strictly less than b. I want to find the minimum set of intervals of size b (let's call it M) so all the intervals in S are contained in the in...

Possible: Set Operations on Disparate Maps with Same Key Type?

Let's say I have two maps: typedef int Id; std::map<Id, std::string> idToStringMap; std::map<Id, double> idToDoubleMap; And let's say I would like to do a set operation on the keys of the two maps. Is there an easier way to do this than to create a custom "inserter" iterator? such that I could do something like: std::set<Id> res...

Can I have a set containing identical elements?

It is convenient for me to use a set. I like how I can "add" ("remove") an element to (from) the set. It is also convenient to check if a given element is in the set. The only problem, I found out that I cannot add a new element to a set if the set has already such an element. Is it possible to have "sets" which can contain several iden...

Is frozenset adequate for caching of symmetric input data in a python dict?

The title more or less says it all: I have a function which takes symmetric input in two arguments, e.g. something like def f(a1, a2): return heavy_stuff(abs(a1 - a2)) Now, I want to introduce some caching method. Would it be correct / pythonic / reasonably efficient to do something like this: cache = {} def g(a1, a2): fs =f...

Ruby on Rails associations for set theory (union, difference, intersection, etc.)

I would like a has_many association that works like so: class Hood acts_as_tree has_many :houses, :union_with => :parent end class House end where any House associated with Hood 1 would also be returned in .houses of subhoods of Hood 1, along with the subhoods' individual associations. The association only needs to work from the...

What is a data structure for quickly finding non-empty intersections of a list of sets?

I have a set of N items, which are sets of integers, let's assume it's ordered and call it I[1..N]. Given a candidate set, I need to find the subset of I which have non-empty intersections with the candidate. So, for example, if: I = [{1,2}, {2,3}, {4,5}] I'm looking to define valid_items(items, candidate), such that: valid_items(I,...

Distribution of items from "x" sets of plants in "y" baskets equally.

I need ideas about algorithm for distribution of plants in groups. I have, say 5, sets of plants and each set depicts a certain property e.g., setA= {set of all plants that are green in color} setB = {set of all plants red in color} setC={ all the plants that are roots also} setD= {fruits} setE= [flowers} A plant can be a memb...

Python: Get items at depth? (set library?)

I have a nested list something like this: PLACES = ( ('CA', 'Canada', ( ('AB', 'Alberta'), ('BC', 'British Columbia' ( ('van', 'Vancouver'), ), ... )), ('US', 'United States', ( ('AL', 'Alabama'), ('AK', 'Alaska'), ... I need to retrieve some data out of i...

How to simulate tuples and sets in C#?

I want to use some features of python like as Tuples and Sets in c#. should I implement them? or there are already implemented? could anybody knows a library of dynamic data structures for .net languages? ...

determine if intersection of a set with conjunction of two other sets is empty

For any three given sets A, B and C: is there a way to determine (programmatically) whether there is an element of A that is part of the conjunction (edit: intersection) of B and C? example: A: all numbers greater than 3 B: all numbers lesser than 7 C: all numbers that equal 5 In this case there is an element in set A, being the numb...

Error:Conversion Between Two Character Set

Hi, I am getting the error "Conversion Between Two Character Sets" when connecting to SAP from .NET using SAP .NET Connector. When i use Win XP and Visual Studio 2003 there is no problem. But when i reference the .dll from visaul studio 2008 on windows 7, the error appears. What can i do? Thanks ...

Indexing SET field

I have two entities A and B. They are related with many to many relation. Entity A can be related up to 100 B entities. Entity B can be related up to 10000 A entities. I need quick way to select for example 30 A entities, that have relation with specified B entities, filtered and sorted by different attributes. Here how I see ideal solu...

Left/Right/Inner joins using C# and LINQ

I am trying to figure out how to do a series of queries to get the updates, deletes and inserts segregated into their own calls. I have 2 tables, one in each of 2 databases. One is a Read Only feeds database and the other is the T-SQL R/W Production source. There are a few key columns in common between the two. What I am doing to set...

What is the best way to translate this recursive python method into Java?

In another question I was provided with a great answer involving generating certain sets for the Chinese Postman Problem. The answer provided was: def get_pairs(s): if not s: yield [] else: i = min(s) for j in s - set([i]): for r in get_pairs(s - set([i, j])): yield [(i, j)] + r for x ...