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
|
#include <stdio.h>
#include <stdlib.h>
#import "ObjFWRT.h"
#import "private.h"
struct objc_sparsearray *
objc_sparsearray_new(uint8_t indexSize)
{
struct objc_sparsearray *sparsearray;
if ((sparsearray = calloc(1, sizeof(*sparsearray))) == NULL)
OBJC_ERROR("Failed to allocate memory for sparse array!");
if ((sparsearray->data = calloc(1, sizeof(*sparsearray->data))) == NULL)
OBJC_ERROR("Failed to allocate memory for sparse array!");
sparsearray->indexSize = indexSize;
return sparsearray;
}
void *
objc_sparsearray_get(struct objc_sparsearray *sparsearray, uintptr_t idx)
{
struct objc_sparsearray_data *iter = sparsearray->data;
for (uint8_t i = 0; i < sparsearray->indexSize - 1; i++) {
uintptr_t j =
(idx >> ((sparsearray->indexSize - i - 1) * 8)) & 0xFF;
if ((iter = iter->next[j]) == NULL)
return NULL;
}
return iter->next[idx & 0xFF];
}
void
objc_sparsearray_set(struct objc_sparsearray *sparsearray, uintptr_t idx,
void *value)
{
struct objc_sparsearray_data *iter = sparsearray->data;
for (uint8_t i = 0; i < sparsearray->indexSize - 1; i++) {
uintptr_t j =
(idx >> ((sparsearray->indexSize - i - 1) * 8)) & 0xFF;
if (iter->next[j] == NULL)
if ((iter->next[j] = calloc(1,
sizeof(struct objc_sparsearray_data))) == NULL)
OBJC_ERROR("Failed to allocate memory for "
"sparse array!");
|
|
|
|
|
|
|
|
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
|
#include <stdio.h>
#include <stdlib.h>
#import "ObjFWRT.h"
#import "private.h"
struct objc_sparsearray *
objc_sparsearray_new(uint8_t levels)
{
struct objc_sparsearray *sparsearray;
if ((sparsearray = calloc(1, sizeof(*sparsearray))) == NULL)
OBJC_ERROR("Failed to allocate memory for sparse array!");
if ((sparsearray->data = calloc(1, sizeof(*sparsearray->data))) == NULL)
OBJC_ERROR("Failed to allocate memory for sparse array!");
sparsearray->levels = levels;
return sparsearray;
}
void *
objc_sparsearray_get(struct objc_sparsearray *sparsearray, uintptr_t idx)
{
struct objc_sparsearray_data *iter = sparsearray->data;
for (uint8_t i = 0; i < sparsearray->levels - 1; i++) {
uintptr_t j =
(idx >> ((sparsearray->levels - i - 1) * 8)) & 0xFF;
if ((iter = iter->next[j]) == NULL)
return NULL;
}
return iter->next[idx & 0xFF];
}
void
objc_sparsearray_set(struct objc_sparsearray *sparsearray, uintptr_t idx,
void *value)
{
struct objc_sparsearray_data *iter = sparsearray->data;
for (uint8_t i = 0; i < sparsearray->levels - 1; i++) {
uintptr_t j =
(idx >> ((sparsearray->levels - i - 1) * 8)) & 0xFF;
if (iter->next[j] == NULL)
if ((iter->next[j] = calloc(1,
sizeof(struct objc_sparsearray_data))) == NULL)
OBJC_ERROR("Failed to allocate memory for "
"sparse array!");
|
86
87
88
89
90
91
92
93
94
95
|
free(data);
}
void
objc_sparsearray_free(struct objc_sparsearray *sparsearray)
{
freeSparsearrayData(sparsearray->data, sparsearray->indexSize);
free(sparsearray);
}
|
|
|
86
87
88
89
90
91
92
93
94
95
|
free(data);
}
void
objc_sparsearray_free(struct objc_sparsearray *sparsearray)
{
freeSparsearrayData(sparsearray->data, sparsearray->levels);
free(sparsearray);
}
|