Esempio n. 1
0
int ObjCache::add(void *obj,void **victim)
{
  *victim=0;

  HashNode *hnode = hashFind(obj);
  //printf("hnode=%p\n",hnode);
  if (hnode) // move object to the front of the LRU list, since it is used
    // most recently
  {
    //printf("moveToFront=%d\n",hnode->index);
    moveToFront(hnode->index);
    m_hits++;
  }
  else // object not in the cache.
  {
    void *lruObj=0;
    if (m_freeCacheNodes!=-1) // cache not full -> add element to the cache
    {
      // remove element from free list
      int index = m_freeCacheNodes;
      m_freeCacheNodes = m_cache[index].next;

      // add to head of the list
      if (m_tail==-1)
      {
        m_tail = index;
      }
      m_cache[index].prev = -1;
      m_cache[index].next = m_head;
      if (m_head!=-1)
      {
        m_cache[m_head].prev = index;
      }
      m_head = index;
      m_count++;
    }
    else // cache full -> replace element in the cache
    {
      //printf("Cache full!\n");
      lruObj = m_cache[m_tail].obj;
      hashRemove(lruObj);
      moveToFront(m_tail); // m_tail indexes the emptied element, which becomes m_head
    }
    //printf("numEntries=%d size=%d\n",m_numEntries,m_size);
    m_cache[m_head].obj = obj;
    hnode = hashInsert(obj);
    hnode->index = m_head;
    *victim = lruObj;
    m_misses++;
  }
  return m_head;
}
Esempio n. 2
0
void RecentFile::selectRecentFile(const QString &filePath)
{
    QByteArray securityTokenData;
    moveToFront(filePath);
    securityTokenData = d->securityTokenData.first();
    SecurityToken *securityToken = SecurityToken::create(securityTokenData);
    emit recentFileSelected(filePath, securityToken);
    securityToken->release();
    securityToken = nullptr;
}
Esempio n. 3
0
void addRandom(Node*& node)
{
	moveToFront(node);
	for (int i = 0; i < 5; i++)
	{
		insert(node, new Node());
		node->id = 228 + rand() % 5;
		node->group = 1 + rand() % 31;
		for (int i = 0; i < 3 + rand() % 4; i++)
			node->name += 'a' + rand() % ('z' - 'a' + 1);
	}
}
Esempio n. 4
0
/*************************************************************************
	Tells the popup menu to open.
*************************************************************************/
void PopupMenu::openPopupMenu(bool notify)
{
    // already open and not fading, or fading in?
    if (d_isOpen && (!d_fading || !d_fadingOut))
    {
        // then don't do anything
        return;
    }

    // should we let the parent menu item initiate the open?
    Window* parent = getParent();
    if (notify && parent && parent->testClassName("MenuItem"))
    {
        static_cast<MenuItem*>(parent)->openPopupMenu();
        return; // the rest will be handled when MenuItem calls us itself
    }

    // we'll handle it ourselves then.
	// are we fading, and fading out?
	if (d_fading && d_fadingOut)
	{
		if (d_fadeInTime>0.0f&&d_fadeOutTime>0.0f)
		{
			// jump to the point of the fade in that has the same alpha as right now - this keeps it smooth
			d_fadeElapsed = ((d_fadeOutTime-d_fadeElapsed)/d_fadeOutTime)*d_fadeInTime;
		}
		else
		{
			// start the fade in from the beginning
			d_fadeElapsed = 0;
		}
		// change to fade in
		d_fadingOut=false;
	}
	// otherwise just start normal fade in!
	else if (d_fadeInTime>0.0f)
	{
		d_fading = true;
		d_fadingOut=false;
		setAlpha(0.0f);
		d_fadeElapsed = 0;
	}
	// should not fade!
	else
	{
		d_fading = false;
		setAlpha(d_origAlpha);
	}
	
	show();
	moveToFront();
}
void DisplayGroupGraphicsView::addContentWindow( ContentWindowPtr contentWindow )
{
    assert( displayGroup_ );

    ContentWindowGraphicsItem* cwgi = new ContentWindowGraphicsItem( contentWindow );
    scene()->addItem( static_cast< QGraphicsItem* >( cwgi ) );

    connect( cwgi, SIGNAL( moveToFront( ContentWindowPtr )),
             displayGroup_.get(),
             SLOT( moveContentWindowToFront( ContentWindowPtr )));

    connect( cwgi, SIGNAL( close( ContentWindowPtr )),
             displayGroup_.get(),
             SLOT( removeContentWindow( ContentWindowPtr )));
}
// call with lock held
void SoundPool::done(SoundChannel* channel)
{
    LOGV("done(%d)", channel->channelID());

    // if "stolen", play next event
    if (channel->nextChannelID() != 0) {
        LOGV("add to restart list");
        addToRestartList(channel);
    }

    // return to idle state
    else {
        LOGV("move to front");
        moveToFront(channel);
    }
}
Esempio n. 7
0
void removeByGroup(Node*& node, int group)
{
	if (!node)
		return;

	moveToFront(node);

	while (node->group == group)
		remove(node);

	for (Node* n = node; n; n = n->next)
	{
		if (n->group == group)
			remove(n);
	}
}
Esempio n. 8
0
void sort(Node* index)
{
	moveToFront(index);

	if (!index || !index->next)
		return;

	for (Node* i = index; i->next; i = i->next)
	{
		for (Node* j = index; j->next; j = j->next)
		{
			if (j->group > j->next->group)
				swap(j, j->next);
		}
	}
}
Esempio n. 9
0
void printAll(Node* node)
{
	if (!node)
	{
		cout << "Список пуст" << endl;
		return;
	}

	moveToFront(node);
	cout << "Номер зачетки\tГруппа\tИмя" << endl;
	do
	{
		node->print();
		node = node->next;
	} while (node);
}
Esempio n. 10
0
void hDialog::mousePressed(int xx, int yy, int btn)
{
    hPanel::mousePressed(xx, yy, btn);

    clickedX    = xx;
    clickedY    = yy;
    clickedXpos = xx-x;
    clickedYpos = yy-y;
    xShift      = 0;
    yShift      = 0;

    moveToFront();
    checkMouseInTopBar();

    // cout << "clickedXpos " << clickedXpos << endl;
    // cout << "clickedYpos " << clickedYpos << endl;
}
Esempio n. 11
0
void ObjCache::del(int index)
{
  assert(index!=-1);
  assert(m_cache[index].obj!=0);
  hashRemove(m_cache[index].obj);
  moveToFront(index);
  m_head = m_cache[index].next;
  if (m_head==-1) 
    m_tail=-1;
  else 
    m_cache[m_head].prev=-1;
  m_cache[index].obj=0;
  m_cache[index].prev=-1;
  m_cache[index].next = m_freeCacheNodes;
  m_freeCacheNodes = index;
  m_count--;
}
int pushRelabel(const int **C, int **F, int source, int sink) {
	int *excess, *height, *list, *seen, i, p;

	excess = (int *) calloc(NODES, sizeof(int));
	height = (int *) calloc(NODES, sizeof(int));
	seen = (int *) calloc(NODES, sizeof(int));

	list = (int *) calloc((NODES-2), sizeof(int));

	for (i = 0, p = 0; i < NODES; ++i){
		if((i != source) && (i != sink)) {
			list[p] = i;
			++p;
		}
	}

	height[source] = NODES;
	excess[source] = INFINITE;
	for (i = 0; i < NODES; ++i)
		push(C, F, excess, source, i);

	p = 0;
	while (p < NODES - 2) {
		int u = list[p];
		int old_height = height[u];
		discharge(C, F, excess, height, seen, u);
		if (height[u] > old_height) {
			moveToFront(p,list);
			p=0;
		}
		else
			p += 1;
	}
	int maxflow = 0;
	for (i = 0; i < NODES; ++i)
		maxflow += F[source][i];

	free(list);

	free(seen);
	free(height);
	free(excess);

	return maxflow;
}
Esempio n. 13
0
	bool Combobox::onLoad(void)
	{
		m_btn = child("_Btn");
		if(m_btn)
		{
			m_btn->setAlwaysOnTop(true);
			moveToFront(m_btn.get());
			subscribe<events::ClickEvent, Combobox> (&Combobox::onBtnClick, m_btn.get());
		}
		m_list = child("_List");
		if(m_list)
		{
			m_list->setAlwaysOnTop(true);
			m_list->setVisible(false);
			subscribe<events::ClickEvent, Combobox> (&Combobox::onListClick, m_list.get());
		}
		return Editbox::onLoad();
	}
Esempio n. 14
0
void insertSpacel(Node*& index, Node* newNode)
{
	if (!index)
		return;

	moveToFront(index);

	if (index->id < newNode->id)
		insert(index, newNode);
	else
	{
		Node* n = index;
		while (n && n->id >= newNode->id)
			n = n->next;

		if (n)
			insert(n, newNode);
	}
}
Esempio n. 15
0
/**
 * @brief MenuActions::windowsChanged
 *
 * Slot invoked when the HashCalcApplication window manager has closed a window.
 * Updates the list of other windows in the window menu.
 */
void MenuActions::windowsChanged()
{
   while(!windowlistActions.isEmpty()) {
      QAction* currAction = windowlistActions.last();
      windowlistActions.remove(windowlistActions.size()-1);
      windowMenu->removeAction(currAction);
      delete currAction;
   }
   for (int i=0; i < parent()->parent()->mainwindows.count(); i++) {
      MainWindow* currWindow = parent()->parent()->mainwindows[i];
      QAction* newAction = new QAction(currWindow->windowTitle(), parent());
      if (i < 10) {
         newAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_1 + i));
      }
      connect(newAction, SIGNAL(triggered()), currWindow, SLOT(moveToFront()));
      windowMenu->addAction(newAction);
      windowlistActions.push_back(newAction);
   }
}
Esempio n. 16
0
bool base_window::onLoad(void)
{
	onMoved();
	if(m_alwaysOnTop)
		moveToFront();

	HandlerMap::iterator it = m_handlers.find("On_Draw");
	if(it != m_handlers.end())
	{
		m_drawhandler = it->second;
		if(!m_drawhandler.empty())
		{
			m_customDraw = true;
		}
	}

	EventArgs a;
	a.name = "On_Load";
	callHandler(&a);
	return a.handled; 
}
/* Druver program to test above function */
int main()
{
  struct node *start = NULL;   
 
  /* The constructed linked list is:
   1->2->3->4->5 */
  push(&start, 5);
  push(&start, 4);
  push(&start, 3);
  push(&start, 2);
  push(&start, 1);
 
  printf("\n Linked list before moving last to front ");
  printList(start);
 
  moveToFront(&start);
 
  printf("\n Linked list after removing last to front ");
  printList(start);
 
  getchar();
}        
void ContentWindowGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent * event)
{
    // on Mac we've seen that mouse events can go to the wrong graphics item
    // this is due to the bug: https://bugreports.qt.nokia.com/browse/QTBUG-20493
    // here we ignore the event if it shouldn't have been sent to us, which ensures
    // it will go to the correct item...
    if(boundingRect().contains(event->pos()) == false)
    {
        event->ignore();
        return;
    }

    // button dimensions
    float buttonWidth, buttonHeight;
    getButtonDimensions(buttonWidth, buttonHeight);

    // item rectangle and event position
    QRectF r = rect();
    QPointF eventPos = event->pos();

    // check to see if user clicked on the close button
    if(fabs((r.x()+r.width()) - eventPos.x()) <= buttonWidth && fabs((r.y()) - eventPos.y()) <= buttonHeight)
    {
        close();

        return;
    }

    // check to see if user clicked on the resize button
    if(fabs((r.x()+r.width()) - eventPos.x()) <= buttonWidth && fabs((r.y()+r.height()) - eventPos.y()) <= buttonHeight)
    {
        resizing_ = true;
    }

    // move to the front of the GUI display
    moveToFront();

    QGraphicsItem::mousePressEvent(event);
}
Esempio n. 19
0
GUI_status DraggableView::MouseDown(int x, int y, int button)
{
	if(bg_image && HitRect(x, y))
	{
		Uint32 pixel = sdl_getpixel(bg_image, x - area.x, y - area.y);
		if(pixel == bg_color_key)
		{
			return GUI_PASS;
		}
	}
 drag = true;
 button_x = x;
 button_y = y;

 moveToFront();
 if(Game::get_game()->is_new_style())
 {
	 Game::get_game()->get_scroll()->moveToFront();
 }
 grab_focus();

 return GUI_YUM;
}
Esempio n. 20
0
int main()
{
	int n, i, e; // variables for the number of patients, an iterator and the ID of an emergency
	char c = '\0'; // variable for the commands

	// Getting the number of patients
	scanf("%d", &n);

	// Initializing the queue
	initializeQueue();

	// Enqueing all of the patients
	for (i = 1; i <= n; i++)
	{
		enqueue(i);
	}

	// Scanning the commands
	while (c != 'F')
	{
		scanf("%c", &c);

		switch(c)
		{
			case 'A':
				printf("%d ", dequeue());
				break;

			case 'E':
				scanf("%d ", &e);
				moveToFront(e);
				break;
		}
	}
	
	return 0;
}
void ContentWindowGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent * event)
{
    // on Mac we've seen that mouse events can go to the wrong graphics item
    // this is due to the bug: https://bugreports.qt.nokia.com/browse/QTBUG-20493
    // here we ignore the event if it shouldn't have been sent to us, which ensures
    // it will go to the correct item...
    if(boundingRect().contains(event->pos()) == false)
    {
        event->ignore();
        return;
    }

    // button dimensions
    float buttonWidth, buttonHeight;
    getButtonDimensions(buttonWidth, buttonHeight);

    // item rectangle and event position
    QRectF r = boundingRect();
    QPointF eventPos = event->pos();

    // check to see if user clicked on the close button
    if(fabs((r.x()+r.width()) - eventPos.x()) <= buttonWidth &&
       fabs(r.y() - eventPos.y()) <= buttonHeight)
    {
        close();

        return;
    }

    // move to the front of the GUI display
    moveToFront();

    ContentWindowManagerPtr contentWindow = getContentWindowManager();
    if (!contentWindow)
        return;

    if (selected())
    {
        contentWindow->getInteractionDelegate().mousePressEvent(event);
        return;
    }

    contentWindow->getContent()->blockAdvance( true );

    // check to see if user clicked on the resize button
    if(fabs((r.x()+r.width()) - eventPos.x()) <= buttonWidth &&
       fabs((r.y()+r.height()) - eventPos.y()) <= buttonHeight)
    {
        resizing_ = true;
    }
    // check to see if user clicked on the fullscreen button
    else if(fabs(r.x() - eventPos.x()) <= buttonWidth &&
            fabs((r.y()+r.height()) - eventPos.y()) <= buttonHeight)
    {
        toggleFullscreen();
    }
    else if(fabs(((r.x()+r.width())/2) - eventPos.x() - buttonWidth) <= buttonWidth &&
            fabs((r.y()+r.height()) - eventPos.y()) <= buttonHeight &&
            g_configuration->getOptions()->getShowMovieControls( ))
    {
        contentWindow->setControlState( ControlState(contentWindow->getControlState() ^ STATE_PAUSED) );
    }
    else if(fabs(((r.x()+r.width())/2) - eventPos.x()) <= buttonWidth &&
            fabs((r.y()+r.height()) - eventPos.y()) <= buttonHeight &&
            g_configuration->getOptions()->getShowMovieControls( ))
    {
        contentWindow->setControlState( ControlState(contentWindow->getControlState() ^ STATE_LOOP) );
    }
    else
        moving_ = true;

    QGraphicsItem::mousePressEvent(event);
}
Esempio n. 22
0
void pushRelabel(Edge **C, int **F, int nNodes, int source, int sink
                /* , int *maxFlow, double *probability */)
{
    int *excess, *height, *list, *seen, i, /* j, */ p;
    int *sequenceList;
    /* int  *constList; */

    excess = (int *)calloc(nNodes, sizeof(int));
    height = (int *)calloc(nNodes, sizeof(int));
    seen = (int *)calloc(nNodes, sizeof(int));

    sequenceList = (int *)calloc(nNodes, sizeof(int));
    bfs(C, nNodes, sink, sequenceList);

    list = (int *)calloc(nNodes-2, sizeof(int));
    /* constList = (int *)calloc(nNodes-2, sizeof(int)); */

    /* for (i = 0, p = 0; i < nNodes; i++) { */
    /*     if (sequenceList[i] != source && */
    /*         sequenceList[i] != sink) { */
    /*         list[p] = sequenceList[i]; */
    /*         p++; */
    /*     } */
    /* } */

    for (i = 0, p = 0; i < nNodes; i++) {
        if ((i != source) && (i != sink)) {
            list[p] = i;
            /* constList[p] = i; */
            p++;
        }
    }

    height[source] = nNodes;
    excess[source] = INFINITE;
    for (i = 0; i < nNodes; i++)
        push(C, F, excess, source, i);

    p = 0;
    while (p < nNodes-2) {
        int u = list[p];
        int old_height = height[u];
        discharge(C, F, nNodes, excess, height, seen, sequenceList, u);
        if (height[u] > old_height) {
            /* memcpy(list, constList, (nNodes -2) * sizeof(int)); */
            moveToFront(p, list);
            p = 0;
        } else {
            p += 1;
        }
    }

    /* *maxFlow = 0; */
    /* for (i = 0; i < nNodes; i++) */
    /*     *maxFlow += F[source][i]; */

    /* *probability = 1; */
    /* for (i = 0; i < nNodes; i++) */
    /*     for (j = 0; j < nNodes; j++) */
    /*         if (F[i][j] > 0) */
    /*             *probability *= C[i][j].eProbability; */

    free(excess);
    free(height);
    free(seen);
    free(sequenceList);
    free(list);

}
Esempio n. 23
0
void ViewManager::addView(View *view) {
	_views.push_back(view);
	moveToFront(view);
}