- 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.
57 lines
960 B
Markdown
57 lines
960 B
Markdown
```c
|
|
#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);
|
|
}
|
|
```
|