Skip to content
Open

42 #28

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
Expand Down Expand Up @@ -506,7 +505,6 @@ Doxyfile.docs
# End of Doxygen rules

DartConfiguration.tcl
Makefile
build
obj
libft
56 changes: 0 additions & 56 deletions CMakeLists.txt

This file was deleted.

36 changes: 30 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,36 @@ SRC_D = src
INC_D = inc
OBJ_D = obj
LIB_D = lib
TEST_D = tests/standalone_tests

SRC = $(SRC_D)/hash_map.c
TEST_D = tests

SRC = $(SRC_D)/hash.c\
$(SRC_D)/new_node.c\
$(SRC_D)/add_node_to_history.c\
$(SRC_D)/history_destroy.c\
$(SRC_D)/hm_new.c\
$(SRC_D)/hm_destroy.c\
$(SRC_D)/find_node_by_key.c\
$(SRC_D)/node_remove_from_list.c\
$(SRC_D)/hm_remove.c\
$(SRC_D)/hm_add_new_key.c\
$(SRC_D)/hm_find_existing_node_and_replace_value.c\
$(SRC_D)/hm_insert_node.c\
$(SRC_D)/hm_handle_collision.c\
$(SRC_D)/hm_set.c\
$(SRC_D)/hm_get_seq.c\
$(SRC_D)/hm_get.c\
$(SRC_D)/hm_get_collision_count.c


INC = $(INC_D)/hashmap.h

OBJ := $(SRC:$(SRC_D)/%.c=$(OBJ_D)/%.o)

LIBFT = $(LIB_D)/libft/libft.a
LIBPAIR = $(LIB_D)/pair/pair.a

LIB_INC = $(LIB_D)/libft/inc
LIB_INC_PAIR = $(LIB_D)/pair/inc

CC = clang
LD = ar
Expand All @@ -37,34 +56,39 @@ LD_FLAGS = -rcs

all: $(NAME)

$(NAME): $(LIBFT) $(OBJ_D) $(OBJ) $(INC_D) $(INC)
$(NAME): $(LIBFT) $(LIBPAIR) $(OBJ_D) $(OBJ) $(INC_D) $(INC)
@$(LD) $(LD_FLAGS) $(NAME) $(OBJ)

$(OBJ_D):
@mkdir -p $(OBJ_D)

$(OBJ): $(OBJ_D)/%.o: $(SRC_D)/%.c
@$(CC) $(CC_FLAGS) -I$(INC_D) -I$(LIB_INC) -c $< -o $@
@$(CC) $(CC_FLAGS) -I$(INC_D) -I$(LIB_INC) -I$(LIB_INC_PAIR) -c $< -o $@

$(LIBFT):
@make -C $(LIB_D)/libft

$(LIBPAIR):
@make -C $(LIB_D)/pair

clean:
@rm -rf $(OBJ_D)
@rm -rf *.dSYM
@make -C $(LIB_D)/libft clean
@make -C $(LIB_D)/pair clean

fclean: clean
@rm -f $(NAME)
@rm -f test
@make -C $(LIB_D)/libft fclean
@make -C $(LIB_D)/pair fclean

submodule:
@git submodule init
@git submodule update

test: $(NAME)
@$(CC) $(CC_FLAGS) -I$(INC_D) -I$(LIB_INC) -o test $(TEST_D)/main.c $(NAME) $(LIBFT)
@$(CC) $(CC_FLAGS) -I$(INC_D) -I$(LIB_INC) -I$(LIB_INC_PAIR) -o test $(TEST_D)/main.c $(NAME) $(LIBFT)
@./test

re: fclean all
7 changes: 0 additions & 7 deletions cmake/add_FetchContent_MakeAvailable.cmake

This file was deleted.

5 changes: 0 additions & 5 deletions docs/CMakeLists.txt

This file was deleted.

11 changes: 0 additions & 11 deletions docs/mainpage.md

This file was deleted.

22 changes: 11 additions & 11 deletions inc/hashmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
/* */
/* ************************************************************************** */

#ifndef LIBHASHMAP_H
# define LIBHASHMAP_H
#ifndef HASHMAP_H
# define HASHMAP_H

#include <stddef.h>
#include "pair.h"
# include <stddef.h>
# include "pair.h"

void *hm_new(size_t _size);
void hm_destroy(void *_hm, void (*f)(void *));
void *hm_set(void *_hm, const char *_key, void *_value);
void *hm_get(const void *_hm, const char *_key);
t_pair hm_get_seq(const void *_hm);
size_t hm_get_collision_count(void *_hm);
void hm_remove(void *_hm, const char *_key, void (*_ft_delete)(void*));
void *hm_new(size_t _size);
void hm_destroy(void *_hm, void (*f)(void *));
void *hm_set(void *_hm, const char *_key, void *_value);
void *hm_get(const void *_hm, const char *_key);
t_pair hm_get_seq(const void *_hm);
size_t hm_get_collision_count(void *_hm);
void hm_remove(void *_hm, const char *_key, void (*_ft_delete)(void*));

#endif
48 changes: 31 additions & 17 deletions inc/hashmap_internal.h
Original file line number Diff line number Diff line change
@@ -1,26 +1,40 @@
#ifndef LIBHASHMAP_INTERNAL_H
# define LIBHASHMAP_INTERNAL_H
#ifndef HASHMAP_INTERNAL_H
# define HASHMAP_INTERNAL_H

# include <stdlib.h>
# include <stdint.h>
# include "libft.h"
# include "hashmap.h"

typedef struct s_hm_node {
char *key;
void *value;
struct s_hm_node *next;
struct s_hm_node *prev;
} t_hm_node;
typedef struct s_hm_node {
struct s_hm_node *next;
struct s_hm_node *prev;
char *key;
void *value;
} t_hm_node;

typedef struct s_hash_map {
t_hm_node **nodes;
t_hm_node *first_node;
t_hm_node *last_node;
t_hm_node *history;
size_t collisions;
size_t cap;
size_t size;
} t_hash_map;
typedef struct s_hash_map {
t_hm_node **nodes;
t_hm_node *first_node;
t_hm_node *last_node;
t_hm_node *history;
size_t collisions;
size_t cap;
size_t size;
} t_hash_map;

uint64_t hash(const size_t cap, const char *key);
t_hm_node *new_node(const char *_key, void *_value);
void add_node_to_history(t_hm_node **root, t_hm_node *node);
void history_destroy(t_hm_node *root, void (*f)(void *));
t_hm_node *find_node_by_key(t_hm_node *_node, const char *_key);
void node_remove_from_list(t_hash_map *_hm, t_hm_node *_node);
void *hm_add_new_key(t_hash_map *hm, t_hm_node **node,
const char *_key, void *_value);
void node_destroy(t_hm_node *_to_destroy, void (*_ft_delete)(void*));
void *hm_find_existing_node_and_replace_value(t_hash_map *hm,
t_hm_node *node_at_index, const char *_key, void *_value);
void *hm_insert_node(t_hash_map *hm, t_hm_node *node, t_hm_node *new);
void *hm_handle_collision(t_hash_map *hm,
t_hm_node *node, const char *_key, void *_value);
#endif
26 changes: 0 additions & 26 deletions lib/CMakeLists.txt

This file was deleted.

28 changes: 0 additions & 28 deletions minimake.sh

This file was deleted.

25 changes: 0 additions & 25 deletions src/CMakeLists.txt

This file was deleted.

30 changes: 30 additions & 0 deletions src/add_node_to_history.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* main.c :+: :+: */
/* +:+ */
/* By: haachtch <haachtch@student.codam.n> +#+ */
/* +#+ */
/* Created: 2020/07/13 09:34:21 by haachtch #+# #+# */
/* Updated: 2020/09/03 14:12:42 by haachtch ######## odam.nl */
/* */
/* ************************************************************************** */

#include "hashmap_internal.h"

void add_node_to_history(t_hm_node **root, t_hm_node *node)
{
t_hm_node *lst;

if (!*root)
{
(*root) = node;
}
else
{
lst = *root;
while (lst->next)
lst = lst->next;
lst->next = node;
}
}
Loading