aboutsummaryrefslogtreecommitdiffstats
path: root/src/libutil/util.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2020-08-22 12:51:06 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2020-08-22 12:51:06 +0100
commitdc917551811ef6850831f0770016e65f3d2e51dd (patch)
treebbf1cf36f424713cefdc9f1c914d9e3d1addeeee /src/libutil/util.c
parentd1cab3edeef224d8d2611087d4fa12623e68165d (diff)
downloadrspamd-dc917551811ef6850831f0770016e65f3d2e51dd.tar.gz
rspamd-dc917551811ef6850831f0770016e65f3d2e51dd.zip
[Minor] Add ptr array shuffle routine
Diffstat (limited to 'src/libutil/util.c')
-rw-r--r--src/libutil/util.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/libutil/util.c b/src/libutil/util.c
index 19f07e82d..9e5147ab5 100644
--- a/src/libutil/util.c
+++ b/src/libutil/util.c
@@ -2437,4 +2437,21 @@ rspamd_set_counter_ema (struct rspamd_counter_data *cd,
cd->number ++;
return cd->mean;
+}
+
+void
+rspamd_ptr_array_shuffle (GPtrArray *ar)
+{
+ if (ar->len < 2) {
+ return;
+ }
+
+ guint n = ar->len;
+
+ for (guint i = 0; i < n - 1; i++) {
+ guint j = i + rspamd_random_uint64_fast () % (n - i);
+ gpointer t = g_ptr_array_index (ar, j);
+ g_ptr_array_index (ar, j) = g_ptr_array_index (ar, i);
+ g_ptr_array_index (ar, i) = t;
+ }
} \ No newline at end of file