示例#1
0
OMX_ERRORTYPE
tiz_map_insert (tiz_map_t * ap_map, OMX_PTR ap_key,
                OMX_PTR ap_value, OMX_U32 * ap_index)
{
  tiz_map_item_t *p_item = NULL;

  assert (NULL != ap_map);
  assert (NULL != ap_key);
  assert (NULL != ap_map->p_tree);
  assert (NULL != ap_index);

  if (NULL != tiz_map_find (ap_map, ap_key))
    {
      return OMX_ErrorBadParameter;
    }

  if (NULL == (p_item = (tiz_map_item_t *)
               map_calloc (ap_map->p_soa, sizeof (tiz_map_item_t))))
    {
      return OMX_ErrorInsufficientResources;
    }

  p_item->p_key = ap_key;
  p_item->p_value = ap_value;
  p_item->p_map = ap_map;

  if (-1 == avl_insert_by_key (ap_map->p_tree, p_item, ap_index))
    {
      map_free (ap_map->p_soa, p_item);
      p_item = NULL;
      return OMX_ErrorInsufficientResources;
    }

  ap_map->size++;

  TIZ_LOG (TIZ_TRACE, "Inserted in map. size [%d]", ap_map->size);

  return OMX_ErrorNone;
}
示例#2
0
文件: test.c 项目: pydatastructs/avl
int
main (int argc, char ** argv)
{
  avl_tree * tree;
  unsigned int index;

  tree = avl_new_avl_tree (compare_ints, NULL);

  avl_insert_by_key (tree, (void *) 50, &index); avl_print_tree (tree, int_printer); avl_verify (tree);
  avl_insert_by_key (tree, (void *) 45, &index); avl_print_tree (tree, int_printer); avl_verify (tree);
  avl_insert_by_key (tree, (void *) 15, &index); avl_print_tree (tree, int_printer); avl_verify (tree);
  avl_insert_by_key (tree, (void *) 10, &index); avl_print_tree (tree, int_printer); avl_verify (tree);
  avl_insert_by_key (tree, (void *) 75, &index); avl_print_tree (tree, int_printer); avl_verify (tree);
  avl_insert_by_key (tree, (void *) 55, &index); avl_print_tree (tree, int_printer); avl_verify (tree);
  avl_insert_by_key (tree, (void *) 70, &index); avl_print_tree (tree, int_printer); avl_verify (tree);
  avl_insert_by_key (tree, (void *) 80, &index); avl_print_tree (tree, int_printer); avl_verify (tree);
  avl_insert_by_key (tree, (void *) 60, &index); avl_print_tree (tree, int_printer); avl_verify (tree);
  avl_insert_by_key (tree, (void *) 32, &index); avl_print_tree (tree, int_printer); avl_verify (tree);
  avl_insert_by_key (tree, (void *) 20, &index); avl_print_tree (tree, int_printer); avl_verify (tree);
  avl_insert_by_key (tree, (void *) 40, &index); avl_print_tree (tree, int_printer); avl_verify (tree);
  avl_insert_by_key (tree, (void *) 25, &index); avl_print_tree (tree, int_printer); avl_verify (tree);
  avl_insert_by_key (tree, (void *) 22, &index); avl_print_tree (tree, int_printer); avl_verify (tree);
  avl_insert_by_key (tree, (void *) 31, &index); avl_print_tree (tree, int_printer); avl_verify (tree);
  avl_insert_by_key (tree, (void *) 30, &index); avl_print_tree (tree, int_printer); avl_verify (tree);
  while (tree->length) {
    int num = 0;
    int any = 0;
    any = fscanf (stdin, "%d", &num);
    if (any < 1) {
      return 0;
    } else {
      fprintf (stdout, "deleting %d\n", num);
      avl_remove_by_key (tree, (void *) num, null_key_free);
      avl_print_tree (tree, int_printer);
      avl_verify (tree);
    }
  }
  return 0;
}