Skip to content

Commit

Permalink
Merge pull request #24 from Garz4/main
Browse files Browse the repository at this point in the history
Update data structures
  • Loading branch information
urielgarciarivas authored Mar 15, 2024
2 parents 25d77af + 505cac5 commit c4242a1
Show file tree
Hide file tree
Showing 13 changed files with 125 additions and 44 deletions.
11 changes: 9 additions & 2 deletions DataStructures/inc/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,15 @@
#ifndef __ZNG_ARRAY_H__
#define __ZNG_ARRAY_H__

struct array {
#include <stddef.h>

};
typedef struct __zng_array {
int* data;
size_t size;
} array;

extern array* new_array(int value);

extern void delete_array(array* arr);

#endif // __ZNG_ARRAY_H__
2 changes: 2 additions & 0 deletions DataStructures/inc/hash_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@
#ifndef __ZNG_HASH_MAP_H__
#define __ZNG_HASH_MAP_H__

#include <stdio.h>

#endif // __ZNG_HASH_MAP_H__
2 changes: 2 additions & 0 deletions DataStructures/inc/hash_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@
#ifndef __ZNG_HASH_SET_H__
#define __ZNG_HASH_SET_H__

#include <stdio.h>

#endif // __ZNG_HASH_SET_H__
2 changes: 2 additions & 0 deletions DataStructures/inc/sort_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@
#ifndef __ZNG_SORT_MAP_H__
#define __ZNG_SORT_MAP_H__

#include <stdio.h>

#endif // __ZNG_SORT_MAP_H__
13 changes: 8 additions & 5 deletions DataStructures/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@

CC = gcc
CFLAGS = -Wall -Werror -Wpedantic -I./inc/
INC = ./inc/linked_list.h ./inc/sort_set.h
INC = ./inc/array.h ./inc/hash_map.h ./inc/hash_set.h ./inc/linked_list.h ./inc/sort_map.h ./inc/sort_set.h
SRC = $(patsubst ./inc/%.h,./src/%.c,$(INC))
OBJ = $(patsubst ./inc/%.h,./obj/%.o,$(INC))

all: test
test: hash_map_test hash_set_test linked_list_test sort_map_test sort_set_test
( ./hash_map_test && ./hash_set_test && ./linked_list_test \
test: array_test hash_map_test hash_set_test linked_list_test sort_map_test sort_set_test
( ./array_test && ./hash_map_test && ./hash_set_test && ./linked_list_test \
&& ./sort_map_test && ./sort_set_test ) ; make clean

./obj/%.o: ./src/%.c
$(CC) $(CFLAGS) -c $^ -o $@

linked_list_test: test/linked_list_test.c $(OBJ)
array_test: test/array_test.c $(OBJ)
$(CC) $(CFLAGS) $(INC) $< -o $@ $(OBJ)

hash_map_test: test/hash_map_test.c $(OBJ)
Expand All @@ -37,14 +37,17 @@ hash_map_test: test/hash_map_test.c $(OBJ)
hash_set_test: test/hash_set_test.c $(OBJ)
$(CC) $(CFLAGS) $(INC) $< -o $@ $(OBJ)

linked_list_test: test/linked_list_test.c $(OBJ)
$(CC) $(CFLAGS) $(INC) $< -o $@ $(OBJ)

sort_map_test: test/sort_map_test.c $(OBJ)
$(CC) $(CFLAGS) $(INC) $< -o $@ $(OBJ)

sort_set_test: test/sort_set_test.c $(OBJ)
$(CC) $(CFLAGS) $(INC) $< -o $@ $(OBJ)

clean:
rm linked_list_test hash_map_test hash_set_test sort_map_test \
rm array_test hash_map_test hash_set_test linked_list_test sort_map_test \
sort_set_test $(OBJ)

# $(wildcard *.o)
20 changes: 20 additions & 0 deletions DataStructures/src/array.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* MIT License
*
* Copyright (c) 2024 Uriel Rivas
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* https://github.com/zoningorg/zoning/blob/main/LICENSE
*/

#include "../inc/array.h"

20 changes: 20 additions & 0 deletions DataStructures/src/hash_map.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* MIT License
*
* Copyright (c) 2024 Uriel Rivas
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* https://github.com/zoningorg/zoning/blob/main/LICENSE
*/

#include "../inc/hash_map.h"

20 changes: 20 additions & 0 deletions DataStructures/src/hash_set.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* MIT License
*
* Copyright (c) 2024 Uriel Rivas
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* https://github.com/zoningorg/zoning/blob/main/LICENSE
*/

#include "../inc/hash_set.h"

39 changes: 13 additions & 26 deletions DataStructures/src/linked_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
#include "../inc/linked_list.h"
#include "../inc/memory.h"

inline linked_list*
new_linked_list(int value) {
inline linked_list* new_linked_list(int value) {
linked_list* response;

ALLOCATE(linked_list, response);
Expand All @@ -37,8 +36,7 @@ new_linked_list(int value) {
return response;
}

void
print_linked_list(const linked_list*const list) {
void print_linked_list(const linked_list*const list) {
if (list == NULL) {
printf("list = {};\n");
return;
Expand All @@ -59,8 +57,7 @@ print_linked_list(const linked_list*const list) {
printf("};\n");
}

bool
exist_in_linked_list(const linked_list*const list, int value) {
bool exist_in_linked_list(const linked_list*const list, int value) {
if (list == NULL) {
return false;
}
Expand All @@ -79,8 +76,7 @@ exist_in_linked_list(const linked_list*const list, int value) {
}

// TODO(Garz4): Fix edge case when list is not NULL, but its head and tail are.
inline void
add_to_linked_list(linked_list*const list, int value) {
inline void add_to_linked_list(linked_list*const list, int value) {
if (list == NULL) {
return;
}
Expand All @@ -92,8 +88,7 @@ add_to_linked_list(linked_list*const list, int value) {
list->size++;
}

void
delete_linked_list(linked_list* list) {
void delete_linked_list(linked_list* list) {
if (list == NULL || list->head == NULL) {
return;
}
Expand All @@ -112,8 +107,7 @@ delete_linked_list(linked_list* list) {
DEALLOCATE(list);
}

void
erase_single_match_linked_list(linked_list* list, int target) {
void erase_single_match_linked_list(linked_list* list, int target) {
if (list == NULL || list->head == NULL) {
return;
}
Expand Down Expand Up @@ -147,13 +141,9 @@ erase_single_match_linked_list(linked_list* list, int target) {
}
}

void
erase_all_match_linked_list(linked_list* list, int target) {
void erase_all_match_linked_list(linked_list* list, int target) {}

}

void
reverse_linked_list(linked_list*const list) {
void reverse_linked_list(linked_list*const list) {
if (list == NULL) {
return;
}
Expand All @@ -174,8 +164,7 @@ reverse_linked_list(linked_list*const list) {
list->tail = current;
}

linked_list*
copy_linked_list(const linked_list*const list) {
linked_list* copy_linked_list(const linked_list*const list) {
if (list == NULL || list->head == NULL) {
return NULL;
}
Expand All @@ -191,8 +180,8 @@ copy_linked_list(const linked_list*const list) {
return copy;
}

bool
equal_linked_list(const linked_list*const lhs, const linked_list*const rhs) {
bool equal_linked_list(
const linked_list*const lhs, const linked_list*const rhs) {
if (lhs == NULL && rhs == NULL) {
return true;
} else if (lhs == NULL || rhs == NULL || lhs->size != rhs->size) {
Expand All @@ -214,11 +203,9 @@ equal_linked_list(const linked_list*const lhs, const linked_list*const rhs) {
return lhs_node == NULL && rhs_node == NULL;
}

void
sort_linked_list(linked_list*const list) {}
void sort_linked_list(linked_list*const list) {}

inline bool
empty_linked_list(const linked_list*const list) {
inline bool empty_linked_list(const linked_list*const list) {
return list == NULL
|| list->head == NULL
|| list->tail == NULL
Expand Down
20 changes: 20 additions & 0 deletions DataStructures/src/sort_map.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* MIT License
*
* Copyright (c) 2024 Uriel Rivas
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* https://github.com/zoningorg/zoning/blob/main/LICENSE
*/

#include "../inc/sort_map.h"

12 changes: 4 additions & 8 deletions DataStructures/src/sort_set.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
#include "../inc/memory.h"
#include "../inc/sort_set.h"

inline sort_set*
new_sort_set(int value) {
inline sort_set* new_sort_set(int value) {
sort_set* response;

ALLOCATE(sort_set, response);
Expand All @@ -39,11 +38,9 @@ new_sort_set(int value) {
return response;
}

inline void
add_to_sort_set(sort_set*const set, int value) {}
inline void add_to_sort_set(sort_set*const set, int value) {}

bool
exist_in_sort_set(const sort_set*const set, int target) {
bool exist_in_sort_set(const sort_set*const set, int target) {
if (set == NULL || set->size == 0) {
return false;
}
Expand All @@ -63,8 +60,7 @@ exist_in_sort_set(const sort_set*const set, int target) {
return false;
}

void
delete_sort_set(sort_set* set) {
void delete_sort_set(sort_set* set) {
if (set == NULL) {
return;
}
Expand Down
4 changes: 3 additions & 1 deletion DataStructures/test/array_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
int main(void) {
START_TEST("array_test");

EXPECT_TRUE(1);
/*
array arr = new_array();
delete_array(arr);
Expand Down Expand Up @@ -62,7 +64,7 @@ int main(void) {
delete_linked_list(list);
delete_linked_list(list_copy);

*/
FINISH_TEST();

return 0;
Expand Down
4 changes: 2 additions & 2 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#
# https://github.com/zoningorg/zoning/blob/main/LICENSE

all: test clean
all: test

data:
cd DataStructures && make
Expand All @@ -30,4 +30,4 @@ FileTransferTest:
cd FileTransfer && make test

clean:
whoami
cd DataStructures && make clean && cd ../FileTransfer && make clean

0 comments on commit c4242a1

Please sign in to comment.