set

Convert sets to frozensets as values of a dictionary

I have dictionary that is built as part of the initialization of my object. I know that it will not change during the lifetime of the object. The dictionary maps keys to sets. I want to convert all the values from sets to frozensets, to make sure they do not get changed. Currently I do that like this: for key in self.my_dict.iterkeys():...

Fastest way to put contents of Set<String> to a single String with words separated by a whitespace?

I have a few Set<String>s and want to transform each of these into a single String where each element of the original Set is separated by a whitespace " ". A naive first approach is doing it like this Set<String> set_1; Set<String> set_2; StringBuilder builder = new StringBuilder(); for (String str : set_1) { builder.append(str).appe...

How to iterate over a STL set and selectively remove elements?

The following code does not work correctly. How should it be done correctly? for (std::set<Color>::iterator i = myColorContainer.begin(); i!=myColorContainer.end(); ++i) { if ( *i == Yellow) { DoSomeProccessing( *i ); myColorContainer.erase(i); } } ...

How to select a random element in std::set?

How can I select a random element in an std::set? I naively tried this: int GetSample(const std::set<int>& s) { double r = rand() % s.size(); return *(s.begin() + r); // compile error } But the operator+ is not allowed in this way. ...

Find missing number in sequence in set or list

If a std::set or std::list contains a sequence of natural numbers (1, 2, 3..). would there be a function in standard library to find the missing number? ...

Java - easily convert array to set

Hey, I'd like to convert an array to a set in Java. There are some obvious ways of doing this (i.e. with a loop) but I would like something a bit neater, something like: java.util.Arrays.asList(Object[] a); Any ideas? Cheers, Pete ...

What's the best way to validate the values of a Set in a unit test?

Okay, often I'll have a method that returns a Set of some sort. The problem with unit testing such a method is that there is no guarantee an iteration over the set will always return the items in the same order. Does anyone have any preferred method of validating a Set? Peter ...

PHP's _get & _set or unique get and set functions for each variable?

PHP has _get and _set functions built in. Is it better to write my own get and set functions for each variable or use the built in functions with a ton of if else if? What are the pros and cons of each method? ...

Create array with Set Extract in Cakephp with conditions

I have the following array: Array ( [0] => Array ( [id] => 4 [rate] => 82.50 [pounds] => 2 [ounces] => 3 [mailtype] => Package [country] => UNITED KINGDOM (GREAT BRITAIN) [svccommitments] => 1 - 3 business days [svcdescription] =>...

Array in Monotouch NSUserDefaults

Does anyone know how to store an array in Monotouch NSUserDefaults? One possible method: NSUserDefaults.StandardUserDefaults["Array"] = new NSObject(); But how do I turn an array or list into an NSObject? ...

Concurrent Set Queue

Maybe this is a silly question, but I cannot seem to find an obvious answer. I need a concurrent FIFO queue that contains only unique values. Attempting to add a value that already exists in the queue simply ignores that value. Which, if not for the thread safety would be trivial. Is there a data structure in Java or maybe a code snipit...

'No matching function' -error when trying to insert to a set (c++)

I have the following code: class asd { public: int b; asd() { b = rand() % 10; } bool operator<(asd &other) { return b < other.b; } }; int main() { asd * c; c = new asd(); set <asd> uaua; uaua.insert(c); } Yet when running it, I get this error: main.cpp|36|error: no matching function for...

Union-ing two custom classes returns duplicates

I have two custom classes, ChangeRequest and ChangeRequests, where a ChangeRequests can contain many ChangeRequest instances. public class ChangeRequests : IXmlSerializable, ICloneable, IEnumerable<ChangeRequest>, IEquatable<ChangeRequests> { ... } public class ChangeRequest : ICloneable, IXmlSerializable, IEquatable<ChangeRequest>...

c++ Difference between two vector<MyType*> A and B

Dear reader, I've got two vector<MyType*> objects called A and B. The MyType class has a field ID and I want to get the MyType* which are in A but not in B. I'm working on a image analysis application and I was hoping to find a fast/optimized solution. Kind regards, Pollux ...

Serialization issue with SortedSet, Arrays, an Serializable

I have this before the process: protected void onPostExecute(SortedSet<RatedMessage> result) { List<Object> list=Arrays.asList(result.toArray()); lancon.putExtra("results", list.toArray()); // as serializable } then in the other part I have Object o=this.getIntent().getSerializableExtra("results"); //at this point the o holds...

Creating lists and sets in Scala: What do I actually get?

If I create a Set in Scala using Set(1, 2, 3) I get an immutable.Set. scala> val s = Set(1, 2, 3) s: scala.collection.immutable.Set[Int] = Set(1, 2, 3) Q1: What kind of Set is this actually? Is it some hash-set? What is the complexity of look-ups for instance? Q2: Where can I read up on this "set-creating" method? I thought that it w...

Growing/shrinking a frame based on the size of a child panel

I have a frame that contains (among many other things) a panel. I need to be able to explicitly set the size of the panel and have the frame with all its sizers, buttons, and everything else fit around the new size of the panel. I have tried every combination of Fit/Layout/etc I can think of, but I can never get the frame to grow/shrin...

vector vs set in java

which one do you prefer? i want to make a finite automata in java,. it's more efficient using vector or set??? ...

Problems with remove_if in VS2010 when using sets

I have the following code. #include <set> #include <algorithm> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { typedef set<long> MySet; MySet a; for( int i = 0; i < 10; ++i) { a.insert(i); } MySet::iterator start,end,last; start = a.begin(); end = a.end(); last = remove_if(start,end,bind2nd(less_equal<long>...

add append update and extend in python

Is there an article or forum discussion or something somewhere that explains why lists use append/extend but sets and dicts use add/update. I frequently find myself converting lists into sets and this difference makes that quite tedious so for my personal sanity I'd like to know what the rationalization is. The need to convert between ...