sets

Quick Java question: Cloning and subtracting sets - does this work?

private HashMap<DataObject, HashSet> AllDataObjects; ... /** Returns all DataObject elements that are NOT in the specified set. */ private DataObject[] invert( HashSet<DataObject> set ) { HashSet<DataObject> keys = (HashSet) AllDataObjects.keySet(); keys = (HashSet) keys.clone(); keys.removeAll( set ); return (DataObj...

How to use sets of string in Pascal?

I am writing a little game in which the user is asked for their race and class. There are five possible races of string[5] and four possible classes of string[9]. How do I program pascal to 1. define the five races and four classes as constants, 2. check the user input to see whether the input is within the possible races and classes -...

Is it possible to report on 2 tables without using a subquery?

You have one table against which you wish to count the number of items in two different tables. In this example I used buildings, men and women DROP TABLE IF EXISTS building; DROP TABLE IF EXISTS men; DROP TABLE IF EXISTS women; CREATE TABLE building(name VARCHAR(255)); CREATE TABLE men(building VARCHAR(255), name VARCHAR(255)); CREATE ...

How do you determine if two HashSets are equal (by value, not by reference)?

I am trying to determine if two HashSet objects in .NET 3.5 (C#) are equal sets, i.e. contain the same values. This seems like something one would obviously want to do but none of the provided functions seem to give you this information. The way I can think to do this is by checking if the count of the two sets are equal and one set is ...

Finding sets that have specific subsets

I am a graduate student of physics and I am working on writing some code to sort several hundred gigabytes of data and return slices of that data when I ask for it. Here is the trick, I know of no good method for sorting and searching data of this kind. My data essentially consists of a large number of sets of numbers. These sets can co...

Inserting into Set changing the order of Elements in an Array in Ruby

@search_results = Array.new duplicates = Set.new results.each { |result| @search_results.push(result) unless duplicates.add?(result[:url]) } This piece of code is garbling the order of elements in the array @search_results. Why would inserting the same element in a set and an array change the insertion order for Array? Seems like so...

Java Set Initial Capacity Best Practice

Ok, here's my situation: I have an Array of States, which may contain duplicates. To get rid of the duplicates, I can add them all to a Set. However when I create the Set, it wants the initial capacity and load factor to be defined, but what should they be set to? From googling, I have come up with: String[] allStates = getAllStates(...

Is there a basic Java Set implementation that does not permit nulls?

The API for the Java Set interface states: For example, some implementations prohibit null elements, and some have restrictions on the types of their elements I am looking for a basic Set implementation that does not require ordering (as ArrayList provides for the List interface) and that does not permit null. TreeSet, HashSet, and...

Sets in Ruby?

I need a collection that is like a set. Basically I'm scanning a long string and adding words to the collection but I want to be able to detect when there are duplicates. If sets aren't available, what's the most efficient way of doing this in Ruby? Brownie points for example code. ...

Object Status (SubSet) Persistence

Hi everyone: I need help on this: im storing object properties in a DataPacket class. The properties are defined like this type TProperty = class private FName: string; public constructor Create(const AName: string); property Name: string read FName; end; TIntegerProperty = class(TProperty) private FValu...

Why is Scala's immutable Set not covariant in its type?

EDIT: Re-written this question based on original answer The scala.collection.immutable.Set class is not covariant in its type parameter. Why is this? import scala.collection.immutable._ def foo(s: Set[CharSequence]): Unit = { println(s) } def bar(): Unit = { val s: Set[String] = Set("Hello", "World"); foo(s); //DOES NOT CO...

Countability Question (Theory)

I'm taking the GRE tomorrow, and had a question. Based on the answer key, this practice test states that the set of all functions from N to {0, 1} is not countable. Can't you map the natural numbers to these functions, as follows? i 1 2 3 4 5 6 7 8 ... f0 = 0 0 0 0 0 0 0 0 ... f1 = 1 0 0 0 0 0 0 0 ... f2 = 0 1 0 0 0 0 0 0 ... f3 = ...

How do you calculate the total number of all possible unique subsets from a set with repeats?

Given a set** S containing duplicate elements, how can one determine the total number all the possible subsets of S, where each subset is unique. For example, say S = {A, B, B} and let K be the set of all subsets, then K = {{}, {A}, {B}, {A, B}, {B, B}, {A, B, B}} and therefore |K| = 6. Another example would be if S = {A, A, B, B}, the...

Calculate all combinations of a series

I have a list of items, and each item has a quantity. var items = { 1: 12, // we have 12 x item1 2: 1, // we have 1 x item2 3: 1, 4: 7, 5: 2, 6: 2 }; Alternatively this could be viewed as: var items = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 4, 4, 4, 4, 4, 4, 5, 5, 6, 6]; How would you...

Why doesn't java.util.Set have get(int index)?

I'm sure there's a good reason, but could someone please explain why the java.util.Set interface lacks get(int Index), or any similar get() method? It seems that sets are great for putting things into, but I can't find an elegant way of retrieving a single item from it. If I know I want the first item, I can use set.iterator().next(), ...

good books / sites on set theory

I'm trying to understand E.F.Codd's "A Relational Model of Data for Large Shared Data Banks" paper. I would like some suggestions on books / sites on set theory. ...

What is the correct (or best) way to subclass the Python set class, adding a new instance variable?

I'm implementing an object that is almost identical to a set, but requires an extra instance variable, so I am subclassing the built-in set object. What is the best way to make sure that the value of this variable is copied when one of my objects is copied? Using the old sets module, the following code worked perfectly: import sets cla...

Determining whether an object is in a std::set

I'm trying to determine whether an object is already contained within a std::set. According to msdn (and other sources) the set::find function is supposed to return end() if it doesn't find the element you asked for. However when I implement code like the following, set::find returns junk (0xbaadf00d) instead. set<Cell*> cellSet; Cell...

Exclusionary Set Syntax with Linq, VB

I'd like to do a subtraction of sets based on criteria. A pseudo-query would look like: select table1.columnn1 ,table1.column2 from table1, table2 where (table1.column1.value1 not in table2.column1 and table1.column2.value2 not in table2.column2) I can make it to about here: dim list = From tbl1 In table1 Whe...

Working with Anonymous Types with Linq in VB, C#

Say I create two sets of tuples like so: Dim losSPResults As List(Of spGetDataResults) = m_dcDataClasses.spGetData.ToList Dim loTupleKeys = From t In losSPResults Select t.key1, t.key2 '' Query on an existing dataset: Dim loTupleExistingKeys = from t in m_losSPResults Select t.key3, t.key4 Now I want to perform set op...