diff options
Diffstat (limited to 'xs.h')
| -rw-r--r-- | xs.h | 16 |
1 files changed, 12 insertions, 4 deletions
| @@ -1061,14 +1061,15 @@ xs_keyval *xs_keyval_make(xs_keyval *keyval, const xs_str *key, const xs_val *va | |||
| 1061 | 1061 | ||
| 1062 | typedef struct { | 1062 | typedef struct { |
| 1063 | int value_offset; /* offset to value (from dict start) */ | 1063 | int value_offset; /* offset to value (from dict start) */ |
| 1064 | int next; /* next node in sequential search */ | 1064 | int next; /* next node in sequential scanning */ |
| 1065 | int child[4]; /* child nodes in hashed search */ | 1065 | int child[4]; /* child nodes in hashed search */ |
| 1066 | char key[]; /* C string key */ | 1066 | char key[]; /* C string key */ |
| 1067 | } ditem_hdr; | 1067 | } ditem_hdr; |
| 1068 | 1068 | ||
| 1069 | typedef struct { | 1069 | typedef struct { |
| 1070 | int size; /* size of full dict (_XS_TYPE_SIZE) */ | 1070 | int size; /* size of full dict (_XS_TYPE_SIZE) */ |
| 1071 | int first; /* first node for sequential search */ | 1071 | int first; /* first node for sequential scanning */ |
| 1072 | int last; /* last node for sequential scanning */ | ||
| 1072 | int root; /* root node for hashed search */ | 1073 | int root; /* root node for hashed search */ |
| 1073 | /* a bunch of ditem_hdr and value follows */ | 1074 | /* a bunch of ditem_hdr and value follows */ |
| 1074 | } dict_hdr; | 1075 | } dict_hdr; |
| @@ -1153,8 +1154,15 @@ xs_dict *xs_dict_set(xs_dict *dict, const xs_str *key, const xs_val *value) | |||
| 1153 | memcpy(dict + di->value_offset, value, vsz); | 1154 | memcpy(dict + di->value_offset, value, vsz); |
| 1154 | 1155 | ||
| 1155 | /* chain to the sequential list */ | 1156 | /* chain to the sequential list */ |
| 1156 | di->next = dh->first; | 1157 | if (dh->first == 0) |
| 1157 | dh->first = end; | 1158 | dh->first = end; |
| 1159 | else { | ||
| 1160 | /* chain this new element to the last one */ | ||
| 1161 | ditem_hdr *dil = (ditem_hdr *)(dict + dh->last); | ||
| 1162 | dil->next = end; | ||
| 1163 | } | ||
| 1164 | |||
| 1165 | dh->last = end; | ||
| 1158 | } | 1166 | } |
| 1159 | else { | 1167 | else { |
| 1160 | /* ditem already exists */ | 1168 | /* ditem already exists */ |