<div dir="ltr"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">1. Batch tasks processing, especially in concurrent environments, when tasks could have different priorities. Sometimes tasks that are stored in a queue are processed in batches. Using today's stdlib of Java, acquiring such a batch of tasks from collection would be a O(n * log n) complexity, because each heapification is log n and called after each task is popped. Using TreeMultiset, this could be achieved in log (n). This also applies to messaging.</div></div></blockquote><div>This is a good point. There's no way for users to attach tree node metadata that are maintained when a BST is rebalanced, so having a rank operation for a Tree Multiset is quite helpful. Unfortunately, not even google guava supports this operation, but this is technically easy to implement.</div><div><br></div><div>I think this is the main advantage of a Multiset over regular Map<T, Collection<T>> implementations. However, given Java's TreeMap doesn't even support getting element by rank (its RBTree nodes don't record size), we might have to start with adding size to RBTree nodes first.</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto"><div dir="auto"><div class="gmail_quote" dir="auto"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto"><div dir="auto"><div class="gmail_quote" dir="auto"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
</blockquote></div></div></div>
</blockquote></div>
</blockquote></div></div></div>
</blockquote></div>
</blockquote></div>
</blockquote></div></div>