-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray.h
More file actions
73 lines (55 loc) · 2.1 KB
/
array.h
File metadata and controls
73 lines (55 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright (C) 2024 Aleksei Rogov <alekzzzr@gmail.com>. All rights reserved.
#ifndef _ARRAY_H
#define _ARRAY_H
#define ARRAY_INITIAL_SIZE 4
#define ARRAY_INVALID_LEN -1
#define ARRAY_INVALID_OBJSZ -2
#define ARRAY_MALLOC_ERROR -3
#define ARRAY_INVALID_PTR -4
#define ARRAY_INVALID_INDEX -5
#define ARRAY_SUCCESS 0
struct ARRAY_ENTRY {
size_t size;
char data[];
};
struct ARRAY {
struct ARRAY_ENTRY **data;
size_t current;
size_t index;
size_t len;
size_t size;
};
// Init array 'array'
// Return 0 if success or error code
int array_init(struct ARRAY *array);
// Destroy array 'array'
// Return 0 if success or error code
int array_destroy(struct ARRAY *array);
// Add object 'src' of size 'object_size' to 'array'
// Return 0 if success or error code
int array_append(struct ARRAY *array, const void *src, size_t object_size);
// Put object 'src' of size 'object_size' to 'array' at index 'index'
// Return 0 if success or error code
int array_put(struct ARRAY *array, const void *src, size_t object_size, size_t index);
// Copy array[index] to 'src'. If 'object_size' is not equal array[index] return error
// Return 0 if success or error code
int array_get(const struct ARRAY *array, size_t index, void *dst, size_t object_size);
// Insert 'object' of size 'object_size' to array[index] with shift to right
// Return 0 if success or error code
int array_insert(struct ARRAY *array, size_t index, const void *object, size_t object_size);
// Delete objects in 'array' from 'start' to 'end'
// Return 0 if success or error code
int array_del(struct ARRAY *array, size_t start, size_t end);
// Start iterator at 'index'
// Return 0 if success or error code
int array_get_objects_start(struct ARRAY *array, size_t index);
// Get next object from 'array'
// Return 0 if success or error code
struct ARRAY_ENTRY* array_get_objects_next(struct ARRAY *array);
// Get number of object in the array
// Return number of object in the array
size_t array_len(const struct ARRAY *array);
// Get array size in bytes
// Return array size in bytes
size_t array_size(const struct ARRAY *array);
#endif