sets

More efficient way to count intersections?

I have a list of 300000 lists (fiber tracks), where each track is a list of (x,y,z) tuples/coordinates: tracks= [[(1,2,3),(3,2,4),...] [(4,2,1),(5,7,3),...] ... ] I also have a group of masks, where each mask is defined as a list of (x,y,z) tuples/coordinates: mask_coords_list= [[(1,2,3),(8,13,4),...] [(6,2,2),(5,7,3),...] ... ]...

Given list, subset of list: return bitmask (bit vector same length as list) corresponding to the subset.

For example, bitmask({1, 2, 3, 4}, {2, 4}) returns {False, True, False, True} The naive way to do this is to map a membership function over the list: map(lambda(x, member(x, subset)), list) but that's O(n*m) and it can be done in O(n+m). What's the best way to implement bitmask() in your favorite language? PS: It doesn't actua...

Is there a standard user interface paradigm for configuring the partition of a set of elements?

Consider you have a set of objects X (e.g., A, B, C, D) that you wish to divide into non-empty subsets that cover all of X. Mathematically, a partition of the set. So, at first you might treat them as all different, {{A}, {B}, {C}, {D}}. Alternatively, you could separate them into vowels and consonants, i.e. {{A}, {B,C,D}}. Or, arbitra...

Finding sets that are a subset of a specific set

Lets say I have 4 different values A,B,C,D with sets of identifiers attached. A={1,2,3,4,5} B={8,9,4} C={3,4,5} D={12,8} And given set S of identifiers {1,30,3,4,5,12,8} I want it to return C and D. i.e. retrieve all sets from a group of sets for which S is a superset. Is there any algorithms to perform this task efficiently (Prefer...

Please help me find the official name of this programming approach.

I [surely re] invented this [wheel] when I wanted to compute the union and the intersection and diff of two sets (stored as lists) at the same time. Initial code (not the tightest): dct = {} for a in lst1: dct[a] = 1 for b in lst2: if b in dct: dct[b] -= 1 else: dct[b] = -1 union = [k for k in dct] inter = [k for k in dct...

What's the style for immutable set and map in F#

I have just solved problem23 in Project Euler, in which I need a set to store all abundant numbers. F# has a immutable set, I can use Set.empty.Add(i) to create a new set containing number i. But I don't know how to use immutable set to do more complicated things. For example, in the following code, I need to see if a number 'x' could ...

Is there the equivent of a Java Set in php?

Is there the equivalent of a Java Set in php? (meaning a collection that can't contain the same element twice) ...

Python not all in operation

How do I check if a list is a subset of a bigger list. i.e. a = [1,2,3] is a subset of b = [1,2,3,4,5,6] Can I do something like if a all in b ...

A set implementation in LaTeX?

Hi, Consider the following straightforward implementation of a list in latex: \newcommand{\add@to@list}[2]{% \ifx#2\@empty% \xdef#2{#1}% \else% \xdef#2{#2,#1}% \fi% }% I wonder if there is a simple way to implement a set (list with no repeated elements) ? ...

Change Multiple Image Sources Javascript

I am creating a simple image gallery, and I would like to create multiple sets of images. On the click of a link all of the images in the link's given set will change. here is my current code: <ul> <li><img src="image01.jpg" width="500" height="450"></li> <li><img src="image02.jpg" width="200" height="450"></li> <li><img src="ima...

How do you use sets and gets in C++?

I've used them in java and didn't seem to have too many issues, but I'm not grasping them very well in C++. The assignment is: Write a class named Car that has the following member variables: year. An int that holds the car's model year. make. A string that holds the make of the car. speed. An int that holds the car's curr...

Is there a data structure that holds sets of data in .NET?

I'm looking for a data structure similar to a dictionary that returns the set of all related items to a key. For example, I would use it like this: var data = new FancyDataStructure(); data.Add(new string[] {"Elizabeth", "Liz", "Betty"}); data.Add(new string[] {"Bob", "Robert", "Rob"}); string[] alternateNames1 = data["Betty"]; strin...

Python dictionary that maps strings to a set of strings?

I would like to be able to make a Python dictionary with strings as keys and sets of strings as the values. E.g.: { "crackers" : ["crunchy", "salty"] } It must be a set, not a list. However, when I try the following: word_dict = dict() word_dict["foo"] = set() word_dict["foo"] = word_dict["foo"].add("baz") ...

Is this problem NP, and does it have a name?

This problem came up in the real world, but I've translated it into a more generic "textbook-like" formulation. I suspect it is NP, but I'm particularly interested in knowing if it has a name or is well known since I think I can't be the first one to encounter it. ;-) Imagine there is a potluck party with N guests. Each guest may bring ...

Converting sets of integers into ranges

What's the most idiomatic way to convert a set of integers into a set of ranges? E.g. given the set {0, 1, 2, 3, 4, 7, 8, 9, 11} I want to get { {0,4}, {7,9}, {11,11} }. Let's say we are converting from std::set<int> into std::vector<std::pair<int, int>>. I treat Ranges as inclusive on both sides, since it's more convenient in my cas...

sorting lists of lists in haskell

i'm completely stumped on how to Write a function that, given a list of sets returns the sets split into sublists by size (and with the sublists ordered by the size of sets they contain). sample input *Main> allSets [[1,2],[8],[1,4,7,8],[5],[1,4],[1],[2,3],[1,2,5,8],[3,4,6,7],[1,2,3,4],[4],[5,6,7,8],[3,4],[3],[2,3,5,6],[7],[6],[2]] sam...

How would I convert this Delphi Set code to C#?

I've got the following Delphi code that defines a set and then a simple if statement that checks if a passed value of the set type falls within certain values. TOverwriteMode = (omNone, omDateAndSize, omDateOrSize, omDate, omSize, omForce); ... if OverwriteMode in [omDateAndSize, omDateOrSize, omDate, omSize] then begin end; I've co...

Is there a library for a Set data type in Javascript?

Since Javascript doesn't have a built in set datatype has anyone come across a decent library for sets and set operations like union, intersection, etc? ...

How to remove opposite rows from SQL table.

I have the following SQL table: A|B --- w|x x|w y|z z|y Can I construct a query which will yield the following result: A|B --- w|x y|z To summarize, I would like to treat the two columns as an unordered set, such that (a,b) == (b,a). ...

Which C# Collection should I use for mutable and repeatable task management?

I find myself in a situation where I'm not sure which Collection would best suit my needs. I have a series of task objects that will be used in the following manner... The tasks will execute repeatedly during the application's runtime. The tasks will execute in a specific order based on the priority I assign each of them. (I don't c...