Browse Source

first commit

Iver 6 hours ago
commit
497505f0ec
12 changed files with 178 additions and 0 deletions
  1. 16 0
      Makefile
  2. 5 0
      changelog.txt
  3. 1 0
      dbg
  4. 0 0
      issues.txt
  5. 13 0
      readme.md
  6. 1 0
      run
  7. 36 0
      src/headers/OT_functions.h
  8. 9 0
      src/headers/OT_types.h
  9. 8 0
      src/headers/orangetree.h
  10. 3 0
      src/launch program/main.c
  11. 85 0
      src/main/main.c
  12. 1 0
      val

+ 16 - 0
Makefile

@@ -0,0 +1,16 @@
+COMPILER=gcc
+FLAGS_ALL=-g -Wall -Wextra -Wno-unused-variable -Wno-unused-parameter
+FLAGS_EXAMPLE=-Lbuilds/ -lNAMEHERE -lLIBNAMEHERE -Wl,-rpath=builds/ -lm
+FLAGS_LIB=-fPIC -shared -lc -lm 
+
+main.bin: NAMEHERE.so LIBNAMEHERE.so
+	$(COMPILER) $(FLAGS_ALL) src/launch\ program/main.c -o builds/main.bin $(FLAGS_EXAMPLE) 
+
+NAMEHERE.so:
+	$(COMPILER) $(FLAGS_ALL) src/main/main.c -o builds/librasteriver.so $(FLAGS_LIB) 
+
+LIBNAMEHERE.so:
+	cp src/libraries/libLIBNAMEHERE.so builds/
+
+clean:
+	rm builds/*

+ 5 - 0
changelog.txt

@@ -0,0 +1,5 @@
+-added all basic function of linked list (i didn't do any research so im assuming this is how it works)
+-(also i havent tested this at all so idk if it works. lets push to prod!)
+-wrote comments in OT_functions.h
+-added etymology
+-added how-to

+ 1 - 0
dbg

@@ -0,0 +1 @@
+gdb -ex run builds/main.bin

+ 0 - 0
issues.txt


+ 13 - 0
readme.md

@@ -0,0 +1,13 @@
+# OrangeTree, A Linked List Manager
+
+## How to use?
+
+ * Simple, the only thing you have to do in order to make a struct into an OrangeTree linked list is to put 2 members in the start of your struct
+ * `void* OT_next`
+ * `void* OT_prev`
+ * Done!
+
+## Etymology
+
+ * Orange trees have branches, linked lists are kind of like branches idk
+ * it's getting harder and harder to come up with names for this stuff

+ 1 - 0
run

@@ -0,0 +1 @@
+./builds/main.bin

+ 36 - 0
src/headers/OT_functions.h

@@ -0,0 +1,36 @@
+#ifndef OT_FUNCTIONS_H
+#define OT_FUNCTIONS_H
+
+// - Returns the last element of a linked list
+// - Takes in any element of the list
+void* OT_get_last(void* operand);
+
+// - Returns the first element of a linked list
+// - Takes in any element of the list
+void* OT_get_first(void* operand);
+
+// - Removes an element from the linked list and frees it
+// - Takes in specific element of the list
+void OT_drop(void* operand);
+
+// - Adds an element to the end of a linked list
+// - Takes in any element of the list
+void OT_append(void* operand, void* appendee);
+
+// - Adds and element to the beginning of a linked list
+// - Takes in any element of the list
+void OT_prepend(void* operand, void* prependee);
+
+// - Adds an element to the left of an element in a linked list
+// - Takes in specific element of the list
+void OT_insert_left(void* operand, void* insertee);
+
+// - Adds an element to the right of an element in a linked list
+// - Takes in specific element of the list
+void OT_insert_right(void* operand, void* insertee);
+
+// - Frees entire list
+// - Takes in any element of the list
+void OT_free(void* operand);
+
+#endif

+ 9 - 0
src/headers/OT_types.h

@@ -0,0 +1,9 @@
+#ifndef OT_TYPES_H
+#define OT_TYPES_H
+
+struct OT_operand {
+    void* OT_next;
+    void* OT_prev;
+};
+
+#endif

+ 8 - 0
src/headers/orangetree.h

@@ -0,0 +1,8 @@
+#ifndef ORANGETREE_H
+#define ORANGETREE_H
+
+#include <stdlib.h>
+#include "OT_types.h"
+#include "OT_functions.h"
+
+#endif

+ 3 - 0
src/launch program/main.c

@@ -0,0 +1,3 @@
+int main(){
+    return 0;
+}

+ 85 - 0
src/main/main.c

@@ -0,0 +1,85 @@
+#include "../headers/orangetree.h"
+
+void* OT_get_last(void* operand){
+    struct OT_operand* cur_oper = (struct OT_operand*)(operand);
+
+    while (cur_oper->OT_next)
+        cur_oper = (struct OT_operand*)(cur_oper->OT_next);
+
+    return (void*)cur_oper;
+}
+
+void* OT_get_first(void* operand){
+    struct OT_operand* cur_oper = (struct OT_operand*)(operand);
+
+    while (cur_oper->OT_prev)
+        cur_oper = (struct OT_operand*)(cur_oper->OT_prev);
+
+    return (void*)cur_oper;
+}
+
+void OT_drop(void* operand){
+    struct OT_operand* oper = (struct OT_operand*)operand;
+    
+    struct OT_operand* prev = (struct OT_operand*)oper->OT_prev;
+    struct OT_operand* next = (struct OT_operand*)oper->OT_next;
+
+    if (prev) prev->OT_next = (void*)next;
+    if (next) next->OT_prev = (void*)prev;
+
+    free(operand);
+}
+
+void OT_append(void* operand, void* appendee){
+    struct OT_operand* app = (struct OT_operand*)appendee;
+    
+    struct OT_operand* last_element = (struct OT_operand*)OT_get_last(operand);
+
+    last_element->OT_next = appendee;
+    app->OT_prev = (void*)last_element;
+}
+
+void OT_prepend(void* operand, void* prependee){
+    struct OT_operand* pre = (struct OT_operand*)prependee;
+    
+    struct OT_operand* first_element = (struct OT_operand*)OT_get_first(operand);
+
+    first_element->OT_prev = prependee;
+    pre->OT_next = (void*)first_element;
+}
+
+void OT_insert_left(void* operand, void* insertee){
+    struct OT_operand* oper = (struct OT_operand*)operand;
+    struct OT_operand* ins = (struct OT_operand*)insertee;
+
+    struct OT_operand* oper_prev = oper->OT_prev;
+
+    ins->OT_prev = oper->OT_prev;
+    ins->OT_next = operand;
+
+    oper_prev->OT_next = insertee;
+    oper->OT_prev = insertee;
+}
+
+void OT_insert_right(void* operand, void* insertee){
+    struct OT_operand* oper = (struct OT_operand*)operand;
+    struct OT_operand* ins = (struct OT_operand*)insertee;
+
+    struct OT_operand* oper_next = oper->OT_prev;
+
+    ins->OT_prev = operand;
+    ins->OT_next = oper->OT_prev;
+
+    oper->OT_next = insertee;
+    oper_next->OT_prev = insertee;
+}
+
+void OT_free(void* operand){
+    struct OT_operand* cur_oper = (struct OT_operand*)OT_get_first(operand);
+
+    while (cur_oper->OT_next){
+        cur_oper = (struct OT_operand*)(cur_oper->OT_next);
+        
+        free(cur_oper->OT_prev);
+    }
+}

+ 1 - 0
val

@@ -0,0 +1 @@
+valgrind --leak-check=full --track-origins=yes ./builds/main.bin