Questions tagged [set]

A set is a collection in which no element is repeated, which may be able to enumerate its elements according to an ordering criterion (an "ordered set") or retain no order (an "unordered set").

A set is a collection in which no element is repeated. It is often implemented by hashing the objects as they are added to the set, and comparing against those hashes for operations on the set.

In the C++ standard library in particular, the std::set is able to enumerate its elements according to a specific strict weak ordering criterion set on container construction. To achieve this, it is typically implemented by a binary tree. By contrast, the std::unordered_set stores unique elements in no particular order, and allows for fast retrieval of individual elements based on their value.

In Python, there are currently two built-in set types, set and frozenset. set is mutable, i.e. the contents can be changed and it has no hash value and cannot be used as either a dictionary key or as an element of another set. The frozenset type is immutable and hashable.

Common operations on sets:

  • add
  • remove
  • find (check membership)
  • union, intersection, difference

Resources

12019 questions
5
votes
7 answers

Find all the elements which has no duplicate in multiple HashSet of Integers in Java

In multiple HashSet of Integers I want to get all those elements, which has no duplicate. i.e. which came only once in union of all the HashSet. I am not able to conceptualize it programmatically. As an example, consider set first contains…
ravi
  • 6,140
  • 18
  • 77
  • 154
5
votes
3 answers

Java Crazyness - Contains fails when equals passes

This is the most crazy thing I have seen in java (1.6): Set actionPlans = assessment.getActionPlans(); //getActionPlans() returns a java.util.HashSet ActionPlan actionPlan =…
phoenix7360
  • 2,807
  • 6
  • 30
  • 41
5
votes
3 answers

Using set::begin() iterator after insertion

Consider the following code: std::set s; auto it = s.begin(); s.insert(1); s.insert(2); std::cout << *it << std::endl; The output (at least for me) is 2. What's happening here? What's the state of it when I dereference it? I know that when I…
Joseph Mansfield
  • 108,238
  • 20
  • 242
  • 324
5
votes
2 answers

Difference bloom filters and FM-sketches

What is the difference between bloom filters and hash sketches (also FM-sketches) and what is their use?
navige
  • 2,447
  • 3
  • 27
  • 53
5
votes
4 answers

Find a supplement to a subarray of ints in Java

Let we have int[] A = new int[1000] and int[] subA = new int [300] such that subA \in A (subA is a subset of A). How to find an array A \ subA in a fastest way in Java? Both given arrays A and subA are sorted. EDIT: sorry, forgot to mention that…
Sophie Sperner
  • 4,428
  • 8
  • 35
  • 55
5
votes
2 answers

is there an equivalent in C of python's set()?

I m seeking some equivalent in C of python's set() variable type any ideas? here is the python doc about sets http://docs.python.org/2/library/sets.html and could you explain/link me a help for this? please
Arnaud Aliès
  • 1,079
  • 13
  • 26
5
votes
2 answers

Java putting set into map

Whats the quickest way to put a set into a map? public class mySet { private Map map; public mySet(Set set) { Object[] array = set.toArray(); for(int i =0; i< array.length; i++) { …
ealeon
  • 12,074
  • 24
  • 92
  • 173
5
votes
2 answers

Sort Sets in ArrayList by Size

I thought of doing this by putting all of the sets in a list that would then be in a map, where the key is the size. I know the maximum size that a set could be(given to me), so I can just iterate between 0 and that number, get each list and then…
praks5432
  • 7,246
  • 32
  • 91
  • 156
5
votes
1 answer

how to use C++ STL and boost to tell if two sorted vectors intersect

I have two sorted C++ std::vector without duplicates (you could call them sets) and I want to know if they intersect. I do not need the vector of common elements. I wrote the code at the end of this question using the boost::set_intersection…
Stuart Pook
  • 453
  • 3
  • 7
5
votes
3 answers

How to Store unique objects to avoid the duplicates in java Set?

How to Store unique objects to avoid the duplicates in java Set? For example Consider Employee object which (Employee Id, name, salary....) list of employee of objects need to add in the Set. We need to restrict the Set for the duplicate elements…
iamjustcoder
  • 4,714
  • 10
  • 33
  • 46
5
votes
1 answer

How to sort a std::set with const getters

I have a std::set container whose elements are objects of the following class: class LaneConnector { public: const Lane* getLaneFrom() const { return From; } const Lane* getLaneTo() const { return To; } private: …
rahman
  • 4,820
  • 16
  • 52
  • 86
5
votes
2 answers

Best algorithm to compare a set with a collection of sets

What is the best algorithm to find the sets in a finite collection of sets that are a subset of a specific set? For example, if A = {1, 2} B = {2, 3, 4} C = {3, 5} D = {6} and X = {1, 2, 3, 5} Then, A and C are subsets of X. Is there an algorithm…
Mohammad
  • 117
  • 2
  • 8
5
votes
3 answers

PHP-EWS 2010, how to set the IsRead flag

I have been able to successfully retrieve the unread emails from an Exchange 2010 inbox using php-ews API. However after I have fetched the emails, I want to set the IsRead property of the email to true, so that these messages do not appear the next…
Lin
  • 273
  • 4
  • 21
5
votes
3 answers

Re-positioning a Rigid Body in Bullet Physics

I am writing a character animation rendering engine that uses Bullet Physics as a physics simulation engine. A sequence will start out with no model on the screen, then an animation will be assigned to that model, the model will be moved to frame 0…
bearsomg
  • 51
  • 1
  • 1
  • 4
5
votes
1 answer

Find unique elements in tuples in a python list

Is there a better way to do this in python, or rather: Is this a good way to do it? x = ('a', 'b', 'c') y = ('d', 'e', 'f') z = ('g', 'e', 'i') l = [x, y, z] s = set([e for (_, e, _) in l]) I looks somewhat ugly but does what i need without…
tinnet
  • 129
  • 1
  • 7
1 2 3
99
100