Ideally, I'm looking for a templated logical Set class. It would have all of the standard set operations such as Union, Intersection, Etc., and collapse duplicated items.
I ended up creating my own set class based on the C# Dictionary<>- just using the Keys.
...
When I am writing code in Python, I often need to remove items from a list or other sequence type based on some criteria. I haven't found a solution that is elegant and efficient, as removing items from a list you are currently iterating through is bad. For example, you can't do this:
for name in names:
if name[-5:] == 'Smith':
...
Suppose the following:
>>>s = set([1, 2, 3])
How do I get a value (any value) out of s without doing s.pop()? I want to leave the item in the set until I am sure I can remove it - something I can only be sure of after an asynchronous call to another host.
Quick and dirty:
>>>elem = s.pop()
>>>s.add(elem)
But do you know of a bette...
I'm working on a something related to roughset right now. The project uses alot of sets operation and manipulation. I've been using string operations as a stop gap measure for set operation. It has worked fine until we need to process some ungodly amount of data ( 500,000 records with about 40+ columns each ) through the algorithm.
I ...
Hello Stack-Overflow,
Here is my situation. I have a list of data that looks like this:
[(id__1_, description, id_type), (id__2_, description, id_type), ... , (id__n_, description, id_type))
The data is loaded from multiple files that all belong to the same grouping. In each grouping there could be multiples of the same id, each comin...
Is there any built-in functionality for classical set operations on the java.util.Collection class? My specific implementation would be for ArrayList, but this sounds like something that should apply for all subclasses of Collection. I'm looking for something like:
ArrayList<Integer> setA ...
ArrayList<Integer> setB ...
ArrayList<Intege...
I'll go first.
I'm 100% in the set-operations camp. But what happens when the set logic
on the entire desired input domain leads to a such a large retrieval that the query slows down significantly, comes to a crawl, or basically takes infinite time?
That's one case where I'll use a itty-bitty cursor (or a while loop) of perhaps most d...
Hey,
Let's say I have this type in my application:
public class A {
public int id;
public B b;
public boolean equals(Object another) { return this.id == ((A)another).id; }
public int hashCode() { return 31 * id; //nice prime number }
}
and a Set<A> structure. Now, I have an object of type A and want to do the following:
If...
Here's the jist of the problem: Given a list of sets, such as:
[ (1,2,3), (5,2,6), (7,8,9), (6,12,13), (21,8,34), (19,20) ]
Return a list of groups of the sets, such that sets that have a shared element are in the same group.
[ [ (1,2,3), (5,2,6), (6,12,13) ], [ (7,8,9), (21,8,34) ], [ (19,20) ] ]
Note the stickeyness - the set (6,...
Does anyone know if there is a good equivelent to Java's Set collection in C#.
It's one of the few things I miss from having moved to C#.
I am aware that you can have a "pretend" set using a Dictionary or Hashtable and only bothering to populate the keys. But it's not very elegant.
It's wierd every other way I turn in C# somone seems...
Basically what I'm trying to do is create an object of unique objects, a set. I had the brilliant idea of just using a JS object with objects for the property names. Such as,
set[obj] = true;
This works, to a point. It works great with string and numbers, but with other objects, they all seem to "hash" to the same value and access the ...
I am trying to use set.insert (key) as a conditional, where if the key is inserted correctly (meaning that the key does NOT already exsist in the set ) then it should go on and perform some kind of code. For example, something like:
if (set.insert( key ) {
// some kind of code
}
Is this allowed? Because the compiler is throw...
I have a C++ STL set with a custom ordering defined.
The idea was that when items get added to the set, they're naturally ordered as I want them.
However, what I've just realised is that the ordering predicate can change as time goes by.
Presumably, the items in the set will then no longer be in order.
So two questions really:
Is i...
If I have a type defined as a set of an enumerated type, it's easy to create an empty set with [], but how do I create a full set?
EDIT: Yeah, the obvious solution is to use a for loop. That's also a really bad solution if there's another way. Does anyone know of a way that'll work in constant time?
...
I have a list of numbers, say {2,4,5,6,7}
I have a table, foos, with foos.ID, including say, {1,2,3,4,8,9}
Id like to take my list of numbers, and find those without a counterpart in the ID field of my table.
One way to achieve this would be to create a table bars, loaded with {2,4,5,6,7} in the ID field.
Then, I would do
SELECT bar...
Given two sets A and B, what is the common algorithm used to find their union, and what is it's running time?
My intuition:
a = set((1, 2, 3))
b = set((2, 3, 5))
union = set()
for el in a:
union.add(el)
for el in b:
union.add(el)
Add checks for a collision, which is O(1), and then adds the element, which is (??). This is do...
The title pretty much says it all. I'm using a TClientDataset to store an array of objects, and one of the objects has a member defined as a set of an enumerated type. As I understand it, Delphi sets are bitfields whose size can vary from 1 to 32 bytes depending on how much data they contain, and Delphi doesn't define a TSetField. What...
What is a good way to represent sparse set of integers (really C memory addresses) in a compact and fast way. I already know about the obvious things like bit-vectors and run-length encoding. but I want something much more compact than one word per set element. I need to add and remove elements and test for membership. I do not need othe...
In F#, you can generate a set of numbers, just by saying [1..100].
I want to do something similar in C#. This is what I have come up with so far:
public static int[] To(this int start, int end)
{
var result = new List<int>();
for(int i = start; i <= end; i++)
result.Add(i);
return result.ToArray();
}
By doing thi...
That is, if I had two or more sets, and I wanted to return a new set containing either:
All of the elements each set has in common (AND).
All of the elements total of each set (OR).
All of the elements unique to each set. (XOR).
Is there an easy, pre-existing way to do that?
Edit: That's the wrong terminology, isn't it?
...