fixed the no work
This commit is contained in:
BIN
hehe_array_test
BIN
hehe_array_test
Binary file not shown.
@ -19,7 +19,7 @@ int main(void) {
|
||||
struct HeheArray *array2 = hehe_array_yoink(array, ARRAY2_START_INDEX, ARRAY2_LEN);
|
||||
if(array2 == NULL) return 69;
|
||||
for(i = 0; i < ARRAY2_LEN; i++) {
|
||||
//printf("%d\n", *(int *)hehe_array_get(array2, i));
|
||||
printf("%d\n", *(int *)hehe_array_get(array2, i));
|
||||
}
|
||||
puts("\n\n");
|
||||
for(i = 0; i < ARRAY_LEN - ARRAY2_LEN; i++) {
|
||||
|
||||
@ -3,13 +3,6 @@
|
||||
#ifndef HEHE_ARRAYLIB
|
||||
#define HEHE_ARRAYLIB
|
||||
|
||||
#define DEBUG
|
||||
#ifdef DEBUG
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -24,11 +17,11 @@ struct HeheArray {
|
||||
static void *hehe_alloc_array(size_t initial_len, size_t type_size) {
|
||||
if(initial_len == 0) initial_len = 1;
|
||||
struct HeheArray *array = malloc(sizeof(*array));
|
||||
array->len = initial_len;
|
||||
size_t max_len = 1;
|
||||
while(initial_len >>= 1) max_len <<= 1;
|
||||
|
||||
array->type_size = type_size;
|
||||
array->len = initial_len;
|
||||
array->max_len = max_len;
|
||||
array->content = malloc(max_len * type_size);
|
||||
memset(array->content, 0, max_len * type_size);
|
||||
@ -77,17 +70,11 @@ static int hehe_array_pop(struct HeheArray *array, void *value) {
|
||||
}
|
||||
|
||||
static struct HeheArray *hehe_array_yoink(struct HeheArray *array, size_t start_index, size_t len) {
|
||||
puts("a");
|
||||
if(start_index + len >= array->len) return NULL;
|
||||
puts("b");
|
||||
struct HeheArray *ret = hehe_alloc_array(len, array->type_size);
|
||||
puts("c");
|
||||
memcpy(ret->content, array->content + start_index * array->type_size, len * array->type_size);
|
||||
puts("d");
|
||||
memmove(array->content + start_index * array->type_size, array->content + (start_index + len) * array->type_size, (array->len - len - start_index) * array->type_size);
|
||||
puts("e");
|
||||
hehe_array_set_len(array, array->len - len);
|
||||
puts("f");
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user