Changeset 1c79996 in mainline for uspace/lib/bithenge/tree.c


Ignore:
Timestamp:
2012-08-18T23:20:48Z (12 years ago)
Author:
Sean Bartell <wingedtachikoma@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a42d7d8
Parents:
1f9c9a4
Message:

Bithenge: fix issues and expand coverage for test.sh

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/bithenge/tree.c

    r1f9c9a4 r1c79996  
    102102/** Get a child of a node. Takes ownership of the key. If the node does not
    103103 * provide this function, for_each will be used as an alternative, which may be
    104  * very slow.
    105  * @memberof bithenge_node_t
    106  * @param self The internal node to find a child of.
     104 * very slow. Also works for blob nodes to find the byte value at a given
     105 * index.
     106 * @memberof bithenge_node_t
     107 * @param self The internal/blob node to find a child of.
    107108 * @param key The key to search for.
    108109 * @param[out] out Holds the found node.
     
    112113    bithenge_node_t **out)
    113114{
     115        if (self->type == BITHENGE_NODE_BLOB) {
     116                if (bithenge_node_type(key) != BITHENGE_NODE_INTEGER) {
     117                        bithenge_node_dec_ref(key);
     118                        return ENOENT;
     119                }
     120                bithenge_int_t offset = bithenge_integer_node_value(key);
     121                bithenge_node_dec_ref(key);
     122                uint8_t byte;
     123                aoff64_t size = 1;
     124                int rc = bithenge_blob_read(bithenge_node_as_blob(self),
     125                    offset, (char *)&byte, &size);
     126                if (rc != EOK)
     127                        return rc;
     128                if (size != 1)
     129                        return ENOENT;
     130
     131                return bithenge_new_integer_node(out, byte);
     132        }
     133
    114134        assert(self->type == BITHENGE_NODE_INTERNAL);
    115135        if (self->internal_ops->get)
Note: See TracChangeset for help on using the changeset viewer.