问题标签 [multiset]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
4195 浏览

java - 如何根据输入值和计数对 Guava Multiset 进行排序?

我有一个番石榴Multiset<Integer>,想通过按(a)元素值和(b)元素计数排序的条目独立迭代。我已经使用最简单的方法按元素频率的顺序遍历 Multiset?作为

但这会返回所有条目,而我想要一个排序列表Multiset.Entry<Integer>(每个唯一值一个),这将允许我获得计数。

独立地,我想获得Multiset.Entry<Integer>按 的值排序的相同列表<Integer>

0 投票
1 回答
857 浏览

c++ - 定义映射/集合时如何实例化比较函数(函子)?

我正在使用函数对象来指定地图/集的比较函数:

据我了解,定义这样的集合不会创建任何 CompareObject 实例,并且会假装它是静态的:

但是在我的问题中,我需要将 Tree 的实例传递给它,因为我在实际的比较函数中使用它:

所以,我在 CompareObject 定义中添加了一些字段:

我遇到的问题是我不知道如何用集合的定义来实例化这个对象。

我首先想到的是:

但不出所料,它给了我一个错误:“this”不能出现在常量表达式中

您对如何解决这个问题有任何想法吗?

0 投票
4 回答
1977 浏览

c++ - C ++多重集:删除最后一个元素

如何从多重集中删除最后一个元素。我尝试将反向迭代器传递给擦除函数,但这是不允许的。有什么建议么?

0 投票
2 回答
1683 浏览

object - 方案中的“设置!不是标识符”

我正在尝试使用 set! 修改列表元素的汽车的 cdr,但出现错误:“set!不是标识符”。谁能向我解释为什么会这样?顺便说一句,我开始使用对象。

多重集表示为对的列表。例如,如果我有一个列表 '(1 1 1 2 2 2),那么多重集表示将是 '((1.3)(2.3))

0 投票
1 回答
148 浏览

java - 为什么番石榴的 AbstractMultiset 不公开?

我试图编写一个扩展番石榴的类,AbstractMultiset但我发现它不是一个公共类。这是为什么?
我应该扩展一个不同的类吗?我知道的其他类似课程(AbstractCollection,AbstractSet等)公开的。

0 投票
1 回答
242 浏览

c++ - 在 multiset 中,代码没有进入比较函数并抛出错误

我已经使用断点来检查在将元素插入 Multi-set 时是否调用了我的比较函数,但它从未到达断点。

错误Unhandled exception at 0x003c5a71 in Regular_Calibration_d.exe: 0xC0000005: Access violation reading location 0x00000014.

我粘贴下面的代码。请让我知道我在哪里做错了。几个我有疑问的重要事情。

  • 1) 我在将 sms.message 实际插入到多集中之前对其进行操作,所以你们认为我在那里做错了什么会造成问题吗?

  • 2)如果我暂时认为字符串操作有问题,但是为什么它没有命中比较时间的comapre函数。

下面是我的代码。

短信结构

//消息构造器

//比较函数

//多集声明

// 在某个函数中

// 字符串操作

0 投票
3 回答
7612 浏览

c++ - std::multimap::find 将返回哪个元素,类似地 std::multiset::find?

这个问题很可能是重复的,但我找不到它的参考。

我正在查看std::multiset::findstd::multimap::find函数,我想知道如果多次插入特定键,将返回哪个元素?

从描述:

请注意,此函数将迭代器返回到单个元素(可能是多个等效元素)

问题

是否保证单个元素第一个插入的元素还是随机的?

背景

我问的原因是我正在实现类 multipmap:

我想get_item()完全按照std::multimap::find. 可能吗?如果是这样,它将如何实施?

0 投票
3 回答
516 浏览

java - Get an ordered subset from a Multiset of the most frequent X entries

I have

I want to have a Multiset with the 200 most frequent keys. I've figured out how to get an ImmutableMultiset that is ordered by frequency but I'm having trouble getting just a subset of it.

I got the sorting aspect from this other stackOverFlow question

For the subset aspect I tried using a MinMaxPriorityQueue so that I can use the maximumSize(200).

But it seems to return just a random selection of 200 of the keys. And checking the top value from orderedMultiset doesn't even appear in the returned MinMaxPriorityQueue. I also am afraid that even if it did get them in order I might end up with only a couple different keys where the sum of the counts total 200. And preferably I'd like to have 200 different keys with the count for each.

I asked someone and they mentioned something about a POJO and a Comparable but I didn't follow what they suggested. Since a POJO can't really implement a Comparable by definition. I'm not really sure.

I also was playing around with using the guava Ordering but I don't think that will work since the function would be taking Strings and is unaware of the counts from the multiset.

Does anyone know what I'm doing wrong here or at least point in the right direction. Thanks

0 投票
1 回答
533 浏览

c++ - 插入多组的运行时间

插入多集合的整体运行时间是多少,假设我要遍历十亿个元素并插入多集合,它保持有序的顺序。我最坏的情况下运行时间是多少?

0 投票
2 回答
154 浏览

java - Google Guava MultiSet 返回不正确的值

我正在使用 Google Guava API 来计算字数。

输出应该是

但是我是这样的:

我究竟做错了什么?