set

Picking a random element from a set

How do I pick a random element from a set? I'm particularly interested in picking a random element from a HashSet or a LinkedHashSet, in Java. Solutions for other languages are also welcome. ...

Does Common Lisp have a something like java's Set Interface/implementing classes?

I need something like this, a collection of elements which contains no duplicates of any element. Does Common Lisp, specifically SBCL, have any thing like this? ...

How do you sort a tree stored using the nested set model?

When I refer to nested set model I mean what is described here. I need to build a new system for storing "categories" (I can't think of better word for it) in a user defined hierarchy. Since the nested set model is optimized for reads instead of writes, I decided to use that. Unfortunately during my research and testing of nested sets...

Searching for the best PHP nested sets class (PEAR class excluded)

I'm looking for a PHP (with MYSQL) nested sets class with all needed functions. For example: createLeftNode, createRightNode,createRootNode, createSubNode,deleteNode and moveTree. Not only 1 left, 1 right, 1 up and 1 down but also a part of a tree in a nother tree. Thanks! ...

c++ STL set difference

Does the C++ STL set data structure have a set difference operator? ...

How to use set! in Scheme functions?

How would you use set! in a simple procedure f such that evaluating (+ (f 0) (f 1)) will return 0 if the arguments to + are evaluated from left to right but will return 1 if the arguments are evaluated from right to left? ...

What happens when you make assignments to fields or properties of properties

Lets say you have a property like: Person person1; public Person Captin{ get{ return person1; } set{ person1 = value; } } public void SomeFunction(){ Captin.name = "Hook" } In this case if you set the name on the property we know that the new name of Hook will get applied to the underlying value ...

Algorithm for merging sets that share at least 2 elements

Given a list of sets: S_1 : [ 1, 2, 3, 4 ] S_2 : [ 3, 4, 5, 6, 7 ] S_3 : [ 8, 9, 10, 11 ] S_4 : [ 1, 8, 12, 13 ] S_5 : [ 6, 7, 14, 15, 16, 17 ] What the most efficient way to merge all sets that share at least 2 elements? I suppose this is similar to a connected components problem. So the result would be: [ 1, 2, 3, 4, 5, 6, 7, 1...

What does the function set use to check if two objects are different?

Simple code: >>> set([2,2,1,2,2,2,3,3,5,1]) set([1, 2, 3, 5]) Ok, in the resulting sets there are no duplicates. What if the object in the list are not int but are some defined by me? What method does it check to understand if they are different? I implemented __eq__ and __cmp__ with some objects but set doesn't seems to use them :\ ...

Best way to in situ delete an element

I have a set of objects which I iterate through, however I may decide during the iteration that one (or more) of those objects now need to be deleted. My code goes as follows: if( ! m_Container.empty() ) { for( typedefedcontainer::iterator it = m_Container.begin(); it != m_Container.end(); ++i...

.NET Generic Set ?

Is there a generic container implementing the 'set' behaviour in .NET? I know I could just use a Dictionary<T, Object> (and possibly add nulls as values), because its keys act as a set, but I was curious if there's something ready-made. ...

Contains Test for a Constant Set

The problem statement: Given a set of integers that is known in advance, generate code to test if a single integer is in the set. The domain of the testing function is the integers in some consecutive range. Nothing in particular is known now about the range or the set to be tested. The range could be small or huge (but a solution ca...

Spring context.xml and Set.contains()

Spring: In my context.xml, I have: <util:set id="someIDs" set-class="java.util.HashSet" value-type="java.lang.String"> <value>"W000000001"</value> <value>"W000000003"</value> <value>"W000000009"</value> </util:set> In my Java bean, the implementation is: private Set<String> someSet = ComUtiliti...

How can I update a field in one table with a field from another table? (SQL)

Two tables: COURSE_ROSTER - contains COURSE_ID as foreign key to COURSES USER_ID as field I need to insert into COURSES COURSES - contains COURSE_ID as primary key INSTRUCTOR_ID as field that needs to be updated with USER_ID field from COURSE_ROSTER What would the UPDATE sql syntax be? I am trying this, but no good... I'm miss...

Can I implement State Transitions for a DFA in Java using java.util.Set

I'm implementing a DFA as close as I can to the formal definition as a learning exercise (and blogging material) I planned on using a java.util.Set where a set is involved in the definition. The definition involves a set of tuples to define the legal state transitions: (state,symbol) -> nextState. I have a Transition class with member...

When to use Enum or Collection in Java

Under what circumstances is an enum more appropriate than, for example, a Collection that guarantees unique elements (an implementer of java.util.Set, I guess...)? (This is kind of a follow up from my previous question) Thanks! ...

Flash+PHP+cookie

I want an animation play only once in the browser. If any user seen the movie and if goes to any other page or refresh(F5) and then come back on the animation page then animation should not play from start. I want to play it from another frame. I think it can be done by set cookie or somthing using javascript or php. Please anybody he...

Best c++ container to strip items away from?

I have a list of files (stored as c style strings) that I will be performing a search on and I will remove those files that do not match my parameters. What is the best container to use for this purpose? I'm thinking Set as of now. Note the list of files will never be larger than when it is initialized. I'll only be deleting from the con...

Efficient set intersection algorithm

Given two lists (not necessarily sorted), what is the most efficient non-recursive algorithm to find the intersection of those lists? ...

How to set background image in Java?

I am developing a simple platform game using Java using BlueJ as the IDE. Right now I have player/enemy sprites, platforms and other items in the game drawn using polygons and simple shapes. Eventually I hope to replace them with actual images. For now I would like to know what is the simplest solution to setting an image (either URL or...