Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamJlvt committed Jan 28, 2024
0 parents commit 9a14ee1
Show file tree
Hide file tree
Showing 33 changed files with 1,828 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
30 changes: 30 additions & 0 deletions .github/workflows/test_coding_style.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: check coding style

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: install dependencies
run: sudo apt-get install -y gcc libncurses5-dev
- name: coding-style-install
run: git clone https://github.com/Epitech/coding-style-checker.git
- name: coding-style
run: |
output=$(./coding-style-checker/coding-style.sh . .)
echo "$output"
echo "\n======== errors ========\n"
cat coding-style-reports.log
echo "\n========================\n"
errors=$(echo "$output" | grep -oP '\d+(?= coding style error)' || true)
if (( errors != 3 )); then
exit 1
fi
55 changes: 55 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# IntelliJ IDEA
.idea

# Prerequisites
*.d

# Object files
*.o
*.ko
*.obj
*.elf

# Linker output
*.ilk
*.map
*.exp

# Precompiled Headers
*.gch
*.pch

# Libraries
*.lib
*.a
*.la
*.lo

# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib

# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex

# Debug files
*.dSYM/
*.su
*.idb
*.pdb

# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

43 changes: 43 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
##
## EPITECH PROJECT, 2023
## my_sokoban
## File description:
## Makefile
##

CC = gcc -c -g3

ARRC = ar rc

SRCS = src/algorithm/key_hash.c \
src/dump/hashtable_dump.c \
src/manager/hashtable_delete.c \
src/manager/hashtable_insert.c \
src/provider/hashtable_provider.c \
src/search/hashtable_search.c \
src/utils/my_put_int.c \
src/utils/my_str_dup.c \
src/utils/my_str_utils.c \

HRCS = include

TARGET = libhashtable.a

OBJS = $(SRCS:.c=.o)

CFLAGS = -I $(HRCS)

all: $(TARGET)

$(TARGET): $(OBJS)
$(ARRC) $(TARGET) $(OBJS)

clean:
rm -f $(OBJS)

fclean: clean
rm -f $(TARGET)

re: fclean all

.PHONY: all clean fclean re
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Elementary Programming in C - Secured
Hashtable lib project for semester 1 of the Epitech Elementary Programming in C module (B-CPE-110).

## Introduction
The hash function is the central element of a hash table, defining which table index should be
used to store the data. A hash function is a mathematical function that converts any numerical
data into an output string comprising a fixed number of characters or a positive integer.

The full description of the project can be found in [subject.pdf](pdf/B-PSU-100_my_sokoban.pdf).

## Prerequisites
- [Make](https://www.gnu.org/software/make/)
- [GCC](https://gcc.gnu.org/)
- [LibC](https://www.gnu.org/software/libc/)

## Installation
```
B-PSU-100> git clone [email protected]:WilliamJlvt/secured.git
...
B-PSU-100> make
...
```
It will generate a library binary called `libhashtable.a`

## Results
| test | passed | results |
|-------------------------------------|--------|---------|
| 01 - Algorithm app. - Hash function | 3/4 | 75% |
| 02 - Algorithm app. - Hash table | 5/5 | 100% |
| 03 - Basics | 6/6 | 100% |
| 04 - Data structure | 5/5 | 100% |
| 05 - Optimization | 5/5 | 100% |
| 06 - Robustness | 10/10 | 100% |
| total | 34/35 | 97.1% |

## Coding style
All the source code has been written according to the [Epitech C Coding Style](https://williamjlvt.github.io/assets/coding_style/epitech_c_coding_style.pdf).
#### errors
| Fatal | Major | Minor | Info |
|-------|--------|-------|------|
| 0 | 0 | 0 | 0 |

## Unit tests
Unit tests are written using the [Criterion](https://github.com/Snaipe/Criterion) framework.
You can find the tests in the [bonus](bonus) directory. Just run `make lcriterion` to build the tests and `./hashtable` to run them.

## Authors
* **William JOLIVET** ([GitHub](https://github.com/WilliamJlvt) / [LinkedIn](https://www.linkedin.com/in/william-jolivet-64951a24b/))
* **Feyza MEDDAH** ([GitHub](https://github.com/etsuzaku))

## License
This project is licensed under the GNU Public License version 3.0 - see the [LICENSE](LICENSE) file for details.
72 changes: 72 additions & 0 deletions bonus/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
##
## EPITECH PROJECT, 2023
## my_sokoban
## File description:
## Makefile
##

CC = gcc -g3

LCRITERION = --coverage -lcriterion

VALGRIND = valgrind

SRCS = ../src/algorithm/key_hash.c \
../src/dump/hashtable_dump.c \
../src/manager/hashtable_delete.c \
../src/manager/hashtable_insert.c \
../src/provider/hashtable_provider.c \
../src/search/hashtable_search.c \
../src/utils/my_put_int.c \
../src/utils/my_str_dup.c \
../src/utils/my_str_utils.c \

TEST_SRCS = lcriterion/lcriterion_utils.c \
lcriterion/insert_test.c \
lcriterion/delete_test.c \
lcriterion/dump_test.c \

MAIN_SRCS = main.c

HRCS = ../include \
lcriterion/lcriterion.h \

TARGET = hashtable

BUILD_DIR = build

OBJS = $(SRCS:.c=.o)
TEST_OBJS = $(TEST_SRCS:.c=.o)
MAIN_OBJS = $(MAIN_SRCS:.c=.o)

all:
echo "USAGE\: make main OR make lcriterion"

$(TARGET): $(OBJS) $(TEST_OBJS)
$(CC) -o $(TARGET) $(OBJS) $(TEST_OBJS) $(LCRITERION)

main: $(OBJS) $(MAIN_OBJS)
$(CC) -o $(TARGET) $(OBJS) $(MAIN_OBJS)
clear
./$(TARGET)

mainv: $(OBJS) $(MAIN_OBJS)
$(CC) -o $(TARGET) $(OBJS) $(MAIN_OBJS)
clear
$(VALGRIND) ./$(TARGET)

lcriterion: $(OBJS) $(TEST_OBJS)
$(CC) -o $(TARGET) $(OBJS) $(TEST_OBJS) $(LCRITERION)
clear
./$(TARGET)

re: fclean all

clean:
rm -f $(OBJS)
rm -f $(TEST_OBJS)
rm -f $(MAIN_OBJS)
rm -rf $(BUILD_DIR)

fclean: clean
rm -f $(TARGET)
6 changes: 6 additions & 0 deletions bonus/lcriterion/create_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*
** EPITECH PROJECT, 2024
** secured
** File description:
** create_test.c
*/
48 changes: 48 additions & 0 deletions bonus/lcriterion/delete_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
** EPITECH PROJECT, 2024
** secured
** File description:
** delete_test.c
*/

#include <stdlib.h>
#include <criterion/criterion.h>
#include "../../include/hashtable.h"

Test(delete, delete_1)
{
hashtable_t *ht = new_hashtable(hash, 10);

cr_assert_eq(ht_insert(ht, "key", "value"), 0);
cr_assert_not_null(ht_search(ht, "key"));
cr_assert_str_eq(ht_search(ht, "key"), "value");
cr_assert_eq(ht_delete(ht, "key"), 0);
cr_assert_null(ht_search(ht, "key"));
delete_hashtable(ht);
}

Test(delete, delete_2)
{
hashtable_t *ht = new_hashtable(hash, 10);

cr_assert_eq(ht_insert(ht, "key", "value"), 0);
cr_assert_eq(ht_insert(ht, "key2", "value2"), 0);
cr_assert_not_null(ht_search(ht, "key"));
cr_assert_str_eq(ht_search(ht, "key"), "value");
cr_assert_not_null(ht_search(ht, "key2"));
cr_assert_str_eq(ht_search(ht, "key2"), "value2");
cr_assert_eq(ht_delete(ht, "key"), 0);
cr_assert_null(ht_search(ht, "key"));
cr_assert_not_null(ht_search(ht, "key2"));
cr_assert_str_eq(ht_search(ht, "key2"), "value2");
delete_hashtable(ht);
}

Test(delete, delete_3)
{
hashtable_t *ht = new_hashtable(hash, 10);

cr_assert_eq(ht_insert(ht, "key", "value"), 0);
cr_assert_eq(ht_delete(ht, "key2"), 84);
delete_hashtable(ht);
}
20 changes: 20 additions & 0 deletions bonus/lcriterion/destroy_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
** EPITECH PROJECT, 2024
** secured
** File description:
** destroy_test.c
*/

#include <stdlib.h>
#include <criterion/criterion.h>
#include "../../include/hashtable.h"

Test(destroy, destroy_1)
{
hashtable_t *ht = new_hashtable(hash, 10);

cr_assert_eq(ht_insert(ht, "key", "value"), 0);
cr_assert_not_null(ht_search(ht, "key"));
cr_assert_str_eq(ht_search(ht, "key"), "value");
delete_hashtable(ht);
}
Loading

0 comments on commit 9a14ee1

Please sign in to comment.