From 72cb2e77024970509ff403670f9e4245bcefebd6 Mon Sep 17 00:00:00 2001
From: Tucker Evans <tucker@tuckerevans.com>
Date: Fri, 3 Jul 2020 01:05:09 -0400
Subject: Add swap function to vectors

---
 collections/vector/vector.adoc | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

(limited to 'collections/vector/vector.adoc')

diff --git a/collections/vector/vector.adoc b/collections/vector/vector.adoc
index 0409b05..cc83375 100644
--- a/collections/vector/vector.adoc
+++ b/collections/vector/vector.adoc
@@ -1,7 +1,7 @@
 Vector
 ======
 Tucker Evans
-v0.10, 2020-07-03
+v0.11, 2020-07-03
 
 A basic vector, that hold pointers to your data structures.
 
@@ -257,6 +257,32 @@ vec_push(vector, str_dup(str3));
 assert(str_cmp(vec_index(vector, 1), str2) == 0);
 ----
 
+[[vec_swap]]
++void vec_swap(vec *self, int i, int j)+
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Swaps elements at positions +i+ and +j+, does nothing if +i+ or +j+ are out of
+bounds.
+
+Examples
+^^^^^^^^
+[source,c]
+----
+#include "dvector.h"
+#include <string.h>
+
+char *str1 = "ONE";
+char *str2 = "TWO";
+
+vec *vector = vec_new();
+vec_push(vector, str_dup(str1));
+vec_push(vector, str_dup(str2));
+
+vec_swap(vector, 0, 1);
+
+assert(str_cmp(vec_index(vector, 0), str2) == 0);
+assert(str_cmp(vec_back(vector), str1) == 0);
+----
+
 [[vec_clear]]
 +void vec_clear(vec *self)+
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- 
cgit v1.1

