GLib trees



Hi,

I was looking through the GTree source code and noticed that the
implementation is an AVL tree. In some cases, however, other
structures might be faster or more memory efficient - GLib doesn't let
the user decide. I was thinking that maybe something like the
following could be done:

GUnbalancedTree
GSplayTree
GAVLTree
GRedBlackTree

would have "virtual" pointers to functions implementing their
respective insertion, deletion, etc. functions, and the g_tree_insert
etc. "generic" functions would call the right ones through the vtable.
This way, different data structures could be profiled quite easily
without changing any code; one could change the creation functions to
g_splay_tree_new or whatever and test the performance. Once one was
decided on, the function calls themselves could be replaced with
non-virtual calls.

This, however, is slightly more complicated, and the performance
benefits would only be noticed in very large sets of data - I wasn't
sure if GLib was designed for performance or simplicity and
convenience. Any thoughts on this?

Thanks,
Samuel



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