set

Selecting SUM of TOP 2 values within a table with multiple GROUP in SQL

I've been playing with sets in SQL Server 2000 and have the following table structure for one of my temp tables (#Periods): RestCTR HoursCTR Duration Rest ---------------------------------------- 1 337 2 0 2 337 46 1 3 337 2 ...

Does this seem like a reasonable approach to a concurrent set/queue combo?

Update: As Brian pointed out, my original idea did indeed have a concurrency issue. This was somewhat obscured by the signature of the ConcurrentDictionary<TKey, TValue>.AddOrUpdate method, which can lull a lazy thinker (like myself) into believing that everything--the set add as well as the queue push--will somehow happen all at once, a...

PHP warning magic method set() class.XMLHttpRequest.php

i have a php script that runs perfectly but i get 2 errors: Warning: The magic method __set() must have public visibility and cannot be static in C:\wamp\www\class.XMLHttpRequest.php on line 63 Warning: The magic method __get() must have public visibility and cannot be static in C:\wamp\www\class.XMLHttpRequest.php on line 89...

Ruby Set class: equality of sets.

According to the Ruby Set class's documentation, "== Returns true if two sets are equal. The equality of each couple of elements is defined according to Object#eql?. The essence of this can be demonstrated using Date objects, where sets containing different Date objects but with the same date compare to equal: require 'set' d1 = Date.t...

Nested Set Filtering

Hi, I'm using nested set model for my menu tree, and I'm trying to get nodes with some filtering. I have several root nodes. Example: Menu1(on) \-Submenu1(on) \-Submenu2(on) Menu2(off) \-Submenu3(on) \-Submenu4(on) \-Submenu5(on) Menu3(on) I want to return all nodes "on" but not the ones that have parents "off". The query, f...

Sorting a set<string> on the basis of length

My question is related to this. I wanted to perform a sort() operation over the set with the help of a lambda expression as a predicate. My code is #include <set> #include <string> #include <iostream> #include <algorithm> int main() { using namespace std; string s = "abc"; set<string> results; do { for (int n = 1; n <= s....

Python set iteration order varies from run to run

Why does the iteration order of a Python set (with the same contents) vary from run to run, and what are my options for making it consistent from run to run? I understand that the iteration order for a Python set is arbitrary. If I put 'a', 'b', and 'c' into a set and then iterate them, they may come back out in any order. What I've o...

Python -Intersection of multiple lists?

I am playing with python and am able to get the intersection of two lists: result = set(a).intersection(b) Now if d is a list containing a and b and a third element c, is there an built-in function for finding the intersection of all the three lists inside d? So for instance, d = [[1,2,3,4], [2,3,4], [3,4,5,6,7]] then the result sh...

Choosing N random numbers from a set

I have a sorted set (std::set to be precise) that contains elements with an assigned weight. I want to randomly choose N elements from this set, while the elements with higher weight should have a bigger probability of being chosen. Any element can be chosen multiple times. I want to do this as efficiently as possible - I want to avoid ...

Algorithm find elements not in set

I have a list of products {P1, P2, ...} each of which can have a list of attributes {a1, a2, ...}. What's the fastest algorithm to find all elements NOT having some attributes say {a2, a6, a10}? If P1 = {a1, a2, a3} P2 = {a3} P3 = {a1, a4} , the algorithm should return {P2, P3} The issue is I don't know the input list of attributes ...

Addclass to link in jquery.

I have made a menu that gets subpages with ajax and it works as it should. And now I would like to add a class to the link that was clicked, so I can display an active state on that link? This is what I have: $(document).ready(function(){ loadPage(); }); function loadPage(url) { //loads the menu $('#guiden...

Why is this program overloading () operator ?

Currently I am studying Standard Template Library (STL). In this program I am storing some long values in Associative Container and then sorting them according to unit's place (according to the number in unit's place). Code : #include <iostream> #include <set> #include <functional> using namespace std; class UnitLess { public: ...

VS2008 - VB.net Font Dialog - Filter Fonts by Codepage/Language

Update (in response to first answer, from Hans Passant): I guess I didn't explain my use-case well enough. This application will be designed for people to enter data in a "master" language (most likely English, but not necessarily), and then facilitate the entry of translations in another language. This is all done with a rich-text box ...

How to partition a set of values (vector) in R

I'm programming in R. I've got a vector containing, let's say, 1000 values. Now let's say I want to partition these 1000 values randomly into two new sets, one containing 400 values and the other containing 600. How could I do this? I've thought about doing something like this... firstset <- sample(mydata, size=400) ...but this doesn'...

ConcurrentModification exception using addAll over Set in Java

I have been completely puzzled by an issue I just came over in my Java application. When I attempt to run the code given below, Java raises a ConcurrentModificationException on the line that says "if ( this.vertexStore.get ( v ).addAll ( output ) )". I find this very strange considering this a completely single-threaded application, a...

Hibernate -> ArrayList cannot be cast to Set

Hello! I have a Java EE application and I use Hibernate. The domain objects, I changed the List / ArrayList to Set / HashSet, because it is better to use Sets. But in my Dao implementation I run into a problem: public Set<Person> getAllPersons() { SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session sess ...

Mapping Two Continuous Sorted Integer Sets onto One Integer Set

I have an algorithms problem you should help me out with: I am trying to map two continuous sorted integer sets (with potentially differing number of items) to a single continuous sorted integer set preserving linear spacing. e.g. A: {1,2,3} B: {1,2,3,4} could map onto C: {1,2,3,4,5,6,7} by A: {1->1, 2->4, 3->7} and B: {1->1, 2->3, 3->5...

How get List from Set and Comparator

What is the "good" (and why ?) solution to get a List from a Set and sorted against a given Comparator ? ...

generate all possible subsets of a given Set that contain n elements using stack and queue

generate all possible subsets of a given Set that contain n elements using stack and queue without using recursion. and then find the complexity of this pseudo code so if we have a set {1,2,3) then the subsets are 2^n so its 2^3 and its 8 subsets result will be {} {1} {2] {3} {1,2} {1,3} {2,3} {1,2,3} ...

Quick Question About Get and Set

If there is the following code in a class, are get and set methods associated to the variable? How can I access get and set with an instance of the class? public string Something { get; set; } ...