예제 #1
0
void shift_down(int* d, int i, int c)
{
    if (i >= c - 1) // i已到达堆尾
        return;

    int li = left(i);
    int ri = right(i);

    int l = li < c ? d[li] : -1;
    int r = ri < c ? d[ri] : -1;

    if (d[i] >= l && d[i] >= r) // d[i]不小于左右节点,符合最大堆要求,不需要继续往下检查。
        return;

    if (l > r) // d[i]与左右节点间较大的一个交换,并继续往下检查。
    {
        swap(d, i, li);
        shift_down(d, li, c);
    }
    else
    {
        swap(d, i, ri);
        shift_down(d, ri, c);
    }
}
예제 #2
0
int VFadePatch::handle_event()
{
	if(shift_down())
	{
		update(100);
		set_tooltip(get_caption());
	}

	patch->change_source = 1;

	float change = update_edl();

	if(patch->track->gang) 
		patch->patchbay->synchronize_faders(change, TRACK_VIDEO, patch->track);

	patch->change_source = 0;


	mwindow->gui->unlock_window();
	mwindow->restart_brender();
	mwindow->sync_parameters(CHANGE_PARAMS);
	mwindow->gui->lock_window("VFadePatch::handle_event");
	if(mwindow->edl->session->auto_conf->autos[AUTOMATION_FADE])
	{
		mwindow->gui->canvas->draw_overlays();
		mwindow->gui->canvas->flash();
	}
	return 1;
}
예제 #3
0
파일: ScrView.cpp 프로젝트: KB3NZQ/hexedit4
void CScrView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	if (mouse_down_) return;    // Happens sometimes while debugging

	// Keep control of the pointer until mouse button released
	mouse_down_ = TRUE;

	// Create timer so that we regularly call OnSelUpdate when the mouse is
	// stationery outside the window so that the window is automatically 
	// scrolled (see OnTimer below for what the timer does).
	VERIFY(timer_id_ = SetTimer(1, 100, NULL));

	// Hide caret while dragging.  Plus: calling caret_hide here also means
	// that the caret is displayed in the correct position when caret_show
	// is called at the end of the drag (in OnLButtonUp below).
	caret_hide();
	SetCapture();

	if (shift_down())
	{
		// Shift click restarts selection from where it left off (on button up)
		OnSelUpdate(point);
	}
	else
	{
		// Move caret to where selection started
		CPointAp newpos = ConvertFromDP(point);
		ValidateCaret(newpos, FALSE);
		SetCaret(newpos);
	}

	CView::OnLButtonDown(nFlags, point);
}
예제 #4
0
int SynthNote::button_press_event()
{
	if(BC_Toggle::button_press_event())
	{
// printf("SynthNote::button_press_event %d %d %d\n", 
// __LINE__, 
// ctrl_down(), 
// window->synth->freq_exists(keyboard_freqs[number]));
		window->starting_notes = 1;
		if((ctrl_down() || shift_down()) &&
			window->synth->freq_exists(keyboard_freqs[number]))
		{
//printf("SynthNote::button_press_event %d\n", __LINE__);
			stop_note();
			window->starting_notes = 0;
		}
		else
		{
//printf("SynthNote::button_press_event %d\n", __LINE__);
			start_note();
			window->starting_notes = 1;
		}
		window->current_note = number;
		return 1;
	}
	return 0;
}
예제 #5
0
int pop(Heap *heap) {
  assert(heap && heap->arr);
  int data = heap->arr[1];
  heap->arr[1] = heap->arr[heap->size];
  heap->size -= 1;
  shift_down(heap, 1);
  return data;
}
예제 #6
0
 void heap_delete(int id) {
     assert(n > 0);
     int cur = id2heap[id];
     swap(heap[cur], heap[n-1]);
     swap(id2heap[heap[cur].second], id2heap[id]);
     n--;
     shift_down(cur);
 }
예제 #7
0
inline void to_heap(std::vector<BinaryTreeChromosome *>* arr, size_t size){
	int i = static_cast<int>(size / 2) - 1;

    while (i >= 0) {
        shift_down(arr, i, size);
        --i;
    }
}
예제 #8
0
void HeapSort::Sort(std::vector<BinaryTreeChromosome *>* array, size_t size){
    to_heap(array, size);
	size_t end = size - 1;
    while (end > 0) {
        std::swap(array->at(0), array->at(end));
        shift_down(array, 0, end);
        --end;
    }
}
예제 #9
0
int can_move_down(board *b)
{
	board *tmp;

	tmp = dup_board(b);

	shift_down(tmp);
	merge_down(tmp);
	shift_down(tmp);

	if (cmp_board(b, tmp)) {
		free(tmp);
		return 0;
	} else {
		free(tmp);
		return 1;
	}
}
예제 #10
0
void to_heap(int arr[], int N) 
{
    int i = (N/2) - 1;
    while(i >= 0) 
    {
        shift_down(arr, i, N);
        --i;
    }
}
예제 #11
0
void heap_sort(int* d, int c)
{
    max_heap_construction(d, c); // 先建立最大堆
    while (c >= 2)
    {
        swap(d, 0, --c); // 每次迭代把root去除,也就是把根节点与堆最后一个节点交换,堆的大小减一。
        shift_down(d, 0, c); // 交换后,需要用shift_down重新恢复最大堆性质。
    }
}
예제 #12
0
파일: priqueue.cpp 프로젝트: fastdft/alg
T PriQueue<T>::extract_min()
{
	if (m_now_size <= 0)
		return ;
	T min_value = m_data[1];
	m_data[1] = m_data[m_now_size--];
	shift_down();

	return min_value;
}
예제 #13
0
int Heap::pop() {
	int x = h[1];		// 取出堆顶元素
	pos[x] = 0;

	h[1] = h[sum--];
	pos[h[1]] = 1;
	shift_down(h[1]);	// 调整剩下的元素

	return x;
}
예제 #14
0
void heap_sort(int arr[], int N)
 {
    to_heap(arr, N);
    int end = N - 1;
    while (end > 0) 
    {
        std::swap(arr[0], arr[end]);
        shift_down(arr, 0, end);
        --end;
    }
}
heap_node remove_min (heap_node *heap, int32_t size) {
    heap_node rv = heap[1];
    
    heap[1] = heap[size];
    
    --size;
    
    shift_down(heap, size, 1);
    
    return rv;
}
예제 #16
0
TimerPtr TimerHeap::pop()
{
    if (timers_.empty())
        return nullptr;
    TimerPtr timer = timers_[0];
    TimerPtr last = timers_[timers_.size() - 1];
    timers_.pop_back();
    shift_down(0, last);
    if (!timer->repeat_)
        ids_.erase(timer->id_);
    return timer;
}
예제 #17
0
 void shift_down(int cur) {
     int v = cur;
     if (cur*2+1 < n && heap[cur*2+1].first > heap[v].first)
         v = cur*2+1;
     if (cur*2+2 < n && heap[cur*2+2].first > heap[v].first)
         v = cur*2+2;
     if (v != cur) {
         swap(heap[cur], heap[v]);
         swap(id2heap[heap[cur].second], id2heap[heap[v].second]);
         shift_down(v);
     }
 }
예제 #18
0
sem_success sem_dynamic_array_remove(sem_dynamic_array* array, void* item) {
	uint32_t i=0;
	for (; i<array->tail_idx; i++) {
		if (array->items[i] == item) break;
	}
	if (i == array->tail_idx) return sem_set_error("Cannot remove item that is not in dynamic array");
	
	shift_down(array, i+1);
	array->tail_idx--;

	return SEM_OK;
}
예제 #19
0
bool TimerHeap::cancel(TimerPtr timer)
{
    int index = timer->heap_index_;
    if (index < 0 || index >= (int)timers_.size())
        return false;
    TimerPtr last = timers_[timers_.size() - 1];
    timers_.pop_back();
    int parent = PARENT(index);
    if (index > 0 && timers_[parent] > last)
        shift_up(index, last);
    else
        shift_down(index, last);
    timer->heap_index_ = -1;
    ids_.erase(timer->id_);
    return true;
}
//static void printHeap(const Node*heap, int len) {
//    int i;
//    printf("Heap: ");
//    for(i = 0; i < len; i++) {
//        printf("%.6f ", heap[i].dist);
//    }
//    printf("\n");
//}
static void processList(const Point2* list, const int lo, const int la, 
                        Node* heap, int* len) {
	
	int64 errLo, errLa, dist;
	int count;
	
    if (!list) {
        return;
    }
    count = 0;
    while(list) {
    	errLo = list->lo0 - lo;
    	errLa = list->la0 - la;
    	

    	// 采用 dist^2来比较大小
    	dist = (long long)errLo * errLo + (long long)errLa * errLa;
#ifdef VERBOSE1
    	if (list->lo0 == 12957035 && list->la0 == 4838017) {
    	    printf("== %15lld, %10lld %10lld %d\n", dist, errLo, errLa, (int)sqrt(dist));
    	}
#endif
        
        if (*len < NEIBOR_NUM) {
            Node* node = heap + ((*len)++);
            node->dist = dist;
            node->pt = list;
            
            shift_up(heap, *len);
        } else {
        	if (dist < heap[0].dist) {
        	    
        	    (*len)--;
        	    shift_down(heap, *len);
        	    
        	    Node* node = heap + ((*len)++);
        	    node->dist = dist;
        	    node->pt = list;
        	    shift_up(heap, *len);
        	}
        }
        count++;
        list = list->next;
    }
    
    // printf("List Length: %d\n", count);
}
예제 #21
0
파일: patch.C 프로젝트: Cuchulain/cinelerra
int PlayPatchOld::handle_event()
{
// get the total selected before this event
	if(shift_down())
	{
		int total_selected = patches->plays_selected();

		if(total_selected == 0)
		{
// nothing previously selected
			patches->select_all_play();
		}
		else
		if(total_selected == 1)
		{
			if(patch->play)
			{
// this patch was previously the only one on
				patches->select_all_play();
			}
			else
			{
// another patch was previously the only one on
				patches->deselect_all_play();
				patch->play = 1;
			}
		}
		else
		if(total_selected > 1)
		{
			patches->deselect_all_play();
			patch->play = 1;
		}
		
		update(patch->play);
	}
	else
	{
		patch->play = get_value();
	}
	patches->button_down = 1;
	patches->reconfigure_trigger = 1;
	patches->new_status = get_value();
	return 1;
}
예제 #22
0
void SynthNote::start_note()
{
	if(window->synth->config.momentary_notes) note_on = 1;

//printf("SynthNote::start_note %d %d\n", __LINE__, ctrl_down());
	if(window->synth->config.momentary_notes || (!ctrl_down() && !shift_down()))
	{
// Kill all frequencies
		window->synth->delete_freqs();
	}

	window->synth->new_freq(keyboard_freqs[number]);
	window->base_freq->update((float)window->synth->config.base_freq[0]);
//printf("SynthNote::start_note %d %f\n", __LINE__, window->synth->config.base_freq[0]);
	window->freqpot->update(window->synth->config.base_freq[0]);
	window->synth->send_configure_change();
	window->update_note_selection();
}
예제 #23
0
파일: patch.C 프로젝트: Cuchulain/cinelerra
int DrawPatchOld::handle_event()
{
// get the total selected before this event
	if(shift_down())
	{
		int total_selected = patches->draws_selected();

		if(total_selected == 0)
		{
// nothing previously selected
			patches->select_all_draw();
		}
		else
		if(total_selected == 1)
		{
			if(patch->draw)
			{
// this patch was previously the only one on
				patches->select_all_draw();
			}
			else
			{
// another patch was previously the only one on
				patches->deselect_all_draw();
				patch->draw = 1;
			}
		}
		else
		if(total_selected > 1)
		{
			patches->deselect_all_draw();
			patch->draw = 1;
		}
		
		update(patch->draw);
	}
	else
	{
		patch->draw = get_value();
	}
	patches->button_down = 1;
	patches->new_status = get_value();
	return 1;
}
예제 #24
0
파일: ScrView.cpp 프로젝트: KB3NZQ/hexedit4
void CScrView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	switch(nChar)
	{
	case VK_LEFT:
	case VK_RIGHT:
	case VK_UP:
	case VK_DOWN:
	case VK_HOME:
	case VK_END:
	case VK_PRIOR:
	case VK_NEXT:
		if (MovePos(nChar, nRepCnt, control_down(), shift_down(), caret_mode_))
		{
			DisplayCaret();
			return;
		}
		break;
	}
	CView::OnKeyDown(nChar, nRepCnt, nFlags);
}
예제 #25
0
void VTimeBar::select_label(double position)
{
	EDL *edl = get_edl();

	if(edl)
	{
		unlock_window();
		gui->transport->handle_transport(STOP, 1, 0, 0);
		lock_window();

		position = mwindow->edl->align_to_frame(position, 1);

		if(shift_down())
		{
			if(position > edl->local_session->get_selectionend(1) / 2 + 
				edl->local_session->get_selectionstart(1) / 2)
			{

				edl->local_session->set_selectionend(position);
			}
			else
			{
				edl->local_session->set_selectionstart(position);
			}
		}
		else
		{
			edl->local_session->set_selectionstart(position);
			edl->local_session->set_selectionend(position);
		}

// Que the CWindow
		gui->vwindow->update_position(CHANGE_NONE, 
			0, 
			1,
			0);
		update(1);
	}
}
예제 #26
0
int SynthNote::keypress_event()
{
	if(number >= FIRST_TITLE && number < LAST_TITLE)
	{
		if(get_keypress() == keyboard_map[number - FIRST_TITLE][0])
		{
			if((ctrl_down() || shift_down()) &&
				window->synth->freq_exists(keyboard_freqs[number]))
			{
				stop_note();
			}
			else
			{
				start_note();
				set_value(1);
			}

// Key releases are repeated, so momentary notes may not work
			return 1;
		}
	}
	return 0;
}
예제 #27
0
void play_game()
{
	board *b = &grid;

	do {

		switch (os_wait_for_key()) {
			case ESC_KEY:
				return;

			case UP_KEY:
				if (can_move_up(b)) {
					shift_up(b);
					merge_up(b);
					shift_up(b);
					add_big_int(&score, &merge_score);
					break;
				} else {
					continue;
				}

			case DOWN_KEY:
				if (can_move_down(b)) {
					shift_down(b);
					merge_down(b);
					shift_down(b);
					add_big_int(&score, &merge_score);
					break;
				} else {
					continue;
				}

			case LEFT_KEY:
				if (can_move_left(b)) {
					shift_left(b);
					merge_left(b);
					shift_left(b);
					add_big_int(&score, &merge_score);
					break;
				} else {
					continue;
				}

			case RIGHT_KEY:
				if (can_move_right(b)) {
					shift_right(b);
					merge_right(b);
					shift_right(b);
					add_big_int(&score, &merge_score);
					break;
				} else {
					continue;
				}

			default:
				continue;
		}

		add_tile(b);
		display_board(b);

	} while (!game_is_lost());
}
예제 #28
0
/* $e <- e/x$ */
static void gf3m_shift_down(element_t e) {
    shift_down(LEN(e), DATA1(e));
    shift_down(LEN(e), DATA2(e));
}
예제 #29
0
int PerspectiveCanvas::button_press_event()
{
	if(is_event_win() && cursor_inside())
	{
// Set current point
		int x1, y1, x2, y2, x3, y3, x4, y4;
		int cursor_x = get_cursor_x();
		int cursor_y = get_cursor_y();
		plugin->thread->window->calculate_canvas_coords(x1, y1, x2, y2, x3, y3, x4, y4);

		float distance1 = DISTANCE(cursor_x, cursor_y, x1, y1);
		float distance2 = DISTANCE(cursor_x, cursor_y, x2, y2);
		float distance3 = DISTANCE(cursor_x, cursor_y, x3, y3);
		float distance4 = DISTANCE(cursor_x, cursor_y, x4, y4);
// printf("PerspectiveCanvas::button_press_event %f %d %d %d %d\n", 
// distance3,
// cursor_x,
// cursor_y,
// x3,
// y3);
		float min = distance1;
		plugin->config.current_point = 0;
		if(distance2 < min)
		{
			min = distance2;
			plugin->config.current_point = 1;
		}
		if(distance3 < min)
		{
			min = distance3;
			plugin->config.current_point = 2;
		}
		if(distance4 < min)
		{
			min = distance4;
			plugin->config.current_point = 3;
		}

		if(plugin->config.mode == AffineEngine::SHEER)
		{
			if(plugin->config.current_point == 1)
				plugin->config.current_point = 0;
			else
			if(plugin->config.current_point == 2)
				plugin->config.current_point = 3;
		}
		start_cursor_x = cursor_x;
		start_cursor_y = cursor_y;

		if(alt_down() || shift_down())
		{
			if(alt_down())
				state = PerspectiveCanvas::DRAG_FULL;
			else
				state = PerspectiveCanvas::ZOOM;

// Get starting positions
			start_x1 = plugin->config.x1;
			start_y1 = plugin->config.y1;
			start_x2 = plugin->config.x2;
			start_y2 = plugin->config.y2;
			start_x3 = plugin->config.x3;
			start_y3 = plugin->config.y3;
			start_x4 = plugin->config.x4;
			start_y4 = plugin->config.y4;
		}
		else
		{
			state = PerspectiveCanvas::DRAG;

// Get starting positions
			start_x1 = plugin->get_current_x();
			start_y1 = plugin->get_current_y();
		}
		plugin->thread->window->update_coord();
		plugin->thread->window->update_canvas();
		return 1;
	}

	return 0;
}