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
-1
votes
2 answers

Why must I use a const& parameter when defining a functor for STL?

auto cmp = [](pair & left, pair & right){if(left > right) return true; else return false;}; multiset, decltype(cmp)> mt(cmp); // If I just compile the two lines above, it will work. // But if I try to insert some…
Yves
  • 11,597
  • 17
  • 83
  • 180
-1
votes
3 answers

STL multiset setting insertion order C++

I am using a multiset to store a collection of objects ordered, I am using operator< to establish the order criteria, but I am doing something wrong because when I iterate through the multiset printing a trace, I can see that they are not ordered at…
Breikdans
  • 67
  • 6
-1
votes
1 answer

How to use a multiset? (guava)

Is it possible to use a Multiset for the purpose of counting letter frequencies of the first letter in a word. Those words exist in a list. example. [the, quick, brown, fox, jumped, over, the, lazy, dog] Output: most common first character: [t, q,…
FatFockFrank
  • 169
  • 1
  • 4
  • 17
-1
votes
2 answers

Google Guava MultiSet returning incorrect value

I am using Google Guava APIs to calculate word count. public static void main(String args[]) { String txt = "Lemurs of Madagascar is a reference work and field guide giving descriptions and biogeographic data for all the known lemur…
Yogi
  • 1,035
  • 2
  • 13
  • 39
-2
votes
1 answer

Can inserting 5*1e8 element in long long multiset crash the program?

I seem to have run in a weird problem. I have a multiset consisting of long longs, but when I try to insert number 5*1e8, it crashes. For more info, when I try to insert the number the multiset is empty ( but I don't see how that could affect…
-2
votes
4 answers

How to create multiset data structure in python

I was trying to solve some of hackerrank questions where I got one question related to multiset. I tried this code but I little bit confused about at which point am I making mistake? class Multiset: def __init__(self): self.items=[] …
Sharma Shivlal
  • 21
  • 1
  • 1
  • 7
-2
votes
1 answer

Multiset With Structures

I want to declare a multiset of a structure. The current form of my declaration of multiset is struct obj { //code }; struct compare { inline bool operator()(const obj &a, const obj &b) { //code } }; multiset
-2
votes
3 answers

Create a multiset from a Set X

in a Multiset it is allowed to have multiple elements For Example. if X (normal set) = {0,2,4,7,10}, then ∆X (multiset) = {2,2,3,3,4,5,6,7,8,10}. ∆X denotes the multiset of all (N 2) pairwise distances between points in X How can i Write this in…
-2
votes
1 answer

How do I solve this out-of-bound-exception for this multi-set?

I keep getting an out-of-bounds-exception. I've checked other sources and it mostly seems to be due to a faulty loops, but mine is fine. Both arrays _store and arr have entries. HEADER CODE: public class ArrayMultiSet implements Collection { …
Gintoki
  • 97
  • 1
  • 9
-2
votes
1 answer

C++ multiset create from sorted vector

I have sorted array: vector arrs; I have a multiset multiset> tr; I have this: tr.erase(); tr.insert(arrs.begin(), arrs.end()); I need convert vector to set fast(linear complexity). Can i do this with use std or…
-2
votes
1 answer

Python dict MultiSet

How do I write the code in Python by using dict? The MultiSet ADT: init(self) - add(item, m) - Add item to the multiset with multiplicity m . If no multiplicity is given, it should default to multiplicity = 1. remove(item, m) - Remove m copies of…
Milkxd
  • 11
  • 1
  • 5
-3
votes
1 answer

Can a list with repeating values be converted into a multiset in python?

I am having two lists with repeating values and I wanted to take the intersection of the repeating values along with the values that have occurred only once in any one of the lists. I am just a beginner and would love to hear simple suggestions!
-4
votes
4 answers

Difference between a list and multiset in C++

In C++: A list is a collection that can contain non-unique values in sequence A multiset is a collection that can contain non-unique elements in sequence What then is the specific difference between the two? Why would I use on over the other? I've…
Toby
  • 9,696
  • 16
  • 68
  • 132
-5
votes
3 answers

Why is iterator in set(c++) not behaving properly?

This is code I have written: multisetS; for(int i = 0;i<20;i++) S.insert(i); for(auto it = S.end();it!=S.begin();--it) cout<<*it<<" "; cout<
user3778989
  • 127
  • 1
  • 2
  • 8
1 2 3
22
23