Changeset e8e31d9 in mainline for uspace/app/bithenge/tree.c


Ignore:
Timestamp:
2012-07-24T21:20:12Z (12 years ago)
Author:
Sean Bartell <wingedtachikoma@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
842ed146
Parents:
ff788c3
Message:

Bithenge: add bithenge_node_get

File:
1 edited

Legend:

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

    rff788c3 re8e31d9  
    8080}
    8181
     82typedef struct {
     83        bithenge_node_t *key;
     84        bithenge_node_t **out;
     85} get_for_each_data_t;
     86
     87static int get_for_each_func(bithenge_node_t *key, bithenge_node_t *value,
     88    void *raw_data)
     89{
     90        get_for_each_data_t *data = (get_for_each_data_t *)raw_data;
     91        bool equal = bithenge_node_equal(key, data->key);
     92        bithenge_node_dec_ref(key);
     93        if (equal) {
     94                *data->out = value;
     95                return EEXIST;
     96        }
     97        bithenge_node_dec_ref(value);
     98        return EOK;
     99}
     100
     101/** Get a child of a node. Takes ownership of the key. If the node does not
     102 * 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.
     106 * @param key The key to search for.
     107 * @param[out] out Holds the found node.
     108 * @return EOK on success, ENOENT if not found, or another error code from
     109 * errno.h. */
     110int bithenge_node_get(bithenge_node_t *self, bithenge_node_t *key,
     111    bithenge_node_t **out)
     112{
     113        assert(self->type == BITHENGE_NODE_INTERNAL);
     114        if (self->internal_ops->get)
     115                return self->internal_ops->get(self, key, out);
     116        *out = NULL;
     117        get_for_each_data_t data = {key, out};
     118        int rc = bithenge_node_for_each(self, get_for_each_func, &data);
     119        bithenge_node_dec_ref(key);
     120        if (rc == EEXIST && *out)
     121                return EOK;
     122        if (rc == EOK)
     123                rc = ENOENT;
     124        bithenge_node_dec_ref(*out);
     125        return rc;
     126}
     127
    82128typedef struct
    83129{
Note: See TracChangeset for help on using the changeset viewer.