diff options
Diffstat (limited to 'comp/cw/code/tokenizer/ads')
-rw-r--r-- | comp/cw/code/tokenizer/ads/dict/Makefile | 4 | ||||
-rw-r--r-- | comp/cw/code/tokenizer/ads/dict/dict.c | 29 | ||||
-rw-r--r-- | comp/cw/code/tokenizer/ads/dict/dict.h | 9 | ||||
-rw-r--r-- | comp/cw/code/tokenizer/ads/dict/dict.o | bin | 0 -> 1768 bytes | |||
-rwxr-xr-x | comp/cw/code/tokenizer/ads/dict/dicttest | bin | 0 -> 20536 bytes | |||
-rw-r--r-- | comp/cw/code/tokenizer/ads/dict/dicttest.c | 10 | ||||
-rw-r--r-- | comp/cw/code/tokenizer/ads/dll/Makefile | 5 | ||||
-rw-r--r-- | comp/cw/code/tokenizer/ads/dll/dll.c | 62 | ||||
-rw-r--r-- | comp/cw/code/tokenizer/ads/dll/dll.h | 19 | ||||
-rw-r--r-- | comp/cw/code/tokenizer/ads/dll/dll.o | bin | 0 -> 2424 bytes | |||
-rwxr-xr-x | comp/cw/code/tokenizer/ads/dll/dlltest | bin | 0 -> 20640 bytes | |||
-rw-r--r-- | comp/cw/code/tokenizer/ads/dll/dlltest.c | 20 | ||||
-rw-r--r-- | comp/cw/code/tokenizer/ads/ll/Makefile | 5 | ||||
-rw-r--r-- | comp/cw/code/tokenizer/ads/ll/ll.c | 50 | ||||
-rw-r--r-- | comp/cw/code/tokenizer/ads/ll/ll.h | 15 | ||||
-rw-r--r-- | comp/cw/code/tokenizer/ads/ll/ll.o | bin | 0 -> 2184 bytes | |||
-rwxr-xr-x | comp/cw/code/tokenizer/ads/ll/lltest | bin | 0 -> 20592 bytes | |||
-rw-r--r-- | comp/cw/code/tokenizer/ads/ll/lltest.c | 18 |
18 files changed, 246 insertions, 0 deletions
diff --git a/comp/cw/code/tokenizer/ads/dict/Makefile b/comp/cw/code/tokenizer/ads/dict/Makefile new file mode 100644 index 0000000..f224267 --- /dev/null +++ b/comp/cw/code/tokenizer/ads/dict/Makefile @@ -0,0 +1,4 @@ +all: dict.c + cc dict.c -c -o dict.o +test: all + cc dict.o dicttest.c -o dicttest diff --git a/comp/cw/code/tokenizer/ads/dict/dict.c b/comp/cw/code/tokenizer/ads/dict/dict.c new file mode 100644 index 0000000..551afca --- /dev/null +++ b/comp/cw/code/tokenizer/ads/dict/dict.c @@ -0,0 +1,29 @@ +#include <stdlib.h> +#include <string.h> + +typedef struct dict_t { + int id; + void *data; +}dict_t; + +dict_t *dictalloc(){ + dict_t *output = malloc(sizeof(dict_t)); + return output; +} + +int dictset(dict_t *dict, int id, void *data){ + dict->id = id; + + dict->data = malloc(sizeof(data)); + if (dict->data == NULL) + return 1; + memcpy(dict->data, data, sizeof(data)); + + return 0; +} + +void dictfree(dict_t *dict){ + free(dict->data); + free(dict); +} + diff --git a/comp/cw/code/tokenizer/ads/dict/dict.h b/comp/cw/code/tokenizer/ads/dict/dict.h new file mode 100644 index 0000000..e6ab69d --- /dev/null +++ b/comp/cw/code/tokenizer/ads/dict/dict.h @@ -0,0 +1,9 @@ +typedef struct dict_t { + int id; + void *data; +}dict_t; + +dict_t *dictalloc(); +int dictset(dict_t *dict, int id, void *data); +void dictfree(dict_t *dict); + diff --git a/comp/cw/code/tokenizer/ads/dict/dict.o b/comp/cw/code/tokenizer/ads/dict/dict.o Binary files differnew file mode 100644 index 0000000..aefd77a --- /dev/null +++ b/comp/cw/code/tokenizer/ads/dict/dict.o diff --git a/comp/cw/code/tokenizer/ads/dict/dicttest b/comp/cw/code/tokenizer/ads/dict/dicttest Binary files differnew file mode 100755 index 0000000..dddf2a0 --- /dev/null +++ b/comp/cw/code/tokenizer/ads/dict/dicttest diff --git a/comp/cw/code/tokenizer/ads/dict/dicttest.c b/comp/cw/code/tokenizer/ads/dict/dicttest.c new file mode 100644 index 0000000..4a20870 --- /dev/null +++ b/comp/cw/code/tokenizer/ads/dict/dicttest.c @@ -0,0 +1,10 @@ +#include <stdio.h> + +#include "dict.h" + +int main(){ + dict_t *dict = dictalloc(); + dictset(dict, 1, "hello"); + printf("%d:%s\n", dict->id, (char *)dict->data); + dictfree(dict); +} diff --git a/comp/cw/code/tokenizer/ads/dll/Makefile b/comp/cw/code/tokenizer/ads/dll/Makefile new file mode 100644 index 0000000..651681d --- /dev/null +++ b/comp/cw/code/tokenizer/ads/dll/Makefile @@ -0,0 +1,5 @@ +all: dll.c + cc dll.c -c -o dll.o + +test: all + cc dll.o dlltest.c -o dlltest diff --git a/comp/cw/code/tokenizer/ads/dll/dll.c b/comp/cw/code/tokenizer/ads/dll/dll.c new file mode 100644 index 0000000..b24b13f --- /dev/null +++ b/comp/cw/code/tokenizer/ads/dll/dll.c @@ -0,0 +1,62 @@ +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +typedef struct dll_t dll_t; + +typedef struct dll_t { + void *data; + dll_t *next; + dll_t *prev; +} dll_t; + +dll_t *dllalloc(){ + dll_t *output = malloc(sizeof(dll_t)); + if (output == NULL) + return NULL; + output->next = NULL; + output->prev = NULL; + return output; +} + +void dllsetdata(dll_t *node, void *data){ + node->data = malloc(sizeof(data)); + memcpy(node->data, data, sizeof(data)); +} + +void dllsetnext(dll_t *node, dll_t *next){ + if (node->next == NULL) { + node->next = next; + node->next->prev = node; + } + else + dllsetnext(node->next, next); +} +void dllsetprev(dll_t *node, dll_t *prev){ + if (node->prev == NULL) { + node->prev = prev; + node->prev->next = node; + } + else + dllsetprev(node->prev, prev); +} + +void *dllgetat(dll_t *head, int index){ + if (index == 0) + return head->data; + else { + if (head->next != NULL) { + return dllgetat(head->next, index - 1); + }else { + return NULL; + } + } +} + +void dllfreeall(dll_t *head){ + if (head->next != NULL) + dllfreeall(head->next); + free(head->data); + free(head); +} + diff --git a/comp/cw/code/tokenizer/ads/dll/dll.h b/comp/cw/code/tokenizer/ads/dll/dll.h new file mode 100644 index 0000000..44940ce --- /dev/null +++ b/comp/cw/code/tokenizer/ads/dll/dll.h @@ -0,0 +1,19 @@ +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +typedef struct dll_t dll_t; + +typedef struct dll_t { + void *data; + dll_t *next; + dll_t *prev; +} dll_t; + +dll_t *dllalloc(); +void dllsetdata(dll_t *node, void *data); +void dllsetnext(dll_t *node, dll_t *next); +void dllsetprev(dll_t *node, dll_t *prev); +void *dllgetat(dll_t *head, int index); +void dllfreeall(dll_t *head); + diff --git a/comp/cw/code/tokenizer/ads/dll/dll.o b/comp/cw/code/tokenizer/ads/dll/dll.o Binary files differnew file mode 100644 index 0000000..2c9a145 --- /dev/null +++ b/comp/cw/code/tokenizer/ads/dll/dll.o diff --git a/comp/cw/code/tokenizer/ads/dll/dlltest b/comp/cw/code/tokenizer/ads/dll/dlltest Binary files differnew file mode 100755 index 0000000..83f900c --- /dev/null +++ b/comp/cw/code/tokenizer/ads/dll/dlltest diff --git a/comp/cw/code/tokenizer/ads/dll/dlltest.c b/comp/cw/code/tokenizer/ads/dll/dlltest.c new file mode 100644 index 0000000..4544d2e --- /dev/null +++ b/comp/cw/code/tokenizer/ads/dll/dlltest.c @@ -0,0 +1,20 @@ +#include <stdio.h> + +#include "dll.h" + +int main(){ + dll_t *head = dllalloc(); + dllsetdata(head, "hello"); + + for (int i = 0; i < 3; i++){ + dll_t *node = dllalloc(); + dllsetdata(node, "hi"); + dllsetnext(head, node); + } + + for (int i = 0; i < 4; i++) + printf("%s\n", (char *)dllgetat(head, i)); + printf("%s\n", (char *)head->prev->next->data); + + dllfreeall(head); +} diff --git a/comp/cw/code/tokenizer/ads/ll/Makefile b/comp/cw/code/tokenizer/ads/ll/Makefile new file mode 100644 index 0000000..aaf0241 --- /dev/null +++ b/comp/cw/code/tokenizer/ads/ll/Makefile @@ -0,0 +1,5 @@ +all: ll.c + cc ll.c -c -o ll.o + +test: all + cc ll.o lltest.c -o lltest diff --git a/comp/cw/code/tokenizer/ads/ll/ll.c b/comp/cw/code/tokenizer/ads/ll/ll.c new file mode 100644 index 0000000..c45ab0c --- /dev/null +++ b/comp/cw/code/tokenizer/ads/ll/ll.c @@ -0,0 +1,50 @@ +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +typedef struct ll_t ll_t; + +typedef struct ll_t { + void *data; + ll_t *next; +} ll_t; + +ll_t *llalloc(){ + ll_t *output = malloc(sizeof(ll_t)); + if (output == NULL) + return NULL; + output->next = NULL; + return output; +} + +void llsetdata(ll_t *node, void *data){ + node->data = malloc(sizeof(data)); + memcpy(node->data, data, sizeof(data)); +} + +void llsetnext(ll_t *node, ll_t *next){ + if (node->next == NULL) + node->next = next; + else + llsetnext(node->next, next); +} + +void *llgetat(ll_t *head, int index){ + if (index == 0) + return head->data; + else { + if (head->next != NULL) { + return llgetat(head->next, index - 1); + }else { + return NULL; + } + } +} + +void llfreeall(ll_t *head){ + if (head->next != NULL) + llfreeall(head->next); + free(head->data); + free(head); +} + diff --git a/comp/cw/code/tokenizer/ads/ll/ll.h b/comp/cw/code/tokenizer/ads/ll/ll.h new file mode 100644 index 0000000..30830b1 --- /dev/null +++ b/comp/cw/code/tokenizer/ads/ll/ll.h @@ -0,0 +1,15 @@ +#include <stdlib.h> +#include <string.h> + +typedef struct ll_t ll_t; + +typedef struct ll_t { + void *data; + ll_t *next; +} ll_t; + +ll_t *llalloc(); +void llsetdata(ll_t *node, void *data); +void llsetnext(ll_t *node, ll_t *next); +void *llgetat(ll_t *head, int index); +void llfreeall(ll_t *head); diff --git a/comp/cw/code/tokenizer/ads/ll/ll.o b/comp/cw/code/tokenizer/ads/ll/ll.o Binary files differnew file mode 100644 index 0000000..b033278 --- /dev/null +++ b/comp/cw/code/tokenizer/ads/ll/ll.o diff --git a/comp/cw/code/tokenizer/ads/ll/lltest b/comp/cw/code/tokenizer/ads/ll/lltest Binary files differnew file mode 100755 index 0000000..b98c5de --- /dev/null +++ b/comp/cw/code/tokenizer/ads/ll/lltest diff --git a/comp/cw/code/tokenizer/ads/ll/lltest.c b/comp/cw/code/tokenizer/ads/ll/lltest.c new file mode 100644 index 0000000..8aa6514 --- /dev/null +++ b/comp/cw/code/tokenizer/ads/ll/lltest.c @@ -0,0 +1,18 @@ +#include <stdio.h> + +#include "ll.h" + +int main(){ + ll_t *head = llalloc(); + llsetdata(head, "hello"); + + for (int i = 0; i < 3; i++){ + ll_t *node = llalloc(); + llsetdata(node, "hi"); + llsetnext(head, node); + } + for (int i = 0; i < 4; i++) + printf("%s\n", (char *)llgetat(head, i)); + + llfreeall(head); +} |