Re: Glib questions.
- From: paige rcnchicago com (Mojo B. Nichols)
- To: Sven Neumann <sven gimp org>
- Cc: paige rcnchicago com (Mojo B. Nichols), gtk-list gnome org
- Subject: Re: Glib questions.
- Date: 12 May 2002 00:19:16 -0500
>>>>> "Sven" == Sven Neumann <sven gimp org> writes:
> 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.
Hmmm, well I could certainly try it, but (and my apologies for not
being clear earlier) it needs to be sorted by value not key. I assume
that the order of a GTree is by key and has nothing to do with value.
The lists aren't that big (I can't imagine more then 20000 rows), so
the ability to sort by value is more important.
I think that the reality is that whether, Gtree, Hash, or list I need
to have go through the rigors of sorting the value by "hand". I was
kind of thinking tying two hash's together, or hash and a list to make
the code easy and although maybe not so efficient. Use the look up on
one and the order on another... Or perhaps write everything myself.
Thanks for your help I will play with the GTree.
Mojo
--
_______________________________________________________________________________
"I've finally learned what `upward compatible' means. It means we
get to keep all our old mistakes."
-- Dennie van Tassel
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]