Re: Glib equivalent to std::set



Peter wrote:
Paul Pogonyshev wrote:

Peter wrote:
 

I've been wanting to start an app in C++, but am leaning towards GLib
partly because of its easy Python integration.  My question is, what is
the best way to get a std::set equivalent in GLib?..
   


It seems there is no direct analogue in GLib.  However, you can get away
with using either GHashTable or GTree.  Maybe a little inefficient WRT
storage size, but I can tell you that Sets in Java (at least 1.4) are
implemented on top of Maps, i.e. essentially in the same way.
 

So, ignore the value and store my data in the keys?  Are the keys
guaranteed to be sorted when actually iterating?  After a closer look at
the APIs, I think g_list_find then g_list_insert_sorted could do the
trick as well.  I understand that this means I'll get two iterations and
two comparisons, not to mention loosing out on the benefits of
non-linear sorting (like a binary tree). I can use g_list_next and
g_list_insert_before to mitigate the first problem.  The second problem
may require me to implement my own sorting algorithm.  Oh well, looking
at other's code, it should be pretty competitive without requiring a Ph.D.

If you need it to be sorted, use GTree.

Paul



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]