|
|
| version 1.1.2.2, 2011/05/03 14:22:18 | version 1.2, 2011/05/03 15:41:00 |
|---|---|
| Line 156 io_sarrGet(sarr_t * __restrict arr, u_int idx) | Line 156 io_sarrGet(sarr_t * __restrict arr, u_int idx) |
| } | } |
| /* | /* |
| * io_sarrGet2() - Always get element from dynamic split-order array | |
| * Function automatic grow array. Good use for Hash tables! | |
| * @arr = Array | |
| * @idx = Index (warning 1st element is at position 1) | |
| * return: NULL not found, !=NULL element | |
| */ | |
| void * | |
| io_sarrGet2(sarr_t * __restrict arr, u_int idx) | |
| { | |
| assert(arr); | |
| if (!arr || idx < 1) | |
| return NULL; | |
| if (arr->sarr_num < idx) | |
| if (io_sarrGrow(arr, idx)) | |
| return NULL; | |
| return io_sarrGet(arr, idx); | |
| } | |
| /* | |
| * io_sarrSet() - Set element to dynamic split-order array | * io_sarrSet() - Set element to dynamic split-order array |
| * @arr = Array | * @arr = Array |
| * @idx = Index (warning 1st element is at position 1) | * @idx = Index (warning 1st element is at position 1) |
| Line 174 io_sarrSet(sarr_t * __restrict arr, u_int idx, void *d | Line 193 io_sarrSet(sarr_t * __restrict arr, u_int idx, void *d |
| return ret; | return ret; |
| seg = arr->sarr_data[idx / arr->sarr_seg]; | seg = arr->sarr_data[idx / arr->sarr_seg]; |
| if (seg) { | if (!seg) { |
| pos = idx % arr->sarr_seg; | seg = calloc(arr->sarr_seg, sizeof(void*)); |
| ret = seg[pos]; | if (!seg) { |
| seg[pos] = data; | LOGERR; |
| return ret; | |
| } else | |
| memset(seg, 0, arr->sarr_seg * sizeof(void*)); | |
| arr->sarr_data[idx / arr->sarr_seg] = seg; | |
| } | } |
| pos = idx % arr->sarr_seg; | |
| ret = seg[pos]; | |
| seg[pos] = data; | |
| return ret; | return ret; |
| } | } |