Example #1
0
/****************************************************************************************
* Function name - heap_remove_node
*
* Description -  Removes hnode from a certain slot position, reheapefies the heap 
* 		 and marks the slot in the ids array as available (-1)
*
* Input -       *h - pointer to an initialized heap
*               slot - index of the heap-array (slot), where to remove hnode
*               reserve_slot - true -means to reserve the slot
* Return Code/Output - On success - a valid hnode, on error - 0
****************************************************************************************/
hnode* heap_remove_node (heap*const h, const size_t slot, int reserve_slot)
{
  hnode* mved_end_node = 0;
  size_t parent_slot = 0;
  hnode* removed_node = h->heap[slot];
  size_t removed_node_id;

  if (!removed_node)
    {
      fprintf(stderr, "%s - error: null removed node.\n", __func__);
      return 0;
    }
	
  removed_node_id = removed_node->node_id;

  /* Decrement the heap size */
  h->curr_heap_size--;

  /* Reheapify only, if we're not deleting the last entry. */
  if (slot < h->curr_heap_size)
    {
      mved_end_node = h->heap[h->curr_heap_size];
      
      /* 
         Move the end node to the location being removed.  Update
         slot in the parallel <ids> array.
      */
      heap_put_node_to_slot (h, slot, mved_end_node);

      /* 	
         If the mved_end_node "node-value" < than the value its 
         parent, we move it up the heap.
      */
      parent_slot = HEAP_PARENT (slot);
		
      if ((*h->fcomp) (mved_end_node, h->heap[parent_slot])) // <
        {
          filter_up (h, slot);
        }
      else
        {
          filter_down (h, slot);
        }
    }
	
  /* Mark the node-id entry as free. */
  if (! reserve_slot)
    {
      release_node_id (h, removed_node_id);
    }

  return removed_node;
}
Example #2
0
    void group_free_deep(abstract_group * group, Functor const & doOnFree)
    {
        size_t synths = 0;
        group->apply_deep_on_children([&](server_node & node) {
             if (node.is_synth()) {
                 release_node_id(&node);
                 synths += 1;
             }
             doOnFree(node);
        });

        group->free_synths_deep();
        synth_count_ -= synths;
    }
Example #3
0
int release_kept_timer_id (timer_queue*const tq, long timer_id)
{
  heap* h = (heap *) tq;

  if (!tq || timer_id < 0 || (size_t) timer_id > h->max_heap_size)
    {
      fprintf (stderr, "%s - error: wrong input.\n", __func__);
      return -1;
    }

  release_node_id (h, (size_t) timer_id);

  return 0;
}
Example #4
0
    void group_free_all(abstract_group * group, Functor const & doOnFree)
    {
        size_t synths = 0, groups = 0;
        group->apply_deep_on_children([&](server_node & node) {
            release_node_id(&node);
            if (node.is_synth())
                synths += 1;
            else
                groups += 1;
            doOnFree(node);
        });

        group->free_children();
        synth_count_ -= synths;
        group_count_ -= groups;
    }
Example #5
0
    void remove_node(server_node * node, Functor const & doOnFree)
    {
        if (!node->is_synth())
            group_free_all(static_cast<abstract_group*>(node), doOnFree);

        /** \todo recursively remove nodes from node_set
         *        for now this is done by the auto-unlink hook
         * */

        doOnFree(*node);
        abstract_group * parent = node->parent_;
        parent->remove_child(node);
        if (node->is_synth())
            synth_count_ -= 1;
        else
            group_count_ -= 1;

        release_node_id(node);
    }