Questions tagged [multiset]

Anything related to multisets (a.k.a. bags), i.e. data structures that are generalizations of sets and in which an element can be present more than once. This tag applies to questions about multisets implementations, regardless of the specific programming language involved.

Anything related to multisets (a.k.a. bags), i.e. data structures that are generalizations of sets and in which an element can be present more than once. This tag applies to questions about multisets implementations, regardless of the specific programming language involved.

See Wikipedia page on multisets.

344 questions
112
votes
10 answers

In std::multiset is there a function or algorithm to erase just one sample (unicate or duplicate) if an element is found

Perhaps this is a duplicate but I did not find anything searching: When erase(value) is called on std::multiset all elements with the value found are deleted. The only solution I could think of is: std::multiset::iterator hit(mySet.find(5)); if…
Martin
  • 4,738
  • 4
  • 28
  • 57
41
votes
7 answers

"multiset" & "multimap" - What's the point?

As the question states ... I don't get the point about multisets / multimaps. So, what's the purpose?
Sebastian
  • 8,046
  • 2
  • 34
  • 58
38
votes
5 answers

Is there a Python equivalent for C++ "multiset"?

I am porting some C++ code to Python and one of the data structures is a multiset, but I am not sure how to model this in Python. Let ms be the C++ multiset How ms is used (posting some examples) multiset::iterator it =…
MrP
  • 801
  • 2
  • 10
  • 14
35
votes
3 answers

How to generate permutations or combinations of object in R?

How to generate sequences of r objects from n objects? I'm looking for a way to do either permutations or combinations, with/without replacement, with distinct and non-distinct items (aka multisets). This is related to twelvefold way. The "distinct"…
Randy Lai
  • 3,084
  • 2
  • 22
  • 23
32
votes
4 answers

Simplest way to iterate through a Multiset in the order of element frequency?

Consider this example which prints out some device type stats. ("DeviceType" is an enum with a dozenish values.) Multiset histogram = getDeviceStats(); for (DeviceType type : histogram.elementSet()) { System.out.println(type + ": " +…
Jonik
  • 80,077
  • 70
  • 264
  • 372
30
votes
5 answers

Are there any implementations of multiset for .Net?

I'm looking for a .Net implementation of a multiset. Can anyone recommend a good one? (A multiset, or bag, is a set that can have duplicate values, and on which you can do set operations: intersection, difference, etc. A shopping cart for instance…
dan-gph
  • 16,301
  • 12
  • 61
  • 79
21
votes
4 answers

Why is using a std::multiset as a priority queue faster than using a std::priority_queue?

I try to replace std::multiset with std::priority_queue. But I was dissapointed with the speed results. Running time of the algorithm increase by 50%... Here are the corresponding commands: top() = begin(); pop() = erase(knn.begin()); push() =…
Johny
  • 323
  • 2
  • 3
  • 5
21
votes
2 answers

Adding counters deletes keys

See below, why does the implementation of += blow away a key in my original counter? >>> c = Counter({'a': 0, 'b': 0, 'c': 0}) >>> c.items() [('a', 0), ('c', 0), ('b', 0)] >>> c += Counter('abba') >>> c.items() [('a', 2), ('b', 2)] I think that's…
wim
  • 338,267
  • 99
  • 616
  • 750
20
votes
6 answers

Filter a Set for Matching String Permutations

I am trying to use itertools.permutations() to return all the permutations of the string and return only the ones which are members of a set of words. import itertools def permutations_in_dict(string, words): ''' Parameters ---------- …
Meruemu
  • 611
  • 1
  • 8
  • 28
17
votes
3 answers

which element will be returned from std::multimap::find, and similarly std::multiset::find?

Most likely this question is a duplicate but I could not find a reference to it. I'm looking at std::multiset::find & std::multimap::find functions and I was wondering which element will be returned if a specific key was inserted multiple…
idanshmu
  • 5,061
  • 6
  • 46
  • 92
15
votes
2 answers

Iterating over unique elements of `std::multiset`

All I need is to know if something exists and how many times it exist. I will iterate over the existent things and query how much of that exists. My implementation so far uses multiset, I do as follow: std::multiset a; auto previous =…
André Puel
  • 8,741
  • 9
  • 52
  • 83
14
votes
1 answer

Multiset erase last element

I am trying to erase the last element of a multiset using: minheap.erase(minheap.rbegin()); It doesn't compile, and gives 4-5 erros. Note that in C++ multisets, .end() points next to the last element, and not to the last element. Any…
XCS
  • 27,244
  • 26
  • 101
  • 151
14
votes
2 answers

C++ : Running time of next() and prev() in a multiset iterator?

What is the time complexity of applying the next() and prev() function on an multiset::iterator type object where the corresponding multiset contains the N elements? I understand that in STL, a multiset is implemented as a balanced binary…
Banach Tarski
  • 1,821
  • 17
  • 36
13
votes
5 answers

Is there an algorithm to generate all unique circular permutations of a multiset?

I encountered this problem when doing some enthusiastic programming. The problem can be expressed as follows: For a multiset A, let P(A) denote the set of all possible permutations of A. P(A) is naturally divided into disjoint subsets that…
Cong Ma
  • 10,692
  • 3
  • 31
  • 47
13
votes
2 answers

Find top N elements in a Multiset from Google Collections?

A Google Collections Multiset is a set of elements each of which has a count (i.e. may be present multiple times). I can't tell you how many times I want to do the following Make a histogram (exactly Multiset) Get the top N elements by count from…
dfrankow
  • 20,191
  • 41
  • 152
  • 214
1
2 3
22 23