-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathobject.h
97 lines (72 loc) · 1.5 KB
/
object.h
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#ifndef OBJECT_H
#define OBJECT_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h>
typedef enum {
DataType_InValid=0,
DataType_Int,
DataType_Float,
DataType_String,
DataType_True,
DataType_False,
DataType_Null,
DataType_Array,
DataType_Dict
} DataType;
typedef struct {
DataType type;
char _nextFlag;
int _referNum;
union {
int i;
double d;
} value;
void *data;
void *_data1; // key weak
void *_data2; // next strong
} Object;
typedef struct {
int length;
int capacity;
Object **dataArr;
} Array;
typedef struct {
int length;
int capacity;
char **keyArr;
Object **valueArr;
} Dict;
typedef struct {
int length;
int capacity;
char **keyArr;
Object **valueArr;
int *lenArr;
} Hash;
Array *array_create(int *capacity);
void array_set(Array *array,Object *value);
Object *array_get(Array *array,int index);
int array_length(Array *array);
void array_free(Array *array);
char *array_toString(Array *array);
Dict *dict_create(int *capacity);
void dict_set(Dict *dict,char *key,Object *value);
Object *dict_get(Dict *dict,char *key);
int dict_length(Dict *dict);
void dict_free(Dict *dict);
char *dict_toString(Dict *dict);
Object *object_create();
void object_free(Object *object);
char *object_toString(Object *object);
Hash *hash_create(int *capcity);
void hash_set(Hash *dict,char *key,Object *value);
Object *hash_get(Hash *dict,char *key);
int hash_length(Hash *dict);
void hash_free(Hash *dict);
char *hash_toString(Hash *dict);
#ifdef __cplusplus
}
#endif
#endif