Ejemplo n.º 1
0
static void insert_node(pj_timer_heap_t *ht, pj_timer_entry *new_node)
{
    if (ht->cur_size + 2 >= ht->max_size)
	grow_heap(ht);
    
    reheap_up( ht, new_node, ht->cur_size, HEAP_PARENT(ht->cur_size));
    ht->cur_size++;
}
Ejemplo n.º 2
0
            void reheap_up(unsigned index)
            {
                unsigned parent_index = parent(index);
//                PRX_DEBUG_COLOR("parent index : " << parent_index << "   current index: " << index, PRX_TEXT_GREEN);

                if( parent_index != 0 && *heap[index] < *heap[parent_index] )
                {
                    swap(index, parent_index);
                    reheap_up(parent_index);
                }
            }
Ejemplo n.º 3
0
//增加一个Timer Node
int ZCE_Timer_Heap::add_nodeid(int add_node_id)
{
    //放在堆的最后一个,
    timer_node_heap_[size_heap_] = add_node_id;
    note_to_heapid_[add_node_id] = static_cast<int>( size_heap_);

    ++size_heap_;

    reheap_up(size_heap_ - 1);

    return 0;
}
Ejemplo n.º 4
0
            void update( astar_node_t* element, astar_node_t* new_element )
            {
                PRX_ASSERT(finder.find(element) != finder.end());

                unsigned index = finder[element];
                finder[new_element] = index;
                finder.erase(element);

                heap[index] = new_element;
                reheap_up(index);
                reheap_down(index);
                delete element;
            }
Ejemplo n.º 5
0
            void insert(astar_node_t* element)
            {
                if( finder.find(element) != finder.end() )
                {
                    PRX_WARN_S("Element already exists in open set, should be using update instead.");
                    return;
                }
//                PRX_DEBUG_COLOR("Heap size: " << heap.size() << "    heap_size: " << heap_size, PRX_TEXT_LIGHTGRAY);
                if( heap.size() > heap_size )
                {
                    heap[heap_size] = element;
                }
                else
                {
                    heap.push_back(element);
                }
                heap_size++;
                finder[element] = heap_size - 1;
                reheap_up(heap_size - 1);
            }
Ejemplo n.º 6
0
int ZCE_Timer_Heap::remove_nodeid(int timer_node_id)
{

    assert(size_heap_ > 0);

    if (size_heap_ == 0)
    {
        //看你妹呀,瞎填参数
        return -1;
    }

    size_t delete_heap_id = note_to_heapid_[timer_node_id];

    //
    note_to_heapid_[timer_node_heap_[delete_heap_id]] = INVALID_TIMER_ID;
    timer_node_heap_[delete_heap_id] = INVALID_TIMER_ID;

    --size_heap_;

    //数量为0不旋转
    if (size_heap_ == 0)
    {
        return 0;
    }

    //将最后一个堆放到删除的位置,进行调整
    timer_node_heap_[delete_heap_id] = timer_node_heap_[size_heap_];
    note_to_heapid_[timer_node_heap_[delete_heap_id]] = static_cast<int>( delete_heap_id);
    timer_node_heap_[size_heap_] = INVALID_TIMER_ID;

    //看是否需要向上调整
    bool alread_up = reheap_up(delete_heap_id);

    //如果不需要向上调整,看是否需要向下调整
    if ( !alread_up )
    {
        reheap_down(delete_heap_id);
    }

    return 0;
}
Ejemplo n.º 7
0
static pj_timer_entry * remove_node( pj_timer_heap_t *ht, size_t slot)
{
    pj_timer_entry *removed_node = ht->heap[slot];
    
    // Return this timer id to the freelist.
    push_freelist( ht, removed_node->_timer_id );
    
    // Decrement the size of the heap by one since we're removing the
    // "slot"th node.
    ht->cur_size--;
    
    // Set the ID
    removed_node->_timer_id = -1;

    // Only try to reheapify if we're not deleting the last entry.
    
    if (slot < ht->cur_size)
    {
	int parent;
	pj_timer_entry *moved_node = ht->heap[ht->cur_size];
	
	// Move the end node to the location being removed and update
	// the corresponding slot in the parallel <timer_ids> array.
	copy_node( ht, slot, moved_node);
	
	// If the <moved_node->time_value_> is great than or equal its
	// parent it needs be moved down the heap.
	parent = HEAP_PARENT (slot);
	
	if (PJ_TIME_VAL_GTE(moved_node->_timer_value, ht->heap[parent]->_timer_value))
	    reheap_down( ht, moved_node, slot, HEAP_LEFT(slot));
	else
	    reheap_up( ht, moved_node, slot, parent);
    }
    
    return removed_node;
}