[glib: 1/8] Add some notes on complexity in glib/garray.c
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 1/8] Add some notes on complexity in glib/garray.c
- Date: Wed, 2 Sep 2020 13:09:54 +0000 (UTC)
commit 34f03f01c898d54b9e095643d9094137c3153738
Author: Emmanuel Fleury <emmanuel fleury gmail com>
Date: Tue Aug 6 18:33:07 2019 +0200
Add some notes on complexity in glib/garray.c
Related to issue #3
glib/garray.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
---
diff --git a/glib/garray.c b/glib/garray.c
index 4d29bc068..3f23b980d 100644
--- a/glib/garray.c
+++ b/glib/garray.c
@@ -58,17 +58,21 @@
*
* To create a new array use g_array_new().
*
- * To add elements to an array, use g_array_append_val(),
- * g_array_append_vals(), g_array_prepend_val(), g_array_prepend_vals(),
- * g_array_insert_val() and g_array_insert_vals().
+ * To add elements to an array with a cost of O(n) at worst, use
+ * g_array_append_val(), g_array_append_vals(), g_array_prepend_val(),
+ * g_array_prepend_vals(), g_array_insert_val() and g_array_insert_vals().
*
- * To access an element of an array (to read it or write it),
+ * To access an element of an array in O(1) (to read it or to write it),
* use g_array_index().
*
* To set the size of an array, use g_array_set_size().
*
* To free an array, use g_array_unref() or g_array_free().
*
+ * All the sort functions are internally calling a quick-sort (or similar)
+ * function with an average cost of O(n log(n)) and a worst case
+ * cost of O(n^2).
+ *
* Here is an example that stores integers in a #GArray:
* |[<!-- language="C" -->
* GArray *garray;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]