c-md/srcs/map/core.c.md
lohhiiccc 80f7a1b9b6 feat(build): add build instructions in README and convert sources to .c.md format
- Add detailed build and bootstrap instructions to README.md.
 - Convert all source and header files from .c/.h to .c.md/.h.md.
 - Add bootstrap.sh script for automated building across version history.
 - Update Makefile and sources.mk to reflect new markdown-based source organization.
2026-01-12 14:54:49 +01:00

960 B

#include <stdlib.h>

#include "map.h"
#include "internal/map_internal.h"

void
map_init(t_map *map)
{
	map->ranges = NULL;
	map->count = 0;
	map->capacity = 0;
}

void
map_add(t_map *map, uint32_t src_start, uint32_t src_end,
	uint32_t dst_start, uint32_t dst_end)
{
	t_range	*range;

	if (map->count >= map->capacity)
	{
		if (0 != map_grow(map))
			return ;
	}
	range = &map->ranges[map->count];
	range->src_start = src_start;
	range->src_end = src_end;
	range->dst_start = dst_start;
	range->dst_end = dst_end;
	map->count++;
}

void
map_free(t_map *map)
{
	free(map->ranges);
	map->ranges = NULL;
	map->count = 0;
	map->capacity = 0;
}

int8_t
map_grow(t_map *map)
{
	size_t		new_cap;
	t_range		*new_ranges;

	new_cap = (0 == map->capacity) ? MAP_INIT_CAP : map->capacity * 2;
	new_ranges = realloc(map->ranges, new_cap * sizeof(t_range));
	if (NULL == new_ranges)
		return (1);
	map->ranges = new_ranges;
	map->capacity = new_cap;
	return (0);
}