Re: hash table freeze is useless



> I was just noticing that g_hash_table_insert() performs a hash lookup.  
> This means that if you freeze the hash table, then insert a lot of items,
> the performance of g_hash_table_insert() will be degenerating into O(n)
> over time, so your insert-items loop will have O(n^2) performance. Without
> the freeze, it is basically O(n) (with the hash resizes amortized, and
> each insertion constant time).
> 
> A better solution than freeze/thaw might be a way to set the expected
> number of items, g_hash_table_resize_for(hash, n_items) which would resize
> the table in advance to accomodate that number of additional items, saving 
> n_items re-insertions and perhaps reducing the total number of resizes.

I believe the intent is so you can freeze a hashtable that is 
large, delete half the items, insert a bunch of new items
without resizing the table extraneously.

- Dave



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