Esempio n. 1
0
 /*
  * @param key: An integer
  * @return: An integer
  */
 int get(int key) {
     // 1. access the cached items map
     // 2. update the key as the most recent used cache
     if (!cacheMap.count(key)) return -1;
     Node* item = cacheMap[key];
     updateCache(item);
     return item->value;
 }
 int get(int key) {
     if(dict.find(key) == dict.end())
         return -1;
     int value = 0;
     value = dict[key].second->second;
     updateCache(key, value);
     return value;
 }
Esempio n. 3
0
 CachedPlanRunner::~CachedPlanRunner() {
     // The runner may produce all necessary results without
     // hitting EOF. In this case, we still want to update
     // the cache with feedback.
     if (!_updatedCache) {
         updateCache();
     }
 }
Esempio n. 4
0
//-----------------------------------------------------------------------
void SMBUrl::addPath(const QString &filedir)
{
    if(path().length() > 0 && path().at(path().length() - 1) != QLatin1Char('/')) {
        QUrl::setPath(path() + QLatin1Char('/') + filedir);
    } else {
        QUrl::setPath(path() + filedir);
    }
    updateCache();
}
Esempio n. 5
0
toBrowserSchemaTableView::toBrowserSchemaTableView(QWidget * parent, const QString &type)
    : toResultTableView(true, false, parent),
      toBrowserSchemaBase()
{
    ObjectType = type;
    ForceRequery = false;
    if (!type.isEmpty())
        connect(this, SIGNAL(done()), this, SLOT(updateCache()));
}
void AvatarButton::leaveEvent(QEvent *event)
{
	QToolButton::leaveEvent(event);
	mouseIsHovered = false;

	setIconSize(getIconSizeHint());
	
	updateCache();
}
void AvatarButton::enterEvent(QEvent *event)
{
	QToolButton::enterEvent(event);
	mouseIsHovered = true;

	setIconSize(getIconSizeHint());
	
	updateCache();
}
Esempio n. 8
0
 /*
  * @param key: An integer
  * @param value: An integer
  * @return: nothing
  */
 void set(int key, int value) {
     if (m_capacity <= 0) return;
     if (cacheMap.count(key))
     {
         cacheMap[key]->value = value;
         // update an existing cache also makes it most recently used
         updateCache(cacheMap[key]); 
         return;
     }
     // 1. if LRUCache is full
     //  1.1 remove the least recent used cache - head
     //  1.2 insert key and value to the cache, make it the most recent used cache
     //  1.3 update the cache map
     // 2. if LRUCache is not full
     //  2.1 insert into the cache, and make it most recent used cache
     //  2.2 update the cache map
     if (isFull())
     {
         Node* node = new Node(key, value);
         Node* temp = head;
         if (head == tail)
         {
             // single item, replace it with the newly created node
             head = node;
             tail = node;
         }
         else
         {
             head = head->next;
             head->prev = NULL;
             tail->next = node;
             node->prev = tail;
             tail = node;
         }
         cacheMap[key] = node;
         cacheMap.erase(temp->key);
         delete temp;
     }
     else
     {
         Node* node = new Node(key, value);
         if (cacheMap.empty())
         {
             head = node;
             tail = node;
         }
         else
         {
             // make the node the most recent cache (tail)
            tail->next = node;
            node->prev = tail;
            tail = node;
         }
         cacheMap[key] = node;
     }
 }
Esempio n. 9
0
//-----------------------------------------------------------------------
bool SMBUrl::cd(const QString &filedir)
{
    if (filedir == "..") {
        setUrl(KIO::upUrl(*this).url());
    } else {
        setUrl(filedir);
    }
    updateCache();
    return true;
}
        void EntityDefinitionManager::setDefinitions(const EntityDefinitionList& newDefinitions) {
            clear();

            m_definitions = newDefinitions;

            updateIndices();
            updateGroups();
            updateCache();
            bindObservers();
        }
Esempio n. 11
0
  bool VertexSE3::read(std::istream& is)
  {

    Vector7d est;
    for (int i=0; i<7; i++)
      is  >> est[i];
    setEstimate(SE3Quat(est));
    updateCache();
    return true;
  }
Esempio n. 12
0
void Bubble::updateBrush()
{
    QRadialGradient gradient(QPointF(radius, radius), radius,
                             QPointF(radius*0.5, radius*0.5));

    gradient.setColorAt(0, QColor(255, 255, 255, 255));
    gradient.setColorAt(0.25, innerColor);
    gradient.setColorAt(1, outerColor);
    brush = QBrush(gradient);
    updateCache();
}
Esempio n. 13
0
void uiTextNode::validateCache (uiNode_t* node)
{
	int v;
	if (EXTRADATA(node).dataID == TEXT_NULL || node->text != nullptr)
		return;

	v = UI_GetDataVersion(EXTRADATA(node).dataID);
	if (v != EXTRADATA(node).versionId) {
		updateCache(node);
	}
}
Esempio n. 14
0
void KItemListGroupHeader::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{
    Q_UNUSED(painter);
    Q_UNUSED(option);
    Q_UNUSED(widget);

    if (m_dirtyCache) {
        updateCache();
    }

    paintSeparator(painter, m_separatorColor);
    paintRole(painter, m_roleBounds, m_roleColor);
}
Esempio n. 15
0
    virtual Assets operator()(
            const Variates &v, const Assets &a, double dt) const {

        updateCache(dt);
        Assets new_a;
        new_a.r    = std::min(std::max(a.r*ekt_ + t_*(1.0-ekt_) 
                                       + stdR_*v.W1,1E-6),0.5);
        new_a.intR = std::min(std::max(a.r*Psi_ + t_*(dt-Psi_) 
                                       + stdIntR_*v.W1,1E-6),0.5);
        new_a.S    = a.S*std::exp(drift(new_a.intR,dt) 
                          + s_*sqrtDt_*(rho_*v.W1 + rhoComplement_*v.W2));
        return new_a;
    }
Esempio n. 16
0
void NodeEeprom::writeEeprom(uint16 location, uint16 value)
{
    //if we want to check the cache
    if(m_useCache && NodeEepromMap::canUseCache_write(location))
    {
        //attempt to read the value from the cache
        uint16 valInCache;
        if(readCache(location, valInCache))
        {
            //if the value in the cache is the same we are trying to write
            if(valInCache == value)
            {
                //do not need to write anything, just return
                return;
            }
        }
    }

    //if we made it here, we want to actually write to the device

    //if the read/write version is unknown
    if(m_readWriteVersion == 0)
    {
        //try to determine the version of the read/write eeprom cmd
        if(!determineReadWriteVersion())
        {
            //failed to get the read/write version
            throw Error_NodeCommunication(m_nodeAddress, "Failed to write EEPROM " + Utils::toStr(location) + " to Node " + Utils::toStr(m_nodeAddress));
        }
    }

    //attempt to write the value to the Node
    if(m_baseStation.node_writeEeprom(m_readWriteVersion, m_nodeAddress, location, value))
    {
        //successfully wrote to the Node, update the cache
        updateCache(location, value);

        return;
    }

    //we failed to write the value to the Node

    //clear the eeprom cache for this location if we have one, just to be safe
    clearCacheLocation(location);

    throw Error_NodeCommunication(m_nodeAddress, "Failed to write EEPROM " + Utils::toStr(location) + " to Node " + Utils::toStr(m_nodeAddress));
}
Esempio n. 17
0
QPixmap PageProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize)
#endif
{
  qDebug() << "PageProvider::request[Pixmap|Image]" << id;
  requestingPixmap_ = true;//needed to make sure that a second request does not come to quickly

  prevPage_ = currentPage_;
  currentPage_ = id.toInt();
  int width = 100;//default size
  int height =100;

  //the document is not loaded or the cache is not valid
  //the GUI should make sure that the cache is valid before issuing a request
  if ((NULL == doc_) || (0 == doc_->numPages()) ||
  (PageCache::VALID != pageCache_[currentPage_%CACHE_SIZE].status)) {
    //return a default pixmap
    qDebug() << "no document or invalid cache";
    if (size) {
      *size = QSize(width, height);
    }
    requestingPixmap_ = false;
#ifdef POPPLER_BACKEND
	return QImage(width,height, QImage::Format_RGB32);
#else
    return QPixmap(width,height);
#endif
  }

  qDebug() << "valid cache" << currentPage_;
  const OkularDocument::PageContentType *pPix = pageCache_[currentPage_%CACHE_SIZE].page;
  bool isValid = ((NULL != pPix) && (false == pPix->isNull()));
  if (true == isValid) {
    width = requestedSize.width() > 0 ? requestedSize.width() : pPix->width();
    height = requestedSize.height() > 0 ? requestedSize.height() : pPix->height();
    qDebug() << "width" << width << ", height" << height;
  }
  if (size) {
    *size = QSize(width, height);
  }

  updateCache();

  requestingPixmap_ = false;
  return (true == isValid)?*pPix:OkularDocument::PageContentType();
}
Esempio n. 18
0
void IfcPPModel::initCopyIfcModel( const shared_ptr<IfcPPModel>& other )
{
	clearIfcModel();

	shared_ptr<IfcProject> project = other->getIfcProject();
	std::map<IfcPPEntity*, shared_ptr<IfcPPEntity> > map_entities_copy;
	map_entities_copy[project.get()] = project;
	
	shared_ptr<IfcPPEntity> project_as_entity( project );
	collectDependentEntities( project_as_entity, map_entities_copy );

	for( auto it = map_entities_copy.begin(); it != map_entities_copy.end(); ++it )
	{
		shared_ptr<IfcPPEntity> entity = it->second;
		insertEntity( entity );
	}

	updateCache();
}
Esempio n. 19
0
void NodeEeprom::parseEepromPage(const ByteStream& pageData, uint16 pageIndex)
{
    //get the number of bytes in the page ByteStream
    uint16 dataLength = static_cast<uint16>(pageData.size());
    uint16 mapLocation;

    //loop through all the data in the page
    for(uint16 pos = 0; pos < dataLength; pos += 2)
    {
        //calculate the eeprom location that this value should be stored in in the map
        mapLocation = pos + (EEPROMS_PER_PAGE * pageIndex);

        //just storing everything as uint16
        uint16 eepromVal = pageData.read_uint16(pos);

        //update the cache value
        updateCache(mapLocation, eepromVal);
    }
}
void SmoothCanvas::handleReleaseEvent(QPointF pos){
	if(m_bIsDrawing){
		sPoint* pt = new sPoint();
		pt->x = pos.x();
		pt->y = pos.y();
		m_lPoints.append(pt);

		generateCurrentPath();
		m_lPreviousPath << m_pCrntPath;

		//delete m_pCrntPath;
		m_pCrntPath = NULL;

		m_bIsDrawing = false;

		updateCache();
		update();
	}else{
		Q_UNUSED(pos);
	}
}
Esempio n. 21
0
bool DHSkeleton::init() {
    if (!m_data || !Node::init()) {
        return false;
    }
    
    m_bones = m_data->newBones();
    
    m_slots = m_data->newSlots(this);
    
    m_drawOrder = new DHSlot*[m_data->getSlotCount()];
    memcpy(m_drawOrder, m_slots, sizeof(DHSlot*) * m_data->getSlotCount());
    
    m_ikConstraints = m_data->newIkConstraints(this);
    
    updateCache();
    
    updateWorldTransform();
    
    setGLProgram(GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP));
    
    return true;
}
void CtrlrMidiInputComparatorSingle::match (const MidiMessage &m)
{
	messageContainer			= m;
	CtrlrMidiMessageType type	= midiMessageToType(m);
	int channel					= m.getChannel();
	int number					= getMidiNumberFromMidiMessage(m);

	if (cacheMatch(type, number, channel))
	{
		return;
	}

	if (type == SysEx)
	{
		matchSysEx(m);
		return;
	}

	CtrlrMidiMap &map = getMap(type);

	if (map.size() != 0)
	{
		CtrlrMidiMapIterator it = map.find (number);

		if (it != map.end())
		{
			for (int i=0; i < (*it).second.targets.size(); i++)
			{
				if (m.getChannel() == (*it).second.targets[i]->getMidiMessage().getChannel())
				{
					(*it).second.targets[i]->getProcessor().setValueFromMIDI (messageContainer);

					updateCache (type, it);
				}
			}
		}
	}
}
Esempio n. 23
0
    Runner::RunnerState CachedPlanRunner::getNext(BSONObj* objOut, DiskLoc* dlOut) {
        Runner::RunnerState state = _exec->getNext(objOut, dlOut);

        if (Runner::RUNNER_ADVANCED == state) {
            // Indicate that the plan executor already produced results.
            _alreadyProduced = true;
        }

        // If the plan executor errors before producing any results,
        // and we have a backup plan available, then fall back on the
        // backup plan. This can happen if '_exec' has a blocking sort.
        if (Runner::RUNNER_ERROR == state && !_alreadyProduced && NULL != _backupPlan.get()) {
            _exec.reset(_backupPlan.release());
            state = _exec->getNext(objOut, dlOut);
        }

        // This could be called several times and we don't want to update the cache every time.
        if (Runner::RUNNER_EOF == state && !_updatedCache) {
            updateCache();
        }

        return state;
    }
void CtrlrMidiInputComparatorMulti::match (const MidiMessage &m)
{
	bool match = false;
	startTimer (200);

	if (!basicMatch(m))
	{
		updateState(match);
		return;
	}

	if (cacheMatch())
	{
		updateState(match);
		return;
	}

	BigInteger bi = memoryToBits(messageContainer.getData());
	CtrlrMultiMidiMapIterator it;

	for (it=map.begin(); it != map.end(); it++)
	{
		if (compareMemory ((*it).first.toMemoryBlock(), messageContainer.getData()))
		{
			match = true;

			for (int i=0; i < (*it).second.targets.size(); i++)
			{
				(*it).second.targets[i]->getProcessor().setValueFromMIDI (messageContainer);
			}

			updateCache (it);
			break;
		}
	}
	updateState(match);
}
Esempio n. 25
0
PlanStage::StageState CachedPlanStage::work(WorkingSetID* out) {
    ++_commonStats.works;

    // Adds the amount of time taken by work() to executionTimeMillis.
    ScopedTimer timer(&_commonStats.executionTimeMillis);

    if (isEOF()) {
        return PlanStage::IS_EOF;
    }

    StageState childStatus = getActiveChild()->work(out);

    if (PlanStage::ADVANCED == childStatus) {
        // we'll skip backupPlan processing now
        _alreadyProduced = true;
    }
    else if (PlanStage::IS_EOF == childStatus) {
        updateCache();
    }
    else if (PlanStage::FAILURE == childStatus
             && !_alreadyProduced
             && !_usingBackupChild
             && NULL != _backupChildPlan.get()) {
        _usingBackupChild = true;
        childStatus = _backupChildPlan->work(out);
    }

    // Update stats.
    if (PlanStage::NEED_TIME == childStatus) {
        _commonStats.needTime++;
    }
    else if (PlanStage::ADVANCED == childStatus) {
        _commonStats.advanced++;
    }

    return childStatus;
}
Esempio n. 26
0
Vector2f Spline2f::closestPointOnSpline( const Vector2f& p, float* closestT, float* closestDistance )
{
    if( isCacheDirty() )
    {
        updateCache();
    }

    int nPointsToEvaluate = numPointsToEvaluate();

    Vector2f minPoint( 0.f );
    float minDistance = FLT_MAX;
    float minT = -1;
    float delta = 1.f / ( nPointsToEvaluate - 1 );

    for( int i = 0; i < nPointsToEvaluate; ++i )
    {
        Vector2f splinePoint = m_cache[ i ];
        float currentDistanceSquared = ( splinePoint - p ).normSquared();
        if( currentDistanceSquared < minDistance )
        {
            minDistance = currentDistanceSquared;
            minPoint = splinePoint;
            minT = i * delta;
        }
    }

    if( closestT != NULL )
    {
        *closestT = minT;
    }
    if( closestDistance != NULL )
    {
        *closestDistance = sqrt( minDistance );
    }
    return minPoint;
}
Esempio n. 27
0
 bool OptimizableGraph::Vertex::setMinimalEstimateData(const double* v)
 {
   bool ret = setMinimalEstimateDataImpl(v);
   updateCache();
   return ret;
 }
Esempio n. 28
0
int loadRuleFromCacheOrFile( int processType, char *irbSet, ruleStruct_t *inRuleStruct ) {
    char r1[NAME_LEN], r2[RULE_SET_DEF_LENGTH], r3[RULE_SET_DEF_LENGTH];
    snprintf( r2, sizeof( r2 ), "%s", irbSet );
    int res = 0;

#ifdef DEBUG
    /*Cache *cache;*/
#endif

    /* get max timestamp */
    char fn[MAX_NAME_LEN];
    time_type timestamp = time_type_initializer, mtim;
    while ( strlen( r2 ) > 0 ) {
        rSplitStr( r2, r1, NAME_LEN, r3, RULE_SET_DEF_LENGTH, ',' );
        getRuleBasePath( r1, fn );
        if ( ( res = getModifiedTime( fn, &mtim ) ) != 0 ) {
            return res;
        }
        if ( time_type_gt( mtim, timestamp ) ) {
            time_type_set( timestamp, mtim );
        }
        snprintf( r2, sizeof( r2 ), "%s", r3 );
    }
    snprintf( r2, sizeof( r2 ), "%s", irbSet );

#ifdef CACHE_ENABLE

    int update = 0;
    unsigned char *buf = NULL;
    /* try to find shared memory cache */
    if ( processType == RULE_ENGINE_TRY_CACHE && inRuleStruct == &coreRuleStrct ) {
        buf = prepareNonServerSharedMemory();
        if ( buf != NULL ) {
            Cache * cache = restoreCache( buf );
            detachSharedMemory();

            if ( cache == NULL ) {
                rodsLog( LOG_ERROR, "Failed to restore cache." );
            }
            else {
                int diffIrbSet = strcmp( cache->ruleBase, irbSet ) != 0;
                if ( diffIrbSet ) {
                    rodsLog( LOG_DEBUG, "Rule base set changed, old value is %s", cache->ruleBase );
                }

                if ( diffIrbSet || time_type_gt( timestamp, cache->timestamp ) ) {
                    update = 1;
                    free( cache->address );
                    rodsLog( LOG_DEBUG, "Rule base set or rule files modified, force refresh." );
                }
                else {

                    cache->cacheStatus = INITIALIZED;
                    ruleEngineConfig = *cache;
                    /* generate extRuleSet */
                    generateRegions();
                    generateRuleSets();
                    generateFunctionDescriptionTables();
                    if ( inRuleStruct == &coreRuleStrct && ruleEngineConfig.ruleEngineStatus == UNINITIALIZED ) {
                        getSystemFunctions( ruleEngineConfig.sysFuncDescIndex->current, ruleEngineConfig.sysRegion );
                    }
                    /* ruleEngineConfig.extRuleSetStatus = LOCAL;
                    ruleEngineConfig.extFuncDescIndexStatus = LOCAL; */
                    /* createRuleIndex(inRuleStruct); */
                    ruleEngineConfig.ruleEngineStatus = INITIALIZED;
                    //free( cache );
                    return res;
                }
            }
            //free( cache );
        }
        else {
            rodsLog( LOG_DEBUG, "Cannot open shared memory." );
        }
    }
#endif

    if ( ruleEngineConfig.ruleEngineStatus == INITIALIZED ) {
        /* Reloading rule set, clear previously generated rule set */
        unlinkFuncDescIndex();
        clearRuleIndex( inRuleStruct );
    }

    generateRegions();
    generateRuleSets();
    generateFunctionDescriptionTables();
    if ( inRuleStruct == &coreRuleStrct && ruleEngineConfig.ruleEngineStatus == UNINITIALIZED ) {
        getSystemFunctions( ruleEngineConfig.sysFuncDescIndex->current, ruleEngineConfig.sysRegion );
    }
    /*ruleEngineConfig.extRuleSetStatus = LOCAL;
    ruleEngineConfig.extFuncDescIndexStatus = LOCAL;*/
    while ( strlen( r2 ) > 0 ) {
        int i = rSplitStr( r2, r1, NAME_LEN, r3, RULE_SET_DEF_LENGTH, ',' );
        if ( i == 0 ) {
            i = readRuleStructAndRuleSetFromFile( r1, inRuleStruct );
        }
#ifdef DEBUG
        printf( "%d rules in core rule set\n", ruleEngineConfig.coreRuleSet->len );
#endif
        if ( i != 0 ) {
            res = i;
            ruleEngineConfig.ruleEngineStatus = INITIALIZED;
            return res;
        }
        snprintf( r2, sizeof( r2 ), "%s", r3 );
    }

    createRuleIndex( inRuleStruct );
    /* set max timestamp */
    time_type_set( ruleEngineConfig.timestamp, timestamp );
    snprintf( ruleEngineConfig.ruleBase, sizeof( ruleEngineConfig.ruleBase ), "%s", irbSet );

#ifdef CACHE_ENABLE
    if ( ( processType == RULE_ENGINE_INIT_CACHE || update ) && inRuleStruct == &coreRuleStrct ) {
        unsigned char *shared = prepareServerSharedMemory();

        if ( shared != NULL ) {
            int ret = updateCache( shared, SHMMAX, &ruleEngineConfig, processType );
            detachSharedMemory();
            if ( ret != 0 ) {
                removeSharedMemory();
            }
        }
        else {
            rodsLog( LOG_ERROR, "Cannot open shared memory." );
        }
    }
#endif

    ruleEngineConfig.ruleEngineStatus = INITIALIZED;

    return res;
}
Esempio n. 29
0
//-----------------------------------------------------------------------
void SMBUrl::addPath(const QString &filedir)
{
    KURL::addPath(filedir);
    updateCache();
}
Esempio n. 30
0
//-----------------------------------------------------------------------
SMBUrl::SMBUrl(const KURL& kurl)
    : KURL(kurl)
  //-----------------------------------------------------------------------
{
    updateCache();
}