Re: Glib questions.



Hi,

paige rcnchicago com (Mojo B. Nichols) writes:

> I don't know if this an appropriate forum for posting Glib questions
> or not.  I have a problem in which I was going to use a hash table to
> solve, but am know having doubts, or wondering if there is a better
> approach.  Basically I need to store a string followed by an integer,
> (although for now I'm just storing the int as a string and converting
> as necessary).  Each time a string comes along I basically increment
> the integer.  Eventually I dump the list sorted on the integer. So
> I've worked through doing the look up in the hash table and have that
> working appropriately, but it looks like the only way to sort is to
> dump out of the hash, and either sort myself or say strcat(value and
> the key) into a list and sort that list....  Which brings me to why
> not just use a list in the first place, except of course then I can't
> only search on the first string...  The data_relation seems to also
> get me almost there, but then not allow me to sort.   Intuition tells
> me to just manipulate the GHash directly, but the manual suggests that
> I shouldn't.   A couple of functions, one that returns a list of
> values sorted by key and another that returns a list of keys sorted by
> values seem like they would be useful... Any way it seems like a
> somewhat common piece of code and I'm lazy as a sack of potatoes so if
> someone know a better way please let me know.... Using Glib...  

looks like you want to use a GTree, which is a balanced binary tree.
Lookups on balanced binary trees are reasonably fast as long as the
amount of data isn't too large and in contrast to a hash table, the
data is sorted.


Salut, Svem




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