[Asterisk-code-review] vector.h: Add AST_VECTOR_SORT() (asterisk[18])

George Joseph asteriskteam at digium.com
Fri Jul 24 11:29:36 CDT 2020


George Joseph has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/14676 )

Change subject: vector.h: Add AST_VECTOR_SORT()
......................................................................

vector.h: Add AST_VECTOR_SORT()

Allows a vector to be sorted in-place, rather than only during
insertion.

Change-Id: I22cba9ddf556a7e44dacc53c4431bd81dd2fa780
---
M include/asterisk/vector.h
1 file changed, 10 insertions(+), 0 deletions(-)

Approvals:
  Joshua Colp: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved; Approved for Submit



diff --git a/include/asterisk/vector.h b/include/asterisk/vector.h
index 291cdf4..8f5cf8c 100644
--- a/include/asterisk/vector.h
+++ b/include/asterisk/vector.h
@@ -388,6 +388,16 @@
 })
 
 /*!
+ * \brief Sort a vector in-place
+ *
+ * \param vec Vector to sort
+ * \param cmp A memcmp compatible compare function
+ */
+#define AST_VECTOR_SORT(vec, cmp) ({ \
+	qsort((vec)->elems, (vec)->current, sizeof(typeof((vec)->elems[0])), cmp); \
+})
+
+/*!
  * \brief Remove an element from a vector by index.
  *
  * Note that elements in the vector may be reordered, so that the remove can

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/14676
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 18
Gerrit-Change-Id: I22cba9ddf556a7e44dacc53c4431bd81dd2fa780
Gerrit-Change-Number: 14676
Gerrit-PatchSet: 4
Gerrit-Owner: Sean Bright <sean.bright at gmail.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20200724/ae2ce441/attachment.html>


More information about the asterisk-code-review mailing list