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

Python list intersection with non unique items

I have two strings and I would like to have the intersection on them including duplicate items: str_a = "aabbcc" str_b = "aabd" list(set(str_a) & set(str_b)) >> "ab" I would like to have it return: >> "aab" Any ideas?
RickyA
  • 15,465
  • 5
  • 71
  • 95
12
votes
3 answers

Generating all combinations with repetition using MATLAB

How do I create all k-combinations with repetitions of a given set (also called k-multicombinations or multisubsets) using MATLAB? This is similar to the cartesian product, but two rows that only differ by their sorting should be considered the…
knedlsepp
  • 6,065
  • 3
  • 20
  • 41
11
votes
3 answers

Data structure for querying whether a given subset exists in a collection of sets

I'm trying to build a data structure for a word game solver. I need to store about 150,000 sets of the form {A, A, D, E, I, L, P, T, V, Y}. (They are normalized English words, i.e. characters sorted. Note this is a multiset which can contain the…
PBJ
  • 757
  • 8
  • 21
11
votes
4 answers

Initializing multiset with custom comparison function in C++

Consider following comparison function: bool compare(std::shared_ptr &lhs, std::shared_ptr &rhs){ return lhs->value < rhs->value; } Now idea is to initialize a multiset of type std::shared_ptr which orders elements…
Jason
  • 147
  • 1
  • 1
  • 7
10
votes
2 answers

Why can not we use `std::multiset` with custom compare lambda as the value of a `std::map`?

This is a follow-up question of asked How to provide custom comparator for `std::multiset` without overloading `operator()`, `std::less`, `std::greater`? and I have tried to solve by the following manner. Basic One can provide custom compare lambda…
JeJo
  • 30,635
  • 6
  • 49
  • 88
10
votes
1 answer

How to find the 2nd max of a Counter - Python

The max of a counter can be accessed as such: c = Counter() c['foo'] = 124123 c['bar'] = 43 c['foofro'] =5676 c['barbar'] = 234 # This only prints the max key print max(c), src_sense[max(c)] # print the max key of the value x =…
alvas
  • 115,346
  • 109
  • 446
  • 738
9
votes
0 answers

Multiset domination algorithm

Let us say that a multiset M dominates another multiset N if each element in N occurs at least as many times in M. Given a target multiset M and an integer k>0, I'd like to find a list, L, of size-k multisets whose sum dominates M. I'd like this…
dshin
  • 2,354
  • 19
  • 29
9
votes
2 answers

Multiset Index Finding

I have a multi set of int . C++ multisett; I need to find the position of the first element which is greater than of equal to val. I used lower_bound for this multiset::iterator it= lower_bound(t[n].begin(), t[n].end(), val); but can not…
Matrix.code
  • 93
  • 1
  • 2
  • 6
9
votes
1 answer

Table-cast vs cast-multiset in pl-sql

What is the use of Table-CAST and CAST-Multiset? Example of Table-Cast SELECT count(1) INTO v_Temp FROM TABLE(CAST(Pi_Save_Data_List AS Property_data_list)) WHERE Column_Value LIKE '%Contact'; Example of Cast-Multiset SELECT e.last_name, …
Plymouth Rock
  • 472
  • 2
  • 6
  • 20
9
votes
5 answers

Are Multisets missing in Scala?

I was trying the Facebook Hacker Cup 2013 Qualification Problems in Scala, and for the 3rd problem I felt the need of an ordered Multiset but could not find one in scala's (2.10) collections. Is this data structure missing in scala's collections. Is…
redoacs
  • 133
  • 1
  • 4
9
votes
3 answers

Moving elements out of an associative container

Just for fun, I have implemented the simplest sorting algorithm imaginable: template void treesort(Iterator begin, Iterator end) { typedef typename std::iterator_traits::value_type element_type; // copy data…
fredoverflow
  • 256,549
  • 94
  • 388
  • 662
9
votes
2 answers

Why is the STL priority_queue not much faster than multiset in this case?

I am comparing performance of an STL (g++) priority_queue and found that push and pop are not as fast as I would expect. See the following code: #include #include using namespace std; typedef multiset IntSet; void testMap() { …
Jeroen Dirks
  • 7,705
  • 12
  • 50
  • 70
8
votes
4 answers

Efficient hash code for multiset in Java

I have defined a subinterface of java.util.Collection that effectively is a multiset (aka bag). It may not contain null elements, although that's not crucial to my question. The equals contract defined by the interface is as you would expect: obj…
Rinke
  • 6,095
  • 4
  • 38
  • 55
8
votes
6 answers

Get list of unique multi-sets

How can I uniquify the following list in Python: all_the_ways = [(5,), (2, 2, 1), (2, 1, 2), (2, 1, 1, 1), (1, 2, 2),\ (1, 2, 1, 1), (1, 1, 2, 1), (1, 1, 1, 2), (1, 1, 1, 1, 1)] Desired output is: [(5,), (2, 2, 1), (2, 1, 1, 1), (1,…
tsionyx
  • 1,629
  • 1
  • 17
  • 34
7
votes
2 answers

C++ std::set and std::multiset

In C++ by default both std::set and std::multiset have std::less as their comparator. Can anyone please explain how does std::multiset allow duplicates and std::set does not?
A Roy
  • 91
  • 1
  • 2
1
2
3
22 23