sets

How to get the highest value from a Delphi set?

Is there any way to extract the highest (or lowest) value in a set? For example, if I have the following "set of byte": [0, 1, 2, 4, 5, 28, 199] is there any function I could run on that and get back 199 as the result? EDIT: There's an obvious brute-force solution involving a for..in loop. If possible, I'd like to find a better way...

Nested sets, php array and transformation

Hi, I need to transform my nested sets structure (mysql) into json for this spacetree 1) http://blog.thejit.org/wp-content/jit-1.0a/examples/spacetree.html I found this function to create an array from nested sets: 2) http://semlabs.co.uk/journal/converting-nested-set-model-data-in-to-multi-dimensional-arrays-in-php I can also convert...

Determining items that join against the same set in T-SQL

I am writing a a report and was wondering if there is there any way to find items that join into identical sets? For example in the following query, I want to find all areas that join against the same set of products: SELECT Area.Name, AggregateSetOfProductsId FROM Area INNER JOIN AreaToProduct ON AreaToProduct.AreaId = Area.Id GROUP ...

F# Set using custom class

I'm trying to use Set operations with a class that I have. Every instance of this class has a unique ID. Do I need to implement the System.IComparable interface and if so how would I? type SomeClass(id : int) = member this.ID = id let someSet = Set.of_list [SomeClass(1); SomeClass(2)] let test = someSet.Contains(SomeClass(2)) ...

[c++] tr1::unordered_set union and intersection

How to do intersection and union for sets of the type tr1::unordered_set in c++? I can't find much reference about it. Any reference and code will be highly appreciated. Thank you very much. Update: I just guessed the tr1::unordered_set should provide the function for intersection, union, difference.. Since that's the basic operation o...

faster way to use sets in MySQL

I have a MySQL 5.1 InnoDB table (customers) with the following structure: int record_id (PRIMARY KEY) int user_id (ALLOW NULL) varchar[11] postcode (ALLOW NULL) varchar[30] region (ALLOW NULL) .. .. .. There are roughly 7 million rows in the table. Currently, the table is being queried like this: SELECT * FROM custom...

what happens when you modify an element of an std::set?

Like the question says, If I change an element of an std::set, for example, through an iterator, I know it is not "reinserted" or "resorted", but is there any mention of if it triggers undefined behavior? For example, I would imagine insertions would screw up. Is there any mention of specifically what happens? ...

Is the following code using std::set "legal"?

I have this code: set<int>::iterator new_end = set_difference(set1.begin(), set1.end(), set2.begin(), set2.end(), set1.begin()); set1.erase(new_end, set1.end); It compiles and runs fine in visual studio. However, in a previous question, people stat...

Further std::set woes

I asked this question earlier. I am intrigued by std::set but I have another confusing scenario. Namely, is the following code legal, portable c++ for T=std::vector and T=std::set: template <typename T> void remove_elements(T& collection, int removal_value) { typename T::iterator new_end = std::remove(collection.begin(), c...

What are recursively enumerable sets?

There seems to be a lot of discussion (and confusion) regarding the Wikipedia article on the topic. Other results Google throws up are not available for free public use. I would be interested in what you folks have to say. Thanks! ...

set equality in linq

I have two lists A and B (List). How to determine if they are equal in the cheapest way? I can write something like '(A minus B) union (B minus A) = empty set' or join them together and count amount of elements, but it is rather expensive. Is there workaround? ...

Handling unions, subsets and supersets in Scala

I need to write a code snippet that would compare multiple arrays and produce the set that match the data in those arrays, produce the data set only in array A, but not in array B,C,D,in array B but not in A,C,D, being able to handle any number of arrays (i.e. dynamically looped). The code should utilize anonymous functions in Scala (i.e...

Union of All Intersecting Sets

Given a list of objects with multiple attributes I need to find the list of sets created by a union of all intersecting subsets. Specifically these are Person objects, each with many attributes. I need to create a list of 'master' sets based on a handful of unique identifiers such as SSN, DLN, etc. For instance, if Person A and Person...

Difference between Vector, Set, and Tuple

As the title says, what is the differences between vectors, sets, and tuples in programming? ...

How can I generate all subsets of a list in Perl?

I have a mathematical set in a Perl array: (1, 2, 3). I'd like to find all the subsets of that set: (1), (2), (3), (1,2), (1,3), (2,3). With 3 elements this isn't too difficult but if set has 10 elements this gets tricky. Thoughts? ...

Use HashSet over ArrayList to Convey Intention?

Imagine that I need to create a Collection of elements, where order could or could not matter. Effectively all I plan on doing is using the iterator. I notice most of my colleagues using an ArrayList vs LinkedHashSet/HashSet. My question is, if I know that these elements should be unique, should I be using a Set or a List? Effectively it...

Unix command to find string set intersections or outliers?

Is there a UNIX command on par with sort | uniq to find string set intersections or "outliers". An example application: I have a list of html templates, some of them have {% load i18n %} string inside, others don't. I want to know which files don't. edit: grep -L solves above problem. How about this: file1: mom dad bob file2:...

Algorithm for updating a list from a list

I've got a data source that provides a list of objects and their properties (a CSV file, but that doesn't matter). Each time my program runs, it needs to pull a new copy of the list of objects, compare it to the list of objects (and their properties) stored in the database, and update the database as needed. Dealing with new objects is ...

Can't Set Property's Property

I am having trouble with, as I said, setting a property's property. Let's say I have a class that represents a transaction. In my class I have a property that represents another class, such as this: Public Class PersonRecord _myPerson = new Person() Public Property MyPerson as Person Get _myPerson = Person.GetApp...

Easy way to implement dynamic views?

View are useful constructions of Python 3. For those who never noticed (like me): for a dictionary d you can write k = d.keys() and even if you update d the variable k will still be giving you the updated keys. You can write then k1 & k2 and it will always give you d1.keys() & d2.keys() I want to implement this for my personal todo mana...