Browse Source

added swap pop function, added some doc

Iver 3 weeks ago
parent
commit
e1dd7cab4f
4 changed files with 17 additions and 0 deletions
  1. BIN
      builds/libkiyomitree.so
  2. BIN
      builds/main.bin
  3. 9 0
      src/headers/KT_functions.h
  4. 8 0
      src/main/main.c

BIN
builds/libkiyomitree.so


BIN
builds/main.bin


+ 9 - 0
src/headers/KT_functions.h

@@ -3,16 +3,25 @@
 
 
 #include <stdlib.h>
 #include <stdlib.h>
 
 
+// allocate and return a new KT array
 void** KT_new_array(size_t element_count);
 void** KT_new_array(size_t element_count);
 
 
+// add a void* to the end of the array
 void KT_append(void*** array, void* pointer);
 void KT_append(void*** array, void* pointer);
 
 
+// add a void* to the start of the array
 void KT_prepend(void*** array, void* pointer);
 void KT_prepend(void*** array, void* pointer);
 
 
+// add a void* to the left of an index in the array
 void KT_insert_left(void*** array, void* pointer, size_t index);
 void KT_insert_left(void*** array, void* pointer, size_t index);
 
 
+// add a void* to the right of an index in the array
 void KT_insert_right(void*** array, void* pointer, size_t index);
 void KT_insert_right(void*** array, void* pointer, size_t index);
 
 
+// remove a void* from the array (this shifts all data following over, unlike KT_swap_pop)
 void KT_drop(void*** array, size_t index);
 void KT_drop(void*** array, size_t index);
 
 
+// remove a void* from the array (unlike KT_drop, it does not move following data over, but instead changes the order of the array)
+void KT_swap_pop(void*** array, size_t index);
+
 #endif
 #endif

+ 8 - 0
src/main/main.c

@@ -87,3 +87,11 @@ void KT_drop(void*** array, size_t index){
     
     
     if (*existing_elements != index) memmove(*array + index, *array + index + 1, sizeof(void*) * (*existing_elements - index));
     if (*existing_elements != index) memmove(*array + index, *array + index + 1, sizeof(void*) * (*existing_elements - index));
 }
 }
+
+void KT_swap_pop(void*** array, size_t index){
+    size_t* existing_elements = (size_t*)(*array)[-1];
+
+    (*existing_elements)--;
+
+    array[index] = array[*existing_elements];
+}