Changeset 5e718d9 in mainline for uspace/lib/bithenge/tree.c
- Timestamp:
- 2012-08-21T10:04:16Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 67edca6
- Parents:
- 0da6c04 (diff), 6a97f2e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/bithenge/tree.c
r0da6c04 r5e718d9 76 76 if (!node) 77 77 return; 78 assert (node->refs > 0); 78 79 if (--node->refs == 0) 79 80 node_destroy(node); … … 89 90 { 90 91 get_for_each_data_t *data = (get_for_each_data_t *)raw_data; 91 bool equal = bithenge_node_equal(key, data->key); 92 bool equal; 93 int rc = bithenge_node_equal(&equal, key, data->key); 92 94 bithenge_node_dec_ref(key); 95 if (rc != EOK) 96 return rc; 93 97 if (equal) { 94 98 *data->out = value; … … 101 105 /** Get a child of a node. Takes ownership of the key. If the node does not 102 106 * provide this function, for_each will be used as an alternative, which may be 103 * very slow. 104 * @memberof bithenge_node_t 105 * @param self The internal node to find a child of. 107 * very slow. Also works for blob nodes to find the byte value at a given 108 * index. 109 * @memberof bithenge_node_t 110 * @param self The internal/blob node to find a child of. 106 111 * @param key The key to search for. 107 112 * @param[out] out Holds the found node. … … 111 116 bithenge_node_t **out) 112 117 { 118 if (self->type == BITHENGE_NODE_BLOB) { 119 if (bithenge_node_type(key) != BITHENGE_NODE_INTEGER) { 120 bithenge_node_dec_ref(key); 121 return ENOENT; 122 } 123 bithenge_int_t offset = bithenge_integer_node_value(key); 124 bithenge_node_dec_ref(key); 125 uint8_t byte; 126 aoff64_t size = 1; 127 int rc = bithenge_blob_read(bithenge_node_as_blob(self), 128 offset, (char *)&byte, &size); 129 if (rc != EOK) 130 return rc; 131 if (size != 1) 132 return ENOENT; 133 134 return bithenge_new_integer_node(out, byte); 135 } 136 113 137 assert(self->type == BITHENGE_NODE_INTERNAL); 114 138 if (self->internal_ops->get) … … 174 198 int bithenge_new_empty_internal_node(bithenge_node_t **out) 175 199 { 200 if (bithenge_should_fail()) 201 return ENOMEM; 176 202 bithenge_node_inc_ref(&empty_internal_node); 177 203 *out = &empty_internal_node; … … 277 303 { 278 304 assert(out); 305 if (bithenge_should_fail()) 306 return ENOMEM; 279 307 *out = value ? &true_node : &false_node; 280 308 (*out)->refs++; … … 327 355 * internal nodes. Takes ownership of nothing. 328 356 * @memberof bithenge_node_t 357 * @param[out] out Holds whether the nodes are equal. 329 358 * @param a, b Nodes to compare. 330 * @return Whether the nodes are equal. If an error occurs, returns false. 331 * @todo Add support for internal nodes. 332 */ 333 bool bithenge_node_equal(bithenge_node_t *a, bithenge_node_t *b) 334 { 335 if (a->type != b->type) 336 return false; 359 * @return EOK on success or an error code from errno.h. 360 * @todo Add support for internal nodes. */ 361 int bithenge_node_equal(bool *out, bithenge_node_t *a, bithenge_node_t *b) 362 { 363 if (a->type != b->type) { 364 *out = false; 365 return EOK; 366 } 337 367 switch (a->type) { 338 368 case BITHENGE_NODE_INTERNAL: 339 return false; 369 *out = false; 370 return EOK; 340 371 case BITHENGE_NODE_BOOLEAN: 341 return a->boolean_value == b->boolean_value; 372 *out = a->boolean_value == b->boolean_value; 373 return EOK; 342 374 case BITHENGE_NODE_INTEGER: 343 return a->integer_value == b->integer_value; 375 *out = a->integer_value == b->integer_value; 376 return EOK; 344 377 case BITHENGE_NODE_STRING: 345 return !str_cmp(a->string_value.ptr, b->string_value.ptr); 378 *out = !str_cmp(a->string_value.ptr, b->string_value.ptr); 379 return EOK; 346 380 case BITHENGE_NODE_BLOB: 347 return bithenge_blob_equal( bithenge_node_as_blob(a),381 return bithenge_blob_equal(out, bithenge_node_as_blob(a), 348 382 bithenge_node_as_blob(b)); 349 383 } 350 return false;384 return EINVAL; 351 385 } 352 386
Note:
See TracChangeset
for help on using the changeset viewer.