Update the data associated to the element currently selected by the * iterator. The operation works both for regular key nodes and for inline * leaves represented virtually by the iterator. * * The function returns 1 on success or 0 on error. In case the iterator * is not positioned on an element errno is set to ENOENT. If the current * node needs to be reallocated in order to store a non-NU
| 2254 | * node needs to be reallocated in order to store a non-NULL value and the |
| 2255 | * allocation fails, errno is set to ENOMEM. */ |
| 2256 | int raxIteratorSetData(raxIterator *it, void *data) { |
| 2257 | raxNode **parentlink; |
| 2258 | |
| 2259 | if (it->rt == NULL || (it->flags & RAX_ITER_EOF)) { |
| 2260 | errno = ENOENT; |
| 2261 | return 0; |
| 2262 | } |
| 2263 | |
| 2264 | parentlink = raxIteratorCurrentParentLink(it,NULL); |
| 2265 | if (parentlink == NULL) { |
| 2266 | errno = ENOENT; |
| 2267 | return 0; |
| 2268 | } |
| 2269 | |
| 2270 | if (raxIteratorIsInlineLeaf(it)) { |
| 2271 | memcpy(parentlink,&data,sizeof(data)); |
| 2272 | it->data = data; |
| 2273 | return 1; |
| 2274 | } |
| 2275 | |
| 2276 | if (it->node == NULL || !it->node->iskey) { |
| 2277 | errno = ENOENT; |
| 2278 | return 0; |
| 2279 | } |
| 2280 | |
| 2281 | if (it->node->isnull && data != NULL) { |
| 2282 | raxNode *newnode = raxReallocForData(it->node,data); |
| 2283 | if (newnode == NULL) { |
| 2284 | errno = ENOMEM; |
| 2285 | return 0; |
| 2286 | } |
| 2287 | if (newnode != it->node) { |
| 2288 | memcpy(parentlink,&newnode,sizeof(newnode)); |
| 2289 | it->node = newnode; |
| 2290 | } |
| 2291 | } |
| 2292 | |
| 2293 | raxSetData(it->node,data); |
| 2294 | it->data = data; |
| 2295 | return 1; |
| 2296 | } |
| 2297 | |
| 2298 | /* ----------------------- Defragmentation iterator ------------------------- |
| 2299 | * The defragmentation iterator scans the radix tree structure itself and |
nothing calls this directly
no test coverage detected