From 19e67acd4c715b4a90b1549e229a468bb0d1d7b1 Mon Sep 17 00:00:00 2001 From: Hizenberg Date: Mon, 5 Feb 2024 00:45:30 +0530 Subject: [PATCH] How to make library generic? --- ProgrammableLib/.Makefile.un~ | Bin 0 -> 523 bytes ProgrammableLib/.application.c.un~ | Bin 0 -> 1014 bytes ProgrammableLib/.dll.c.un~ | Bin 0 -> 1014 bytes ProgrammableLib/.dll.h.un~ | Bin 0 -> 1014 bytes ProgrammableLib/Makefile | 14 + ProgrammableLib/application.c | 200 +++++++++++++ .../comparison_callback/.Makefile.un~ | Bin 0 -> 523 bytes .../comparison_callback/.application.c.un~ | Bin 0 -> 5724 bytes .../comparison_callback/.dll.c.un~ | Bin 0 -> 1014 bytes .../comparison_callback/.dll.h.un~ | Bin 0 -> 1014 bytes ProgrammableLib/comparison_callback/Makefile | 14 + .../comparison_callback/application.c | 278 ++++++++++++++++++ .../comparison_callback/application.c~ | 278 ++++++++++++++++++ ProgrammableLib/comparison_callback/dll.c | 155 ++++++++++ ProgrammableLib/comparison_callback/dll.h | 55 ++++ ProgrammableLib/dll.c | 58 ++++ ProgrammableLib/dll.h | 41 +++ ProgrammableLib/search_callback/.Makefile.un~ | Bin 0 -> 523 bytes .../search_callback/.application.c.un~ | Bin 0 -> 1040 bytes ProgrammableLib/search_callback/.dll.c.un~ | Bin 0 -> 1014 bytes ProgrammableLib/search_callback/.dll.h.un~ | Bin 0 -> 1014 bytes ProgrammableLib/search_callback/Makefile | 14 + ProgrammableLib/search_callback/application.c | 228 ++++++++++++++ ProgrammableLib/search_callback/dll.c | 82 ++++++ ProgrammableLib/search_callback/dll.c~ | 82 ++++++ ProgrammableLib/search_callback/dll.h | 48 +++ 26 files changed, 1547 insertions(+) create mode 100644 ProgrammableLib/.Makefile.un~ create mode 100644 ProgrammableLib/.application.c.un~ create mode 100644 ProgrammableLib/.dll.c.un~ create mode 100644 ProgrammableLib/.dll.h.un~ create mode 100644 ProgrammableLib/Makefile create mode 100644 ProgrammableLib/application.c create mode 100644 ProgrammableLib/comparison_callback/.Makefile.un~ create mode 100644 ProgrammableLib/comparison_callback/.application.c.un~ create mode 100644 ProgrammableLib/comparison_callback/.dll.c.un~ create mode 100644 ProgrammableLib/comparison_callback/.dll.h.un~ create mode 100644 ProgrammableLib/comparison_callback/Makefile create mode 100644 ProgrammableLib/comparison_callback/application.c create mode 100644 ProgrammableLib/comparison_callback/application.c~ create mode 100644 ProgrammableLib/comparison_callback/dll.c create mode 100644 ProgrammableLib/comparison_callback/dll.h create mode 100644 ProgrammableLib/dll.c create mode 100644 ProgrammableLib/dll.h create mode 100644 ProgrammableLib/search_callback/.Makefile.un~ create mode 100644 ProgrammableLib/search_callback/.application.c.un~ create mode 100644 ProgrammableLib/search_callback/.dll.c.un~ create mode 100644 ProgrammableLib/search_callback/.dll.h.un~ create mode 100644 ProgrammableLib/search_callback/Makefile create mode 100644 ProgrammableLib/search_callback/application.c create mode 100644 ProgrammableLib/search_callback/dll.c create mode 100644 ProgrammableLib/search_callback/dll.c~ create mode 100644 ProgrammableLib/search_callback/dll.h diff --git a/ProgrammableLib/.Makefile.un~ b/ProgrammableLib/.Makefile.un~ new file mode 100644 index 0000000000000000000000000000000000000000..4cd81e58ba248e3d29d232e0748ed0646571998d GIT binary patch literal 523 zcmWH`%$*;a=aT=Ffhk0@dtpQZ`|qVm{(N-@;`*82y#3bqb#B6ss}ACC6`z&;7#J8% z05LLP1ag?50w5ZO8B+IOI>rK$Wn_p4X#@e7LJ%7w1!4ige;{CBhOkFTT7&>FI(CDj zgMs0z1keIjAZCYJ1d0k71uX?2a7isrF3Kz@$;{8QQc$pQ4h;(S53&R6fGP%4ARQ2M zz$}=QX(KqQQN)09plBC{sR2hdx(b-&C{2YB07msuXwCyioDh1MBm=0dmd;KUP!O8vjzpnV=9Mk!tp^cq|FT(g37#OU8 z7#T1EIZRLi5Dmi&srzrvVgboAGQ?j%QUGNFg+WqK@E-^mm|?t8n))FCjE*Vb=wM*@ zDgiW}6^PlP)_|fxMnOvf2wYN&lZ!G7N;32FtP~V%oI`_x{e$elI-rWd6gc9*qVOmL yiJLZpqZ&mFC=5yy!XSAN07o^t3W(GwNtF-)M)gc+&I3o05R$3jfH!S?z6t;ump1kQ literal 0 HcmV?d00001 diff --git a/ProgrammableLib/.dll.h.un~ b/ProgrammableLib/.dll.h.un~ new file mode 100644 index 0000000000000000000000000000000000000000..b31f0464eb62a36098e50db1fd90b50ddfb2d26d GIT binary patch literal 1014 zcmWH`%$*;a=aT=FfywyARO_n?E`B|+#7!U@U{QD! zg2YW5!BLGO1{4OR2_cX?2!Nv+T?IsHl%z@s0Hb;nH0Ob%ND#?XaKM{3K3@d@D)>1u literal 0 HcmV?d00001 diff --git a/ProgrammableLib/Makefile b/ProgrammableLib/Makefile new file mode 100644 index 0000000..e7b734e --- /dev/null +++ b/ProgrammableLib/Makefile @@ -0,0 +1,14 @@ +TARGET: exe +libdll.a: dll.o + ar rs libdll.a dll.o +dll.o: dll.c + gcc -c -I . dll.c -o dll.o +exe: application.o libdll.a + gcc application.o -o exe -L . -ldll +application.o: application.c + gcc -c -I . application.c -o application.o +clean: + rm *.o + rm libdll.a + rm exe + diff --git a/ProgrammableLib/application.c b/ProgrammableLib/application.c new file mode 100644 index 0000000..2bc6aab --- /dev/null +++ b/ProgrammableLib/application.c @@ -0,0 +1,200 @@ +/* + * ===================================================================================== + * + * Filename: application.c + * + * Description: + * + * Version: 1.0 + * Created: 04/02/24 11:38:59 PM IST + * Revision: none + * Compiler: gcc + * + * Author: YOUR NAME (), + * Organization: + * + * ===================================================================================== + */ + +#include "dll.h" +#include +#include +#include + +/*Application specific data structures*/ +typedef struct student_{ + + char name[32]; + int age; + int weight; + unsigned int rollno; +} student_t; + +static void +print_student_details(student_t *student){ + + printf("Name = %s\n", student->name); + printf("Age = %d\n", student->age); + printf("weight = %d\n", student->weight); + printf("rollno = %u\n", student->rollno); +} + +static void +print_student_db(dll_t *student_db) { + + if(!student_db || !student_db->head) return; + + dll_node_t *head = student_db->head; + student_t *data = NULL; + + while(head){ + data = head->data; + print_student_details(data); + head = head->right; + } +} + +/*Application specific data structures*/ +typedef struct employee_{ + + char name[32]; + char designation[32]; + unsigned int salary; + unsigned int emp_id; +} employee_t; + +static void +print_employee_details(employee_t *employee){ + + printf("Name = %s\n", employee->name); + printf("Designation = %s\n", employee->designation); + printf("salary = %u\n", employee->salary); + printf("emp_id = %u\n", employee->emp_id); +} + +static void +print_employee_db(dll_t *student_db) { + + if(!student_db || !student_db->head) return; + + dll_node_t *head = student_db->head; + student_t *data = NULL; + + while(head){ + data = head->data; + print_student_details(data); + head = head->right; + } +} + +/*Search function*/ + +student_t * +search_student_by_rollno(dll_t *student_db, + unsigned int rollno/*search key*/){ + + if(!student_db || !student_db->head) return NULL; + + dll_node_t *head = student_db->head; + student_t *data = NULL; + + while(head){ + data = head->data; + if(data->rollno == rollno) + return data; + head = head->right; + } +} + + +/*Search function*/ + +employee_t * +search_employee_by_emp_id(dll_t *employee_db, + unsigned int emp_id/*search key*/){ + + if(!employee_db || !employee_db->head) return NULL; + + dll_node_t *head = employee_db->head; + employee_t *data = NULL; + + while(head){ + data = head->data; + if(data->emp_id == emp_id) + return data; + head = head->right; + } +} + +int +main(int argc, char **argv){ + + /*Student database*/ + student_t *student1 = calloc(1, sizeof(student_t)); + strncpy(student1->name, "Abhishek", strlen("Abhishek")); + student1->age = 31; + student1->weight = 75; + student1->rollno = 800000; + + student_t *student2 = calloc(1, sizeof(student_t)); + strncpy(student2->name, "Joseph", strlen("Joseph")); + student2->age = 41; + student2->weight = 70; + student2->rollno = 800400; + + student_t *student3 = calloc(1, sizeof(student_t)); + strncpy(student3->name, "Jack", strlen("Jack")); + student3->age = 29; + student3->weight = 55; + student3->rollno = 800400; + + /*Create a new Linked List*/ + + dll_t *student_db = get_new_dll(); + add_data_to_dll(student_db, student1); + add_data_to_dll(student_db, student2); + add_data_to_dll(student_db, student3); + + student_t *student = search_student_by_rollno(student_db, 800400); + if(!student){ + printf("Student record not found\n"); + } + else{ + print_student_details(student); + } + + /*Employee database*/ + employee_t *employee1 = calloc(1, sizeof(employee_t)); + strncpy(employee1->name, "Harsh", strlen("Harsh")); + strncpy(employee1->designation, "Vice President", strlen("Vice President")); + employee1->salary = 11131; + employee1->emp_id = 10000; + + employee_t *employee2 = calloc(1, sizeof(employee_t)); + strncpy(employee2->name, "Huma", strlen("Huma")); + strncpy(employee2->designation, "CEO", strlen("CEO")); + employee1->salary = 127000; + employee1->emp_id = 10001; + + employee_t *employee3 = calloc(1, sizeof(employee_t)); + strncpy(employee3->name, "Neena", strlen("Neena")); + strncpy(employee2->designation, "Manager", strlen("Manager")); + employee1->salary = 139000; + employee1->emp_id = 10002; + + /*Create a new Linked List*/ + + dll_t *employee_db = get_new_dll(); + add_data_to_dll(employee_db, employee1); + add_data_to_dll(employee_db, employee2); + add_data_to_dll(employee_db, employee3); + + employee_t *employee = search_employee_by_emp_id(employee_db, 10002); + if(!employee){ + printf("Student record not found\n"); + } + else{ + print_employee_details(employee); + } + return 0; +} diff --git a/ProgrammableLib/comparison_callback/.Makefile.un~ b/ProgrammableLib/comparison_callback/.Makefile.un~ new file mode 100644 index 0000000000000000000000000000000000000000..a999418617fc15d642f4efffc4a26dcc0fe15893 GIT binary patch literal 523 zcmWH`%$*;a=aT=Ffr;fd^Wu#xg}W6RbWUFqStvAP`QIk>|Galzw`TgSf(wXkF+moqgx4te!Y+4ABl@#ki(_ag` zvh;(N^s4n$zbqGJidU!adK>d}{u3&fsl=$9qJqFSEW&GdCKG6li`9>4rHJ=7>J?2W zD*jN2k?_cEho1qj{ppe75aQQ4`uG!6M)hUDFe5Yg1?0VEso~dKel3`ja^Xf{dFAHv zHT4dCvf3y(ReMB;`q>AH8g(2K>}S!AP}F_z>eai~VP$}*cRBSG`(TxL%>R}4QG1lu*+J|WlbR{5o$rpy>(3m>$i&e30TR0N9~g#|$q(sHYWby!VXZ|G781qW(jT-X=ly>zlvm COiY*n literal 0 HcmV?d00001 diff --git a/ProgrammableLib/comparison_callback/.dll.c.un~ b/ProgrammableLib/comparison_callback/.dll.c.un~ new file mode 100644 index 0000000000000000000000000000000000000000..3ba8b9b5e6b684cea114d4771a8e12373b589c09 GIT binary patch literal 1014 zcmWH`%$*;a=aT=FfobRQGmB@{J(2WxW9E7-85Zxux!>Wte1)R^H1FS_6s(83io`AaF@7PAwqc-Q{adLi^8K2 yByQRWj%pM!pfD&+2!rH7036lmDj-s$BvnEH7}Xb{IS(8~LP(~91Kzap`6>X~@HKG& literal 0 HcmV?d00001 diff --git a/ProgrammableLib/comparison_callback/.dll.h.un~ b/ProgrammableLib/comparison_callback/.dll.h.un~ new file mode 100644 index 0000000000000000000000000000000000000000..5e05094b3aa6b905e77840ed3cfa18cfaa61e8c7 GIT binary patch literal 1014 zcmWH`%$*;a=aT=Ff$8+IB|jGJV*0eq?5Uc-4eKMOZ7c!*7R*h^u((%wIQ08c1_lOm zAVvm^Kn@dB07SzuL+bv!yI4T7j12J?kQ6|fKw*#+6#NGQ24)y@ zzDfX%X9Z$*s5PKykWtW500NiP;^d;tf|AVqJSznS8|ToVVE-UHunwqVFa?e{uqZqV zLE@&3;HX9s0}6xEgb+v`1i(>^t^y)8N>U{RfKj~@n)AR>B#2}xIN(hipRWP{K`S^x literal 0 HcmV?d00001 diff --git a/ProgrammableLib/comparison_callback/Makefile b/ProgrammableLib/comparison_callback/Makefile new file mode 100644 index 0000000..5d92dc0 --- /dev/null +++ b/ProgrammableLib/comparison_callback/Makefile @@ -0,0 +1,14 @@ +TARGET: exe +libdll.a: dll.o + ar rs libdll.a dll.o +dll.o: dll.c + gcc -g -c -I . dll.c -o dll.o +exe: application.o libdll.a + gcc -g application.o -o exe -L . -ldll +application.o: application.c + gcc -g -c -I . application.c -o application.o +clean: + rm *.o + rm libdll.a + rm exe + diff --git a/ProgrammableLib/comparison_callback/application.c b/ProgrammableLib/comparison_callback/application.c new file mode 100644 index 0000000..52c0442 --- /dev/null +++ b/ProgrammableLib/comparison_callback/application.c @@ -0,0 +1,278 @@ +/* + * ===================================================================================== + * + * Filename: application.c + * + * Description: + * + * Version: 1.0 + * Created: 05/02/24 12:25:12 AM IST + * Revision: none + * Compiler: gcc + * + * Author: YOUR NAME (), + * Organization: + * + * ===================================================================================== + */ + +#include "dll.h" +#include +#include +#include +#include + +/*Application specific data structures*/ +typedef struct student_{ + + char name[32]; + int age; + int weight; + unsigned int rollno; +} student_t; + +static void +print_student_details(student_t *student){ + + printf("Name = %s\n", student->name); + printf("Age = %d\n", student->age); + printf("weight = %d\n", student->weight); + printf("rollno = %u\n", student->rollno); +} + +static void +print_student_db(dll_t *student_db) { + + if(!student_db || !student_db->head) return; + + dll_node_t *head = student_db->head; + student_t *data = NULL; + + while(head){ + data = head->data; + print_student_details(data); + head = head->right; + } +} + +/*Application specific data structures*/ +typedef struct employee_{ + + char name[32]; + char designation[32]; + unsigned int salary; + unsigned int emp_id; +} employee_t; + +static void +print_employee_details(employee_t *employee){ + + printf("Name = %s\n", employee->name); + printf("Designation = %s\n", employee->designation); + printf("salary = %u\n", employee->salary); + printf("emp_id = %u\n", employee->emp_id); +} + +static void +print_employee_db(dll_t *student_db) { + + if(!student_db || !student_db->head) return; + + dll_node_t *head = student_db->head; + student_t *data = NULL; + + while(head){ + data = head->data; + print_student_details(data); + head = head->right; + } +} + +/*Search function*/ + +student_t * +search_student_by_rollno(dll_t *student_db, + unsigned int rollno/*search key*/){ + + if(!student_db || !student_db->head) return NULL; + + dll_node_t *head = student_db->head; + student_t *data = NULL; + + while(head){ + data = head->data; + if(data->rollno == rollno) + return data; + head = head->right; + } +} + + +/*Search function*/ + +employee_t * +search_employee_by_emp_id(dll_t *employee_db, + unsigned int emp_id/*search key*/){ + + if(!employee_db || !employee_db->head) return NULL; + + dll_node_t *head = employee_db->head; + employee_t *data = NULL; + + while(head){ + data = head->data; + if(data->emp_id == emp_id) + return data; + head = head->right; + } +} + +/*Search callbacks*/ +static int /*return 0 if matches, return -1 if do not match*/ +search_student_db_by_key(void *data, void *key){ + + student_t *student = (student_t *)data; + unsigned int rollno = *((unsigned int*)key); + if(student->rollno == rollno) + return 0; + return -1; +} + +/*Search callbacks*/ +static int /*return 0 if matches, return -1 if do not match*/ +search_employee_db_by_key(void *data, void *key){ + + employee_t *emp = (employee_t *)data; + unsigned int emp_id = *((unsigned int*)key); + if(emp->emp_id == emp_id) + return 0; + return -1; +} + +/*Comparion Callback*/ +/*Return 0 if equal, + * -1 if stud1 < stud2 + * 1 if stud1 > stud2*/ + +static int +student_comparison_fn(void *stud1, void *stud2){ + + /*Let us define the sorting order of students, + * Let us compare the students Alphabetically on their names + * If two students have same name, younger students should + * come before elder student + * If age is also same, lighter student comes before heavier + * if Weight is also same, students with numerically lesser rollno + * comes before in the DLL*/ + + student_t *student1 = (student_t *)stud1; + student_t *student2 = (student_t *)stud2; + + if(strncmp(student1->name, student2->name, 32) < 0) + return -1; + else if(strncmp(student1->name, student2->name, 32) > 0) + return 1; + else if(student1->age < student2->age) + return -1; + else if(student1->age > student2->age) + return 1; + else if(student1->weight < student2->weight) + return -1; + else if(student1->weight > student2->weight) + return 1; + else if(student1->rollno < student2->rollno) + return -1; + else if(student1->rollno > student2->rollno) + return 1; + assert(0); /*intentionally Crash the program !!*/ +} + +int +main(int argc, char **argv){ + + /*Student database*/ + student_t *student1 = calloc(1, sizeof(student_t)); + strncpy(student1->name, "Abhishek", strlen("Abhishek")); + student1->age = 31; + student1->weight = 75; + student1->rollno = 800000; + + student_t *student2 = calloc(1, sizeof(student_t)); + strncpy(student2->name, "Joseph", strlen("Joseph")); + student2->age = 41; + student2->weight = 70; + student2->rollno = 800400; + + student_t *student3 = calloc(1, sizeof(student_t)); + strncpy(student3->name, "Jack", strlen("Jack")); + student3->age = 29; + student3->weight = 55; + student3->rollno = 800400; + + student_t *student4 = calloc(1, sizeof(student_t)); + strncpy(student3->name, "Abhishek", strlen("Abhishek")); + student3->age = 29; + student3->weight = 55; + student3->rollno = 800399; + + /*Create a new Linked List*/ + + dll_t *student_db = get_new_dll(); + register_key_match_callback(student_db, search_student_db_by_key); + register_comparison_callback(student_db, student_comparison_fn); + dll_priority_insert_data(student_db, student1); + dll_priority_insert_data(student_db, student2); + dll_priority_insert_data(student_db, student3); +#if 0 + //student_t *student = search_student_by_rollno(student_db, 800400); + student_t *student = dll_search_by_key(student_db, (void *)800400); + if(!student){ + printf("Student record not found\n"); + } + else{ + print_student_details(student); + } +#endif + printf("Printing Stduents list\n"); + print_student_db(student_db); + +#if 0 + /*Employee database*/ + employee_t *employee1 = calloc(1, sizeof(employee_t)); + strncpy(employee1->name, "Harsh", strlen("Harsh")); + strncpy(employee1->designation, "Vice President", strlen("Vice President")); + employee1->salary = 11131; + employee1->emp_id = 10000; + + employee_t *employee2 = calloc(1, sizeof(employee_t)); + strncpy(employee2->name, "Huma", strlen("Huma")); + strncpy(employee2->designation, "CEO", strlen("CEO")); + employee1->salary = 127000; + employee1->emp_id = 10001; + + employee_t *employee3 = calloc(1, sizeof(employee_t)); + strncpy(employee3->name, "Neena", strlen("Neena")); + strncpy(employee2->designation, "Manager", strlen("Manager")); + employee1->salary = 139000; + employee1->emp_id = 10002; + + /*Create a new Linked List*/ + + dll_t *employee_db = get_new_dll(); + register_key_match_callback(employee_db, search_employee_db_by_key); + register_comparison_callback(employee_db, student_comparison_fn); + + add_data_to_dll(employee_db, employee1); + add_data_to_dll(employee_db, employee2); + add_data_to_dll(employee_db, employee3); + + employee_t *employee = dll_search_by_key(employee_db, (void *)10002); + if(!employee){ + printf("Student record not found\n"); + } + else{ + print_employee_details(employee); + } +#endif + return 0; +} diff --git a/ProgrammableLib/comparison_callback/application.c~ b/ProgrammableLib/comparison_callback/application.c~ new file mode 100644 index 0000000..2fa9959 --- /dev/null +++ b/ProgrammableLib/comparison_callback/application.c~ @@ -0,0 +1,278 @@ +/* + * ===================================================================================== + * + * Filename: application.c + * + * Description: + * + * Version: 1.0 + * Created: 05/02/24 12:25:12 AM IST + * Revision: none + * Compiler: gcc + * + * Author: YOUR NAME (), + * Organization: + * + * ===================================================================================== + */ + +#include "dll.h" +#include +#include +#include +#include + +/*Application specific data structures*/ +typedef struct student_{ + + char name[32]; + int age; + int weight; + unsigned int rollno; +} student_t; + +static void +print_student_details(student_t *student){ + + printf("Name = %s\n", student->name); + printf("Age = %d\n", student->age); + printf("weight = %d\n", student->weight); + printf("rollno = %u\n", student->rollno); +} + +static void +print_student_db(dll_t *student_db) { + + if(!student_db || !student_db->head) return; + + dll_node_t *head = student_db->head; + student_t *data = NULL; + + while(head){ + data = head->data; + print_student_details(data); + head = head->right; + } +} + +/*Application specific data structures*/ +typedef struct employee_{ + + char name[32]; + char designation[32]; + unsigned int salary; + unsigned int emp_id; +} employee_t; + +static void +print_employee_details(employee_t *employee){ + + printf("Name = %s\n", employee->name); + printf("Designation = %s\n", employee->designation); + printf("salary = %u\n", employee->salary); + printf("emp_id = %u\n", employee->emp_id); +} + +static void +print_employee_db(dll_t *student_db) { + + if(!student_db || !student_db->head) return; + + dll_node_t *head = student_db->head; + student_t *data = NULL; + + while(head){ + data = head->data; + print_student_details(data); + head = head->right; + } +} + +/*Search function*/ + +student_t * +search_student_by_rollno(dll_t *student_db, + unsigned int rollno/*search key*/){ + + if(!student_db || !student_db->head) return NULL; + + dll_node_t *head = student_db->head; + student_t *data = NULL; + + while(head){ + data = head->data; + if(data->rollno == rollno) + return data; + head = head->right; + } +} + + +/*Search function*/ + +employee_t * +search_employee_by_emp_id(dll_t *employee_db, + unsigned int emp_id/*search key*/){ + + if(!employee_db || !employee_db->head) return NULL; + + dll_node_t *head = employee_db->head; + employee_t *data = NULL; + + while(head){ + data = head->data; + if(data->emp_id == emp_id) + return data; + head = head->right; + } +} + +/*Search callbacks*/ +static int /*return 0 if matches, return -1 if do not match*/ +search_student_db_by_key(void *data, void *key){ + + student_t *student = (student_t *)data; + unsigned int rollno = (unsigned int)key; + if(student->rollno == rollno) + return 0; + return -1; +} + +/*Search callbacks*/ +static int /*return 0 if matches, return -1 if do not match*/ +search_employee_db_by_key(void *data, void *key){ + + employee_t *emp = (employee_t *)data; + unsigned int emp_id = (unsigned int)key; + if(emp->emp_id == emp_id) + return 0; + return -1; +} + +/*Comparion Callback*/ +/*Return 0 if equal, + * -1 if stud1 < stud2 + * 1 if stud1 > stud2*/ + +static int +student_comparison_fn(void *stud1, void *stud2){ + + /*Let us define the sorting order of students, + * Let us compare the students Alphabetically on their names + * If two students have same name, younger students should + * come before elder student + * If age is also same, lighter student comes before heavier + * if Weight is also same, students with numerically lesser rollno + * comes before in the DLL*/ + + student_t *student1 = (student_t *)stud1; + student_t *student2 = (student_t *)stud2; + + if(strncmp(student1->name, student2->name, 32) < 0) + return -1; + else if(strncmp(student1->name, student2->name, 32) > 0) + return 1; + else if(student1->age < student2->age) + return -1; + else if(student1->age > student2->age) + return 1; + else if(student1->weight < student2->weight) + return -1; + else if(student1->weight > student2->weight) + return 1; + else if(student1->rollno < student2->rollno) + return -1; + else if(student1->rollno > student2->rollno) + return 1; + assert(0); /*intentionally Crash the program !!*/ +} + +int +main(int argc, char **argv){ + + /*Student database*/ + student_t *student1 = calloc(1, sizeof(student_t)); + strncpy(student1->name, "Abhishek", strlen("Abhishek")); + student1->age = 31; + student1->weight = 75; + student1->rollno = 800000; + + student_t *student2 = calloc(1, sizeof(student_t)); + strncpy(student2->name, "Joseph", strlen("Joseph")); + student2->age = 41; + student2->weight = 70; + student2->rollno = 800400; + + student_t *student3 = calloc(1, sizeof(student_t)); + strncpy(student3->name, "Jack", strlen("Jack")); + student3->age = 29; + student3->weight = 55; + student3->rollno = 800400; + + student_t *student4 = calloc(1, sizeof(student_t)); + strncpy(student3->name, "Abhishek", strlen("Abhishek")); + student3->age = 29; + student3->weight = 55; + student3->rollno = 800399; + + /*Create a new Linked List*/ + + dll_t *student_db = get_new_dll(); + register_key_match_callback(student_db, search_student_db_by_key); + register_comparison_callback(student_db, student_comparison_fn); + dll_priority_insert_data(student_db, student1); + dll_priority_insert_data(student_db, student2); + dll_priority_insert_data(student_db, student3); +#if 0 + //student_t *student = search_student_by_rollno(student_db, 800400); + student_t *student = dll_search_by_key(student_db, (void *)800400); + if(!student){ + printf("Student record not found\n"); + } + else{ + print_student_details(student); + } +#endif + printf("Printing Stduents list\n"); + print_student_db(student_db); + +#if 0 + /*Employee database*/ + employee_t *employee1 = calloc(1, sizeof(employee_t)); + strncpy(employee1->name, "Harsh", strlen("Harsh")); + strncpy(employee1->designation, "Vice President", strlen("Vice President")); + employee1->salary = 11131; + employee1->emp_id = 10000; + + employee_t *employee2 = calloc(1, sizeof(employee_t)); + strncpy(employee2->name, "Huma", strlen("Huma")); + strncpy(employee2->designation, "CEO", strlen("CEO")); + employee1->salary = 127000; + employee1->emp_id = 10001; + + employee_t *employee3 = calloc(1, sizeof(employee_t)); + strncpy(employee3->name, "Neena", strlen("Neena")); + strncpy(employee2->designation, "Manager", strlen("Manager")); + employee1->salary = 139000; + employee1->emp_id = 10002; + + /*Create a new Linked List*/ + + dll_t *employee_db = get_new_dll(); + register_key_match_callback(employee_db, search_employee_db_by_key); + register_comparison_callback(employee_db, student_comparison_fn); + + add_data_to_dll(employee_db, employee1); + add_data_to_dll(employee_db, employee2); + add_data_to_dll(employee_db, employee3); + + employee_t *employee = dll_search_by_key(employee_db, (void *)10002); + if(!employee){ + printf("Student record not found\n"); + } + else{ + print_employee_details(employee); + } +#endif + return 0; +} diff --git a/ProgrammableLib/comparison_callback/dll.c b/ProgrammableLib/comparison_callback/dll.c new file mode 100644 index 0000000..4a9b457 --- /dev/null +++ b/ProgrammableLib/comparison_callback/dll.c @@ -0,0 +1,155 @@ +/* + * ===================================================================================== + * + * Filename: dll.c + * + * Description: + * + * Version: 1.0 + * Created: 05/02/24 12:26:05 AM IST + * Revision: none + * Compiler: gcc + * + * Author: YOUR NAME (), + * Organization: + * + * ===================================================================================== + */ + +#include "dll.h" +#include +#include + +/* Public Function Implementation to create and return + * new empty doubly linked list*/ + +dll_t * +get_new_dll(){ + + dll_t *dll = calloc(1, sizeof(dll_t)); + dll->head = NULL; + dll->key_match = NULL; + return dll; +} + +void +register_key_match_callback(dll_t *dll, + int (*key_match)(void *, void *)){ + + dll->key_match = key_match; +} + +void +register_comparison_callback(dll_t *dll, + int (*comparison_cb)(void *, void *)){ + + dll->comparison_fn = comparison_cb; +} + +/*Generic Search function*/ +void * +dll_search_by_key (dll_t *dll, void *key){ + + if(!dll || !dll->head) return NULL; + + dll_node_t *head = dll->head; + + while(head){ + if(dll->key_match(head->data, key) == 0) + return (void *)head->data; + head = head->right; + } + return NULL; +} + +/*Return 0 - on success + * -1 on Failure*/ +int +dll_priority_insert_data (dll_t *dll, void *data){ + + if(!dll) + return -1; + + /*if DLL is empty*/ + if(!dll->head){ + add_data_to_dll(dll, data); + return 0; + } + + dll_node_t *data_node = calloc(1, sizeof(dll_node_t)); + data_node->data = data; + data_node->left = NULL; + data_node->right = NULL; + + /* if there is only one node in DLL*/ + if(dll->head && !dll->head->right){ + if(dll->comparison_fn(dll->head->data, data) == -1){ + dll->head->right = data_node; + data_node->left = dll->head; + } + else{ + dll->head->left = data_node; + data_node->right = dll->head; + dll->head = data_node; + } + return 0; + } + + /*if More than one node in DLL*/ + if(dll->comparison_fn(data, dll->head->data) == -1){ + data_node->right = dll->head; + dll->head->left = data_node; + dll->head = data_node; + return 0; + } + + dll_node_t *prev = NULL, + *curr = NULL; + + curr = dll->head; + + while(curr){ + if(dll->comparison_fn(data, curr->data) != -1){ + prev = curr; + curr = curr->right; + continue; + } + + prev->right = data_node; + data_node->left = prev; + data_node->right = curr; + curr->left = data_node; + return 0; + } + + /*Add in the end*/ + prev->right = data_node; + data_node->left = prev; + return 0; +} + +/* Public Function Implementation to add a new application + * * data to DLL */ +int +add_data_to_dll (dll_t *dll, void *app_data){ + + if(!dll || !app_data) return -1; + + dll_node_t *dll_new_node = calloc(1, sizeof(dll_node_t)); + dll_new_node->left = NULL; + dll_new_node->right = NULL; + dll_new_node->data = app_data; + + /*Now add this to the front of DLL*/ + if(!dll->head){ + dll->head = dll_new_node; + return 0; + } + + dll_node_t *first_node = dll->head; + dll_new_node->right = first_node; + first_node->left = dll_new_node; + dll->head = dll_new_node; + return 0; +} + diff --git a/ProgrammableLib/comparison_callback/dll.h b/ProgrammableLib/comparison_callback/dll.h new file mode 100644 index 0000000..8b5ba7f --- /dev/null +++ b/ProgrammableLib/comparison_callback/dll.h @@ -0,0 +1,55 @@ +/* + * ===================================================================================== + * + * Filename: dll.h + * + * Description: + * + * Version: 1.0 + * Created: 05/02/24 12:25:44 AM IST + * Revision: none + * Compiler: gcc + * + * Author: YOUR NAME (), + * Organization: + * + * ===================================================================================== + */ + +/*Header file for Doubly Linked List*/ + +typedef struct dll_node_{ + + void *data; + struct dll_node_ *left; + struct dll_node_ *right; +} dll_node_t; + +typedef struct dll_{ + dll_node_t *head; + int (*key_match)(void *, void *); + int (*comparison_fn)(void *, void *); +} dll_t; + +void +register_key_match_callback(dll_t *dll, int (*key_match)(void *, void *)); + +void +register_comparison_callback(dll_t *dll, int (*comparison_cb)(void *, void *)); + +/*Generic Search function*/ +void * +dll_search_by_key (dll_t *dll, void *key); + +int +dll_priority_insert_data (dll_t *dll, void *data); + +/* Public Function declaration to create and return + * a new empty doubly linked list*/ +dll_t * +get_new_dll(); + +/* Public Function declaration to add the appication + * data to DLL*/ +int +add_data_to_dll(dll_t *dll, void *appn_data); diff --git a/ProgrammableLib/dll.c b/ProgrammableLib/dll.c new file mode 100644 index 0000000..0b61fbb --- /dev/null +++ b/ProgrammableLib/dll.c @@ -0,0 +1,58 @@ +/* + * ===================================================================================== + * + * Filename: dll.c + * + * Description: + * + * Version: 1.0 + * Created: 05/02/24 12:08:12 AM IST + * Revision: none + * Compiler: gcc + * + * Author: YOUR NAME (), + * Organization: + * + * ===================================================================================== + */ + +#include "dll.h" +#include +#include + +/* Public Function Implementation to create and return + * new empty doubly linked list*/ + +dll_t * +get_new_dll(){ + + dll_t *dll = calloc(1, sizeof(dll_t)); + dll->head = NULL; + return dll; +} + +/* Public Function Implementation to add a new application + * * data to DLL */ +int +add_data_to_dll (dll_t *dll, void *app_data){ + + if(!dll || !app_data) return -1; + + dll_node_t *dll_new_node = calloc(1, sizeof(dll_node_t)); + dll_new_node->left = NULL; + dll_new_node->right = NULL; + dll_new_node->data = app_data; + + /*Now add this to the front of DLL*/ + if(!dll->head){ + dll->head = dll_new_node; + return 0; + } + + dll_node_t *first_node = dll->head; + dll_new_node->right = first_node; + first_node->left = dll_new_node; + dll->head = dll_new_node; + return 0; +} + diff --git a/ProgrammableLib/dll.h b/ProgrammableLib/dll.h new file mode 100644 index 0000000..4df53e4 --- /dev/null +++ b/ProgrammableLib/dll.h @@ -0,0 +1,41 @@ +/* + * ===================================================================================== + * + * Filename: dll.h + * + * Description: + * + * Version: 1.0 + * Created: 05/02/24 12:08:34 AM IST + * Revision: none + * Compiler: gcc + * + * Author: YOUR NAME (), + * Organization: + * + * ===================================================================================== + */ + +/*Header file for Doubly Linked List*/ + +typedef struct dll_node_{ + + void *data; + struct dll_node_ *left; + struct dll_node_ *right; +} dll_node_t; + +typedef struct dll_{ + dll_node_t *head; +} dll_t; + + +/* Public Function declaration to create and return + * a new empty doubly linked list*/ +dll_t * +get_new_dll(); + +/* Public Function declaration to add the appication + * data to DLL*/ +int +add_data_to_dll(dll_t *dll, void *appn_data); diff --git a/ProgrammableLib/search_callback/.Makefile.un~ b/ProgrammableLib/search_callback/.Makefile.un~ new file mode 100644 index 0000000000000000000000000000000000000000..fb8d888ecfd15e11ede11cccb502a2aae4723530 GIT binary patch literal 523 zcmWH`%$*;a=aT=Ffr;fd^Wu#xg}W6RbWUFqStvAP`QIk>|GalzV5cV({Pq=SA83=B_z z7#T1EIZRLi5Dmi&srzsKVgboAGQ?j%QUGNFg+WqK@E-^mm|?t8n))FCjE*nh=wM*@ zDgiW}6^PlP)_|fxMnOvf2wYN&lZ!G7N;32FtP~V%oI`_x{e$elI-rWd6gc9*qVOmL ziJLZpqZ&mFC=5yy!XSAN07o^t3W(GwNtF-)M)gl<&I3o0Ad;!DtO`j4LP#>;C^2n( Gz6t;%_cn|G literal 0 HcmV?d00001 diff --git a/ProgrammableLib/search_callback/.dll.c.un~ b/ProgrammableLib/search_callback/.dll.c.un~ new file mode 100644 index 0000000000000000000000000000000000000000..370f0fe914e3978b06b913617f45c8de5263ca87 GIT binary patch literal 1014 zcmWH`%$*;a=aT=Ffyw^B5p^jC>mrGv=o5ACAB!YD6^m>Ge6HtLBYm3G$`0V$PTOnsu)axBMvMIk3x{R wX(KqQQN)14pfn*2k_Q2BRHLhaNR5(I2?1bK3qo@qIEsXjOa%wLY2))%0FkIOI{*Lx literal 0 HcmV?d00001 diff --git a/ProgrammableLib/search_callback/.dll.h.un~ b/ProgrammableLib/search_callback/.dll.h.un~ new file mode 100644 index 0000000000000000000000000000000000000000..ad5156b85865c5fd140b7f2f08777808c9ee2d58 GIT binary patch literal 1014 zcmWH`%$*;a=aT=FfvLX9ZvN^w7uNiECy||%8NL2OV<^|IYqOV}n5LHH78RGqz`$St z#K?dV$YFvCfM^(INZo%+g9RkZ$Pj-4Ndc4z6b4B_!G9oNV21HVY3hdnFgoPH(ZRs* zRRU-{D-g3otpP=YjDnT|5V)ikCl_TFlw{`TSt%&kIEMxW`v=*9bwCw^DR9JrMd48h y5;tuGM>UEVP#BaZgh28j0FG*O6%eUWk}4qpjB0gg&I3o0Ad;!zfH!S?z6t<}f;Hp- literal 0 HcmV?d00001 diff --git a/ProgrammableLib/search_callback/Makefile b/ProgrammableLib/search_callback/Makefile new file mode 100644 index 0000000..5d92dc0 --- /dev/null +++ b/ProgrammableLib/search_callback/Makefile @@ -0,0 +1,14 @@ +TARGET: exe +libdll.a: dll.o + ar rs libdll.a dll.o +dll.o: dll.c + gcc -g -c -I . dll.c -o dll.o +exe: application.o libdll.a + gcc -g application.o -o exe -L . -ldll +application.o: application.c + gcc -g -c -I . application.c -o application.o +clean: + rm *.o + rm libdll.a + rm exe + diff --git a/ProgrammableLib/search_callback/application.c b/ProgrammableLib/search_callback/application.c new file mode 100644 index 0000000..6d28c47 --- /dev/null +++ b/ProgrammableLib/search_callback/application.c @@ -0,0 +1,228 @@ +/* + * ===================================================================================== + * + * Filename: application.c + * + * Description: + * + * Version: 1.0 + * Created: 05/02/24 12:09:48 AM IST + * Revision: none + * Compiler: gcc + * + * Author: YOUR NAME (), + * Organization: + * + * ===================================================================================== + */ + +#include "dll.h" +#include +#include +#include + +/*Application specific data structures*/ +typedef struct student_{ + + char name[32]; + int age; + int weight; + unsigned int rollno; +} student_t; + +static void +print_student_details(student_t *student){ + + printf("Name = %s\n", student->name); + printf("Age = %d\n", student->age); + printf("weight = %d\n", student->weight); + printf("rollno = %u\n", student->rollno); +} + +static void +print_student_db(dll_t *student_db) { + + if(!student_db || !student_db->head) return; + + dll_node_t *head = student_db->head; + student_t *data = NULL; + + while(head){ + data = head->data; + print_student_details(data); + head = head->right; + } +} + +/*Application specific data structures*/ +typedef struct employee_{ + + char name[32]; + char designation[32]; + unsigned int salary; + unsigned int emp_id; +} employee_t; + +static void +print_employee_details(employee_t *employee){ + + printf("Name = %s\n", employee->name); + printf("Designation = %s\n", employee->designation); + printf("salary = %u\n", employee->salary); + printf("emp_id = %u\n", employee->emp_id); +} + +static void +print_employee_db(dll_t *student_db) { + + if(!student_db || !student_db->head) return; + + dll_node_t *head = student_db->head; + student_t *data = NULL; + + while(head){ + data = head->data; + print_student_details(data); + head = head->right; + } +} + +/*Search function*/ + +student_t * +search_student_by_rollno(dll_t *student_db, + unsigned int rollno/*search key*/){ + + if(!student_db || !student_db->head) return NULL; + + dll_node_t *head = student_db->head; + student_t *data = NULL; + + while(head){ + data = head->data; + if(data->rollno == rollno) + return data; + head = head->right; + } +} + + +/*Search function*/ + +employee_t * +search_employee_by_emp_id(dll_t *employee_db, + unsigned int emp_id/*search key*/){ + + if(!employee_db || !employee_db->head) return NULL; + + dll_node_t *head = employee_db->head; + employee_t *data = NULL; + + while(head){ + data = head->data; + if(data->emp_id == emp_id) + return data; + head = head->right; + } +} + +/*Search callbacks*/ +static int /*return 0 if matches, return -1 if do not match*/ +search_student_db_by_key(void *data, void *key){ + + student_t *student = (student_t *)data; + unsigned int rollno = (unsigned int)key; + if(student->rollno == rollno) + return 0; + return -1; +} + +/*Search callbacks*/ +static int /*return 0 if matches, return -1 if do not match*/ +search_employee_db_by_key(void *data, void *key){ + + employee_t *emp = (employee_t *)data; + unsigned int emp_id = (unsigned int)key; + if(emp->emp_id == emp_id) + return 0; + return -1; +} + + + +int +main(int argc, char **argv){ + + /*Student database*/ + student_t *student1 = calloc(1, sizeof(student_t)); + strncpy(student1->name, "Abhishek", strlen("Abhishek")); + student1->age = 31; + student1->weight = 75; + student1->rollno = 800000; + + student_t *student2 = calloc(1, sizeof(student_t)); + strncpy(student2->name, "Joseph", strlen("Joseph")); + student2->age = 41; + student2->weight = 70; + student2->rollno = 800400; + + student_t *student3 = calloc(1, sizeof(student_t)); + strncpy(student3->name, "Jack", strlen("Jack")); + student3->age = 29; + student3->weight = 55; + student3->rollno = 800400; + + /*Create a new Linked List*/ + + dll_t *student_db = get_new_dll(); + register_key_match_callback(student_db, search_student_db_by_key); + add_data_to_dll(student_db, student1); + add_data_to_dll(student_db, student2); + add_data_to_dll(student_db, student3); + + //student_t *student = search_student_by_rollno(student_db, 800400); + student_t *student = dll_search_by_key(student_db, (void *)800400); + if(!student){ + printf("Student record not found\n"); + } + else{ + print_student_details(student); + } + + /*Employee database*/ + employee_t *employee1 = calloc(1, sizeof(employee_t)); + strncpy(employee1->name, "Harsh", strlen("Harsh")); + strncpy(employee1->designation, "Vice President", strlen("Vice President")); + employee1->salary = 11131; + employee1->emp_id = 10000; + + employee_t *employee2 = calloc(1, sizeof(employee_t)); + strncpy(employee2->name, "Huma", strlen("Huma")); + strncpy(employee2->designation, "CEO", strlen("CEO")); + employee1->salary = 127000; + employee1->emp_id = 10001; + + employee_t *employee3 = calloc(1, sizeof(employee_t)); + strncpy(employee3->name, "Neena", strlen("Neena")); + strncpy(employee2->designation, "Manager", strlen("Manager")); + employee1->salary = 139000; + employee1->emp_id = 10002; + + /*Create a new Linked List*/ + + dll_t *employee_db = get_new_dll(); + register_key_match_callback(employee_db, search_employee_db_by_key); + add_data_to_dll(employee_db, employee1); + add_data_to_dll(employee_db, employee2); + add_data_to_dll(employee_db, employee3); + + //employee_t *employee = search_employee_by_emp_id(employee_db, 10002); + employee_t *employee = dll_search_by_key(employee_db, (void *)10002); + if(!employee){ + printf("Student record not found\n"); + } + else{ + print_employee_details(employee); + } + return 0; +} diff --git a/ProgrammableLib/search_callback/dll.c b/ProgrammableLib/search_callback/dll.c new file mode 100644 index 0000000..cb2dd47 --- /dev/null +++ b/ProgrammableLib/search_callback/dll.c @@ -0,0 +1,82 @@ +/* + * ===================================================================================== + * + * Filename: dll.c + * + * Description: + * + * Version: 1.0 + * Created: 05/02/24 12:10:09 AM IST + * Revision: none + * Compiler: gcc + * + * Author: YOUR NAME (), + * Organization: + * + * ===================================================================================== + */ + +#include "dll.h" +#include +#include + +/* Public Function Implementation to create and return + * new empty doubly linked list*/ + +dll_t * +get_new_dll(){ + + dll_t *dll = calloc(1, sizeof(dll_t)); + dll->head = NULL; + dll->key_match = NULL; + return dll; +} + +void +register_key_match_callback(dll_t *dll, + int (*key_match)(void *, void *)){ + + dll->key_match = key_match; +} + +/*Generic Search function*/ +void * +dll_search_by_key (dll_t *dll, void *key){ + + if(!dll || !dll->head) return NULL; + + dll_node_t *head = dll->head; + + while(head){ + if(dll->key_match(head->data, key) == 0) + return (void *)head->data; + head = head->right; + } + return NULL; +} + +/* Public Function Implementation to add a new application + * * data to DLL */ +int +add_data_to_dll (dll_t *dll, void *app_data){ + + if(!dll || !app_data) return -1; + + dll_node_t *dll_new_node = calloc(1, sizeof(dll_node_t)); + dll_new_node->left = NULL; + dll_new_node->right = NULL; + dll_new_node->data = app_data; + + /*Now add this to the front of DLL*/ + if(!dll->head){ + dll->head = dll_new_node; + return 0; + } + + dll_node_t *first_node = dll->head; + dll_new_node->right = first_node; + first_node->left = dll_new_node; + dll->head = dll_new_node; + return 0; +} + diff --git a/ProgrammableLib/search_callback/dll.c~ b/ProgrammableLib/search_callback/dll.c~ new file mode 100644 index 0000000..cb2dd47 --- /dev/null +++ b/ProgrammableLib/search_callback/dll.c~ @@ -0,0 +1,82 @@ +/* + * ===================================================================================== + * + * Filename: dll.c + * + * Description: + * + * Version: 1.0 + * Created: 05/02/24 12:10:09 AM IST + * Revision: none + * Compiler: gcc + * + * Author: YOUR NAME (), + * Organization: + * + * ===================================================================================== + */ + +#include "dll.h" +#include +#include + +/* Public Function Implementation to create and return + * new empty doubly linked list*/ + +dll_t * +get_new_dll(){ + + dll_t *dll = calloc(1, sizeof(dll_t)); + dll->head = NULL; + dll->key_match = NULL; + return dll; +} + +void +register_key_match_callback(dll_t *dll, + int (*key_match)(void *, void *)){ + + dll->key_match = key_match; +} + +/*Generic Search function*/ +void * +dll_search_by_key (dll_t *dll, void *key){ + + if(!dll || !dll->head) return NULL; + + dll_node_t *head = dll->head; + + while(head){ + if(dll->key_match(head->data, key) == 0) + return (void *)head->data; + head = head->right; + } + return NULL; +} + +/* Public Function Implementation to add a new application + * * data to DLL */ +int +add_data_to_dll (dll_t *dll, void *app_data){ + + if(!dll || !app_data) return -1; + + dll_node_t *dll_new_node = calloc(1, sizeof(dll_node_t)); + dll_new_node->left = NULL; + dll_new_node->right = NULL; + dll_new_node->data = app_data; + + /*Now add this to the front of DLL*/ + if(!dll->head){ + dll->head = dll_new_node; + return 0; + } + + dll_node_t *first_node = dll->head; + dll_new_node->right = first_node; + first_node->left = dll_new_node; + dll->head = dll_new_node; + return 0; +} + diff --git a/ProgrammableLib/search_callback/dll.h b/ProgrammableLib/search_callback/dll.h new file mode 100644 index 0000000..012957e --- /dev/null +++ b/ProgrammableLib/search_callback/dll.h @@ -0,0 +1,48 @@ +/* + * ===================================================================================== + * + * Filename: dll.h + * + * Description: + * + * Version: 1.0 + * Created: 05/02/24 12:10:31 AM IST + * Revision: none + * Compiler: gcc + * + * Author: YOUR NAME (), + * Organization: + * + * ===================================================================================== + */ + +/*Header file for Doubly Linked List*/ + +typedef struct dll_node_{ + + void *data; + struct dll_node_ *left; + struct dll_node_ *right; +} dll_node_t; + +typedef struct dll_{ + dll_node_t *head; + int (*key_match)(void *, void *); +} dll_t; + +void +register_key_match_callback(dll_t *dll, int (*key_match)(void *, void *)); + +/*Generic Search function*/ +void * +dll_search_by_key (dll_t *dll, void *key); + +/* Public Function declaration to create and return + * a new empty doubly linked list*/ +dll_t * +get_new_dll(); + +/* Public Function declaration to add the appication + * data to DLL*/ +int +add_data_to_dll(dll_t *dll, void *appn_data);