Skip to content
tat edited this page Sep 14, 2012 · 3 revisions

Hmap easy is based on Hmap and it have a simplified interface.

Simple Example

This is an example to create a map contains string value.

#include <u/libu.h>
 
int main()
{
  u_hmap_opts_t *map_opts;
  u_hmap_t *map_keys;
  
  //create map
  dbg_err_if(u_hmap_opts_new(&map_opts));
  dbg_err_if(u_hmap_opts_set_val_type(map_opts, U_HMAP_OPTS_DATATYPE_STRING));
  dbg_err_if(u_hmap_easy_new(map_opts, &map));
 
  //add element
  dbg_err_if(u_hmap_easy_put(hmap, "frd1", (const void *) "Jack"));
  dbg_err_if(u_hmap_easy_put(hmap, "frd2", (const void *) "Mickael"));
  dbg_err_if(u_hmap_easy_put(hmap, "frd3", (const void *) "Ranzi"));
 
  //get element
  u_con("my best friends are : %s, %s, %s", 
      (char *) u_hmap_easy_get(map, "frd1"),
      (char *) u_hmap_easy_get(map, "frd2")
      (char *) u_hmap_easy_get(map, "frd3")
  );
  
  //delete element
  dbg_err_if(u_hmap_easy_del(hmap, "frd1");
  
  u_hmap_easy_free(map);
 
  return 0;
err:
  return ~0;
}
Clone this wiki locally