Changeset 4fec9ee in mainline for uspace/app/sbi/src/intmap.c


Ignore:
Timestamp:
2011-03-18T16:17:24Z (13 years ago)
Author:
Lubos Slovak <lubos.slovak@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
00b13408
Parents:
4f66cc7b (diff), d8e61b0d (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.
Message:

Changes from development

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/sbi/src/intmap.c

    r4f66cc7b r4fec9ee  
    5050}
    5151
     52/** Deinitialize map.
     53 *
     54 * The map must be already empty.
     55 *
     56 * @param intmap        Map to initialize.
     57 */
     58void intmap_fini(intmap_t *intmap)
     59{
     60        list_fini(&intmap->elem);
     61}
     62
    5263/** Set value corresponding to a key.
    5364 *
     
    5667 * is removed from the map.
    5768 *
    58  * @param intmap        Map.
    59  * @param key           Key (integer).
    60  * @param value         Value (must be a pointer) or @c NULL.
     69 * @param intmap        Map
     70 * @param key           Key (integer)
     71 * @param value         Value (must be a pointer) or @c NULL
    6172 */
    6273void intmap_set(intmap_t *intmap, int key, void *value)
     
    7586                                /* Remove map element. */
    7687                                list_remove(&intmap->elem, node);
    77                                 node->data = NULL;
    78                                 free(node);
     88                                free(elem);
    7989                        }
    8090                        return;
     
    98108/** Get value corresponding to a key.
    99109 *
    100  * @param intmap        Map.
    101  * @param key           Key for which to retrieve mapping.
     110 * @param intmap        Map
     111 * @param key           Key for which to retrieve mapping
    102112 *
    103113 * @return              Value correspoding to @a key or @c NULL if no mapping
     
    121131        return NULL;
    122132}
     133
     134/** Get first element in the map.
     135 *
     136 * For iterating over the map, this returns the first element (in no
     137 * particular order).
     138 *
     139 * @param intmap        Map
     140 * @return              Map element or NULL if the map is empty
     141 */
     142map_elem_t *intmap_first(intmap_t *intmap)
     143{
     144        list_node_t *node;
     145
     146        node = list_first(&intmap->elem);
     147        if (node == NULL)
     148                return NULL;
     149
     150        return list_node_data(node, map_elem_t *);
     151}
     152
     153/** Get element key.
     154 *
     155 * Giver a map element, return the key.
     156 *
     157 * @param elem          Map element
     158 * @return              Key
     159 */
     160int intmap_elem_get_key(map_elem_t *elem)
     161{
     162        return elem->key;
     163}
     164
     165/** Get element value.
     166 *
     167 * Giver a map element, return the value.
     168 *
     169 * @param elem          Map element
     170 * @return              Value
     171 */
     172void *intmap_elem_get_value(map_elem_t *elem)
     173{
     174        return elem->value;
     175}
Note: See TracChangeset for help on using the changeset viewer.