<commit_before>#include "map.h"
#include <string.h>

map* create_map(){
	map* m = (map*)malloc(sizeof(map));
	int i;
	m->size=0;
	m->buckets = (item**)malloc(sizeof(item*)*NUM_BUCKETS);
	for(i=0;i<NUM_BUCKETS;++i)
		m->buckets[i] = NULL;
	m->keys = create_vector();
	return m;
}

void* map_get(map* m, char * key){
	if(key==NULL){
		return NULL;
	}
	size_t h = hash_func(key);
	item* itm = m->buckets[h];
	while(itm!=NULL){
		if(strcmp(key, itm->key)==0)
			return itm->val;
		itm = itm->next;
	}
	return NULL;
}

void map_put(map* m, char* key, void* val, size_t len){
	int keylen = strlen(key);
	size_t h = hash_func(key);
	item* itm = m->buckets[h];
	item* last = NULL;
	while(itm!=NULL){
		if(strcmp(key, itm->key)==0){
		if(itm->val!=NULL) free(itm->val);
		itm->val = malloc(len);
		memcpy(itm->val, val, len);
			return;
		}
		if(itm->next==NULL) last = itm;
		itm = itm->next;
	}
	itm = (item*)malloc(sizeof(item));
	itm->key = malloc(keylen);
	memcpy(itm->key, key, keylen);
	itm->val = malloc(len);
	memcpy(itm->val, val, len);
	itm->next = NULL;
	if(last==NULL) m->buckets[h] = itm;
	else last->next = itm;
	vector_add(m->keys, itm->key, keylen);
	m->size++;
}

void map_remove(map* m, char* key){
	int n = strlen(key);
	size_t h = hash_func(key);
	item *itm = m->buckets[h];
	item *last = NULL;
	int keyind;
	while(itm!=NULL){
		if(strcmp(key, itm->key)==0){
		if(last==NULL)
		m->buckets[h] = NULL;
		if(last!=NULL)
		last->next = itm->next;
		free(itm->key);
		free(itm->val);<commit_msg>fixed bug in map.c; forgot to include \0 at end of key<commit_after>#include "map.h"
#include <string.h>

map* create_map(){
	map* m = (map*)malloc(sizeof(map));
	int i;
	m->size=0;
	m->buckets = (item**)malloc(sizeof(item*)*NUM_BUCKETS);
	for(i=0;i<NUM_BUCKETS;++i)
		m->buckets[i] = NULL;
	m->keys = create_vector();
	return m;
}

void* map_get(map* m, char * key){
	if(key==NULL){
		return NULL;
	}
	size_t h = hash_func(key);
	item* itm = m->buckets[h];
	while(itm!=NULL){
		if(strcmp(key, itm->key)==0)
			return itm->val;
		itm = itm->next;
	}
	return NULL;
}

void map_put(map* m, char* key, void* val, size_t len){
	int keylen = strlen(key);
	size_t h = hash_func(key);
	item* itm = m->buckets[h];
	item* last = NULL;
	while(itm!=NULL){
		if(strcmp(key, itm->key)==0){
		if(itm->val!=NULL) free(itm->val);
		itm->val = malloc(len);
		memcpy(itm->val, val, len);
			return;
		}
		if(itm->next==NULL) last = itm;
		itm = itm->next;
	}
	itm = (item*)malloc(sizeof(item));
	itm->key = malloc(keylen+1);
	memcpy(itm->key, key, keylen+1);
	itm->val = malloc(len);
	memcpy(itm->val, val, len);
	itm->next = NULL;
	if(last==NULL) m->buckets[h] = itm;
	else last->next = itm;
	vector_add(m->keys, itm->key, keylen);
	m->size++;
}

void map_remove(map* m, char* key){
	int n = strlen(key);
	size_t h = hash_func(key);
	item *itm = m->buckets[h];
	item *last = NULL;
	int keyind;
	while(itm!=NULL){
		if(strcmp(key, itm->key)==0){
		if(last==NULL)
		m->buckets[h] = NULL;
		if(last!=NULL)
		last->next = itm->next;
		free(itm->key);
		free(itm->val);
{'fraction_non_alphanumeric': 0.22072810757625452, 'fraction_numerical': 0.004263693014102984, 'mean_word_length': 4.222602739726027, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3963483', 'n_tokens_mistral': 1462, 'n_tokens_neox': 1411, 'n_words': 280}