Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > multiset unique values count

Reply
Thread Tools

multiset unique values count

 
 
dushkin
Guest
Posts: n/a
 
      02-04-2010
Hi
I wish someone can give a tip on this one..
http://groups.google.co.il/group/com...060bace91a1830
Thanks!
 
Reply With Quote
 
 
 
 
tonydee
Guest
Posts: n/a
 
      02-09-2010
On Feb 4, 5:09*pm, dushkin <(E-Mail Removed)> wrote:
> Is it possible to know (without iterating ofcourse) how many
> unique keys are in a multiset?
> I know that a set has unique values, but I would prefer
> using multiset in my solution if I have the unique keys
> counting solution.
>
> Example:
>
> Given a multiset with values: {1,1,2,4,5,4,3,1} - The unique
> counting will give me 5 for {1,2,3,4,5} keys.


> A indirect solution may be adding the multiset items to a
> set and then get the set size..
> But I wonder if there is a direct way of getting the unique
> items number


STL's multisets do not have any special support for this, i.e. they
don't spend time / use extra memory to track the unique keys while the
values are being inserted. Therefore, you must either proactively
maintain your own count while inserting and erasing from the multiset
(e.g. insert: check if the multiset includes the key, add 1 to
unique_keys counter if not). Otherwise, you will need to step through
the container to count unique keys... using upper_bound() will skip to
the next key, which just might be faster than a simple iteration, but
could also be slower (may depend on average number of times a key
repeats).

Cheers,
Tony
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
multiset unique elements counting dushkin C++ 1 02-02-2010 10:19 AM
list question... unique values in all possible unique spots ToshiBoy Python 6 08-12-2008 05:01 AM
Order items within multiset AND Find object on multiset =?iso-8859-1?q?Jo=E3o_Correia?= C++ 2 02-27-2007 01:04 AM
simple multiset question John Harrison C++ 3 08-04-2004 08:32 AM
multiset segfault Arthur J. O'Dwyer C++ 10 06-18-2004 03:21 AM



Advertisments