2026-06-14 22:51:45 +03:00
|
|
|
#ifndef VALUELIST_H
|
|
|
|
|
#define VALUELIST_H
|
|
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
|
|
struct ValueList {
|
2026-06-21 13:35:05 +03:00
|
|
|
long *data;
|
2026-06-14 22:51:45 +03:00
|
|
|
size_t size;
|
2026-06-21 13:35:05 +03:00
|
|
|
struct ValueList *next;
|
2026-06-14 22:51:45 +03:00
|
|
|
};
|
|
|
|
|
|
2026-06-21 13:35:05 +03:00
|
|
|
static long valueListFind(struct ValueList *list, long *data, size_t size) {
|
2026-06-14 22:51:45 +03:00
|
|
|
long index = 0;
|
|
|
|
|
|
|
|
|
|
while (list) {
|
|
|
|
|
if (list->size == size && !memcmp(list->data, data, size * sizeof(long)))
|
|
|
|
|
return index;
|
|
|
|
|
index++, list = list->next;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-21 13:35:05 +03:00
|
|
|
static long valueListIntern(struct ValueList** list, long *data, size_t size) {
|
2026-06-14 22:51:45 +03:00
|
|
|
long index = 0;
|
|
|
|
|
|
|
|
|
|
while (*list) ++index, list = &(*list)->next;
|
|
|
|
|
if (!(*list = malloc(sizeof(struct ValueList))))
|
|
|
|
|
abort();
|
|
|
|
|
if (!((*list)->data = malloc(size * sizeof(long))))
|
|
|
|
|
abort();
|
|
|
|
|
|
|
|
|
|
memcpy((*list)->data, data, size * sizeof(long));
|
|
|
|
|
(*list)->size = size;
|
|
|
|
|
(*list)->next = NULL;
|
|
|
|
|
|
|
|
|
|
return index;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif /* VALUELIST_H */
|