Example #1
0
int Examine_Semantic_Analyser(int *tokens,int *i,int *whereabout)

{
	char input[Max_input];
	int t[Max_tokens],error=0,k=0;
	Initialize_Tokens(t);
	if(tokens[*i]=='\0')
	{
		printf("What do you want to examine?\n");
		gets(input);
		Tokens_Num=0;
		if(Input_Process(input,t,&error)==-1)
			return -1;
		if(t[1])
		{
			printf("Just \"object\" is okay.\n");
			return -1;
		}
		while(k<Max_carries)
		{
			if(t[0]==player.inventory[k])
			{
				*whereabout=k;
				tokens[*i]=t[0];
				return 0;
			}
			k++;
		}
		if(_find(t[0]))
		{
			tokens[*i]=t[0];
			return 0;
		}
		printf("The object is either not here or not important.\n");
		return -1;
	}
	if(isart(tokens[*i]))
		(*i)++;
	if(!isobj(tokens[*i])||tokens[*i+1]!='\0')
	{
		printf("Illegal sentence.\n");
		return -1;
	}
	while(k<Max_carries)
	{
		if(tokens[*i]==player.inventory[k])
		{
			*whereabout=k;
			return 0;
		}
		k++;
	}
	if(_find(tokens[*i]))
		return 0;
	printf("The object is either not here or not important.\n");
	return -1;
}
Example #2
0
File: e6.cpp Project: berak/e6
		bool findE6Path()
		{
			char up[300];
			char name[300];
			char path[300];
			// this must be in the 'bin' folder.
			const char * e6_dll = "_dllCache";

			const char * here = sys::getCurrentDir();
			strcpy( e6Path, here );
			//printf( "here is %s , - ", here );

			// we're in e6?
			if ( _find(path, e6_dll, here, "bin" ) )
			{
				//printf( "we're in e6.\n");
				return true;
			}
			// we're in e6/bin?
			if ( _find(path, e6_dll, here ) )
			{
				this->chopPath( here, up, name );
				strcpy( e6Path, up );
				//printf( "we're in e6/bin.\n");
				return true;
			}
			// we're in e6/some_folder?
			if ( _find(path, e6_dll, here, "..", "bin" ) )
			{
				this->chopPath( here, up, name );
				strcpy( e6Path, up );
				//printf( "we're in e6/*somewhere.\n");
				return true;
			}

			// we're in e6/bin/some_folder?
			sprintf( path, "%s%c..", here, sys::fileSeparator() );
			if ( _find(path, e6_dll, path  ) )
			{
				this->chopPath( here, up, name );
				this->chopPath( up, up, name );
				strcpy( e6Path, up );
				//printf( "we're in e6/bin/somewhere.\n");
				return true;
			}

			printf( "we're in nowhere.\n");
			return false;
		}
Example #3
0
inline Ob Carrier::find(Ob ob) const {
    SharedLock lock(m_mutex);
    POMAGMA_ASSERT5(contains(ob), "tried to find unsupported object " << ob);

    Ob rep = m_reps[ob].load(std::memory_order_relaxed);
    return rep == ob ? ob : _find(ob, rep);
}
Example #4
0
void *dm_hash_lookup_binary(struct dm_hash_table *t, const char *key,
			 uint32_t len)
{
	struct dm_hash_node **c = _find(t, key, len);

	return *c ? (*c)->data : 0;
}
Example #5
0
	/*! Find a key (reference). If not found, throw InvalidMetadata.
	  Ye Olde Binary Chop
	  \param key the key to find
	  \return value found (reference) */
	const Val& find_ref(const Key& key) const
	{
		const_iterator res(_find(key));
		if (res)
			return res->_value;
		throw InvalidMetadata<Key>(key);
	}
Example #6
0
	TexturePtr NullHWBufferManager::LoadTexture(const String & filename, float priority, int mipmaps, eUsage usage)
	{
		Hash2 hash(filename.c_str());

		TexturePtr p = _find(hash, filename);
		if (p == NULL)
		{
			NullTexture * pTexture = new NullTexture(filename, filename);
			pTexture->mWidth = 0;
			pTexture->mHeight = 0;
			pTexture->mMipmaps = 1;
			pTexture->mUsage = usage;
			pTexture->mFormat = ePixelFormat::UNKNOWN;
			pTexture->mPriority = priority;

			p = pTexture;

			mTextureMap.Insert(hash, p.c_ptr());
		}

		if (priority < 0)
		{
			p->EnsureLoad();
		}
		else
		{
			p->Load();
		}

		return p;
	}
Example #7
0
    void ReplicaSetMonitor::_checkStatus(DBClientConnection *conn) {
        BSONObj status;

        if (!conn->runCommand("admin", BSON("replSetGetStatus" << 1), status) ||
                !status.hasField("members") ||
                status["members"].type() != Array) {
            return;
        }

        BSONObjIterator hi(status["members"].Obj());
        while (hi.more()) {
            BSONObj member = hi.next().Obj();
            string host = member["name"].String();

            int m = -1;
            if ((m = _find(host)) <= 0) {
                continue;
            }

            double state = member["state"].Number();
            if (member["health"].Number() == 1 && (state == 1 || state == 2)) {
                scoped_lock lk( _lock );
                _nodes[m].ok = true;
            }
            else {
                scoped_lock lk( _lock );
                _nodes[m].ok = false;
            }
        }
    }
Example #8
0
int CThesaurus::QueryTopConcepts(UINT TextEntryId, vector<int>& CurrentTopConcepts) const
{
  CurrentTopConcepts.clear();
  vector<long> ConceptsFromTextEntry;
  GetConceptsByTextEntryId(TextEntryId, ConceptsFromTextEntry);
  if (ConceptsFromTextEntry.empty()) return 0;

  for (long i=0; i <ConceptsFromTextEntry.size(); i++)
  {
	vector<long> HIGHERConcepts;
	vector<long> Path;

    if (!GetTree(GetConceptNoByConceptId(ConceptsFromTextEntry[i]), HIGHERConcepts, Path, HIGHER))
    {
       ErrorMessage ("a cycle found starts from TextEntry " + m_Termins[GetTerminNoByTextEntryId(TextEntryId)].m_TerminStr);
       return 0;
    };


   for (long k=0; k < HIGHERConcepts.size(); k++)
    if (GetRelationsCount(*this, HIGHERConcepts[k], HIGHER) == 0) 
		if (!_find(CurrentTopConcepts,HIGHERConcepts[k])) 
          CurrentTopConcepts.push_back(HIGHERConcepts[k]);
  };

  return CurrentTopConcepts.size();
}
Example #9
0
void SceneTreeEditor::_node_visibility_changed(Node *p_node) {


	if (p_node!=get_scene_node() && !p_node->get_owner()) {

		return;
	}
	TreeItem* item=p_node?_find(tree->get_root(),p_node->get_path()):NULL;
	if (!item) {

		return;
	}
	int idx=item->get_button_by_id(0,BUTTON_VISIBILITY);
	ERR_FAIL_COND(idx==-1);

	bool visible=false;

	if (p_node->is_type("CanvasItem")) {
		visible = !p_node->call("is_hidden");
	} else if (p_node->is_type("Spatial")) {
		visible = !p_node->call("is_hidden");
	}

	if (!visible)
		item->set_button(0,idx,get_icon("Hidden","EditorIcons"));
	else
		item->set_button(0,idx,get_icon("Visible","EditorIcons"));


}
Example #10
0
void CThesaurus::QueryLowerTermins(const string& ConceptStr, UINT Language, vector<int>& CurrentLowerTermins) const
{
	CurrentLowerTermins.clear();
	long ConceptNo = GetConceptNoByConceptStr(ConceptStr);	
	if (ConceptNo == -1) return;
	vector<long> LOWERConcepts;
	vector<long> Path;
	if (!GetTree(ConceptNo, LOWERConcepts, Path, LOWER))
		  return;

	bool IsEnglish =  Language == morphEnglish;
	for (long i=0; i <LOWERConcepts.size(); i++)
	{
	  vector<long> TextEntries;
	  GetTextEntriesByConcept(m_Concepts[LOWERConcepts[i]].m_ConceptId, TextEntries);
	  for (long k=0; k < TextEntries.size(); k++)
	  {
		  long TerminNo = GetTerminNoByTextEntryId(TextEntries[k]);
		  if (m_Termins[TerminNo].m_ModelNo == -1) continue;
		  if (IsEnglish != IsEnglishModel(m_Models[m_Termins[TerminNo].m_ModelNo])) continue;
		  if (!_find (CurrentLowerTermins, TerminNo))
			  CurrentLowerTermins.push_back(TerminNo);
	  };
	};

}
Example #11
0
void SceneTreeEditor::set_selected(Node *p_node, bool p_emit_selected) {

	ERR_FAIL_COND(blocked > 0);

	if (pending_test_update)
		_test_update_tree();
	if (tree_dirty)
		_update_tree();

	if (selected == p_node)
		return;

	TreeItem *item = p_node ? _find(tree->get_root(), p_node->get_path()) : NULL;

	if (item) {
		// make visible when it's collapsed
		TreeItem *node = item->get_parent();
		while (node && node != tree->get_root()) {
			node->set_collapsed(false);
			node = node->get_parent();
		}
		item->select(0);
		item->set_as_cursor(0);
		selected = p_node;
		tree->ensure_cursor_is_visible();
	} else {
		if (!p_node)
			selected = NULL;
		_update_tree();
		selected = p_node;
		if (p_emit_selected)
			emit_signal("node_selected");
	}
}
Example #12
0
void SceneTreeEditor::set_selected(Node *p_node,bool p_emit_selected) {

	ERR_FAIL_COND(blocked>0);

	if (pending_test_update)
		_test_update_tree();
	if (tree_dirty)
		_update_tree();

	if (selected==p_node)
		return;


	TreeItem* item=p_node?_find(tree->get_root(),p_node->get_path()):NULL;

	if (item) {
		item->select(0);
		item->set_as_cursor(0);
		selected=p_node;
		tree->ensure_cursor_is_visible();
	} else {
		if (!p_node)
			selected=NULL;
		_update_tree();
		selected=p_node;
		if (p_emit_selected)
			emit_signal("node_selected");
	}

}
Example #13
0
/*向hash表中插入一组数据*/
void hash_insert(struct HashTable *table, char *key, void *value)
{
	int index;
	struct HashNode *node;

	if(!table || !key)
		return;

	index = _find(table, key);
	if(index == -1)
	{
		if(TRIGGER(table->capacity, table->number + 1))
			_resize(table);
		index = _get_empty(table, key);
		node = (struct HashNode*)mm_malloc(sizeof(struct HashNode));
		node->key = (char*)mm_malloc(strlen(key) + 1);
		strcpy(node->key, key);
		if(table->copy_value)
			node->value = table->copy_value(value);
		else
			node->value = value;
		table->head[index] = node;
		table->number ++;
	}
	else
	{
		
		if(table->free_value)
			table->free_value(table->head[index]->value);
		if(table->copy_value)
			table->head[index]->value = table->copy_value(value);
		else
			table->head[index]->value = value;
	}
}
Example #14
0
boost::optional<const DirEntry&> DirEntryList::get(const Key &key) const {
    auto found = _find(key);
    if (found == _entries.end()) {
        return boost::none;
    }
    return *found;
}
Example #15
0
size_t wstring::find_first_not_of(const wchar_t* s, size_t pos, size_t n) const {
    size_t xpos = pos;
    for (; xpos < length(); ++xpos)
        if (_find(s, data() [xpos], 0, n) == npos)
            return xpos;
    return npos;
}
SplayTree* SplayTree::_split(size_t position) {
    size_t treeSize = (_root ? _root->sizeOfSubtree : 0);

    if(position > treeSize) {
        return NULL;
        //    throw std::out_of_range("out of range in SplayTree::split\n");
    }

    if(position == treeSize) {
        return new SplayTree(nullptr);
    }

    Node* newRoot = _find(position, _root);

    SplayTree* rightTree = new SplayTree(newRoot);

    _root = newRoot->leftChild;
    newRoot->leftChild = nullptr;
    _setParent(_root, nullptr);

    if(rightTree->_root) {
        rightTree->_root->treePtr = rightTree;
    }

    Node::push(rightTree->_root);
    Node::push(_root);

    return rightTree;
}
Node* SplayTree::_find(size_t position, Node* vertex) {
    Node::push(vertex);

    size_t indexLeft = Node::getSize(vertex->leftChild);

    if(position == indexLeft) {
        splay(vertex);
        return vertex;
    }

    if(position < indexLeft) {
        return _find(position, vertex->leftChild);
    }

    return _find(position - indexLeft - 1, vertex->rightChild);
}
Example #18
0
void _insert(bp_tree * tree, int k)
{
    if (!tree->root) {
        bp_node * r = new bp_node;
        r->n = 1;
        r->key[0] = k;
        tree->root = tree->sqt = r;
        return;
    }

    bp_node * p = NULL;
    int i = -1;

    if (_find(tree->root, k, p, i)) {
        return;
    }

    _insert_key(p, i, k);

    while (p->n == 4) {
        bp_node *n1 = NULL, *n2 = NULL;
        bp_node * parent = p->parent;
        _split(p, n1, n2);

        if (!parent) {
            tree->root = parent = new bp_node;
        }

        _insert_child(parent, n1, n2);

        p = parent;
    }
}
void SceneTreeEditor::_node_visibility_changed(Node *p_node) {

	if (p_node != get_scene_node() && !p_node->get_owner()) {

		return;
	}
	TreeItem *item = p_node ? _find(tree->get_root(), p_node->get_path()) : NULL;
	if (!item) {

		return;
	}
	int idx = item->get_button_by_id(0, BUTTON_VISIBILITY);
	ERR_FAIL_COND(idx == -1);

	bool visible = false;

	if (p_node->is_class("CanvasItem")) {
		visible = p_node->call("is_visible");
		CanvasItemEditor::get_singleton()->get_viewport_control()->update();
	} else if (p_node->is_class("Spatial")) {
		visible = p_node->call("is_visible");
	}

	if (visible)
		item->set_button(0, idx, get_icon("GuiVisibilityVisible", "EditorIcons"));
	else
		item->set_button(0, idx, get_icon("GuiVisibilityHidden", "EditorIcons"));

	_update_visibility_color(p_node, item);
}
Example #20
0
 /**
  * notify the monitor that server has faild
  */
 void ReplicaSetMonitor::notifySlaveFailure( const HostAndPort& server ) {
     int x = _find( server );
     if ( x >= 0 ) {
         scoped_lock lk( _lock );
         _nodes[x].ok = false;
     }
 }
Example #21
0
	const Value& at(const Key& key) const
	{
		Node* node = _find(_root, key);
		
		if (! node) throw std::invalid_argument("Invalid key!");
		
		return node->value;
	}
Example #22
0
    void LockerImpl::downgradeGlobalXtoSForMMAPV1() {
        invariant(!inAWriteUnitOfWork());

        // Only Global and Flush lock could be held at this point.
        invariant(_requests.size() == 2);

        LockRequest* globalLockRequest = _find(resourceIdGlobal);
        LockRequest* flushLockRequest = _find(resourceIdMMAPV1Flush);

        invariant(globalLockRequest->mode == MODE_X);
        invariant(globalLockRequest->recursiveCount == 1);
        invariant(flushLockRequest->mode == MODE_X);
        invariant(flushLockRequest->recursiveCount == 1);

        globalLockManagerPtr->downgrade(globalLockRequest, MODE_S);
        globalLockManagerPtr->downgrade(flushLockRequest, MODE_S);
    }
Example #23
0
    LockMode LockerImpl::getLockMode(const ResourceId& resId) const {
        scoped_spinlock scopedLock(_lock);

        const LockRequest* request = _find(resId);
        if (request == NULL) return MODE_NONE;

        return request->mode;
    }
Example #24
0
void _pktbuf_internal_free(void *ptr)
{
    _used_t *prev, *node;

    if (_find(&prev, &node, ptr) != NULL) {
        _free_helper(prev, node);
    }
}
Example #25
0
void  CThesaurus::QueryHigherTermins(UINT TextEntryId, vector<int>& CurrentHigherTermins) const
{
	CurrentHigherTermins.clear();
	long TerminNo = GetTerminNoByTextEntryId(TextEntryId);
	if (TerminNo == -1) return;
	if (m_Termins[TerminNo].m_ModelNo == -1) return;
	bool IsEnglish =   IsEnglishModel(m_Models[m_Termins[TerminNo].m_ModelNo]);
 

	vector<long> ConceptsFromTextEntry;
	GetConceptsByTextEntryId(TextEntryId, ConceptsFromTextEntry);
	if (ConceptsFromTextEntry.empty()) return;
	vector<long> HigherConcepts;
	long i=0;
	for (; i <ConceptsFromTextEntry.size(); i++)
	{
		vector<long> HIGHERConcepts;
		vector<long> Path;

		if (!GetTree(GetConceptNoByConceptId(ConceptsFromTextEntry[i]), HIGHERConcepts, Path, HIGHER))
		{
			ErrorMessage ("a cycle found starts from TextEntry " + m_Termins[GetTerminNoByTextEntryId(TextEntryId)].m_TerminStr);
			return;
		};


		for (long k=0; k < HIGHERConcepts.size(); k++)
			if ( !_find(HigherConcepts, HIGHERConcepts[k]) )
				HigherConcepts.push_back(HIGHERConcepts[k]);
	};

	for (i=0; i <HigherConcepts.size(); i++)
	{
	  vector<long> TextEntries;
	  GetTextEntriesByConcept(m_Concepts[HigherConcepts[i]].m_ConceptId, TextEntries);
	  for (long k=0; k < TextEntries.size(); k++)
	  {
		  long TerminNo = GetTerminNoByTextEntryId(TextEntries[k]);
		  if (m_Termins[TerminNo].m_ModelNo == -1) continue;
		  if (IsEnglish != IsEnglishModel(m_Models[m_Termins[TerminNo].m_ModelNo])) continue;
		  if (!_find (CurrentHigherTermins, TerminNo))
			  CurrentHigherTermins.push_back(TerminNo);
	  };
	};

}
Example #26
0
    LockResult LockerImpl::lock(const ResourceId& resId, LockMode mode, unsigned timeoutMs) {
        _notify.clear();

        _lock.lock();
        LockRequest* request = _find(resId);
        if (request == NULL) {
            request = new LockRequest();
            request->initNew(resId, this, &_notify);

            _requests.insert(LockRequestsPair(resId, request));
        }
        else {
            invariant(request->recursiveCount > 0);
            request->notify = &_notify;
        }
        _lock.unlock();

        // Methods on the Locker class are always called single-threadly, so it is safe to release
        // the spin lock, which protects the Locker here. The only thing which could alter the
        // state of the request is deadlock detection, which however would synchronize on the
        // LockManager calls.

        LockResult result = globalLockManagerPtr->lock(resId, request, mode);
        if (result == LOCK_WAITING) {
            // Under MMAP V1 engine a deadlock can occur if a thread goes to sleep waiting on DB
            // lock, while holding the flush lock, so it has to be released. This is only correct
            // to do if not in a write unit of work.
            bool unlockedFlushLock = false;

            if (!inAWriteUnitOfWork() && 
                (resId != resourceIdGlobal) &&
                (resId != resourceIdMMAPV1Flush) &&
                (resId != resourceIdLocalDB)) {

                invariant(unlock(resourceIdMMAPV1Flush));
                unlockedFlushLock = true;
            }

            // Do the blocking outside of the flush lock (if not in a write unit of work)
            result = _notify.wait(timeoutMs);

            if (unlockedFlushLock) {
                // We cannot obey the timeout here, because it is not correct to return from the
                // lock request with the flush lock released.
                invariant(LOCK_OK ==
                    lock(resourceIdMMAPV1Flush, getLockMode(resourceIdGlobal), UINT_MAX));
            }
        }

        if (result != LOCK_OK) {
            // Can only be LOCK_TIMEOUT, because the lock manager does not return any other errors
            // at this point. Could be LOCK_DEADLOCK, when deadlock detection is implemented.
            invariant(result == LOCK_TIMEOUT);
            invariant(_unlockAndUpdateRequestsList(resId, request));
        }

        return result;
    }
Example #27
0
size_t wstring::find_last_not_of(const wchar_t* s, size_t pos, size_t n) const {
    size_t xpos = length() - 1;
    if (xpos > pos)
        xpos = pos;
    for (; xpos; --xpos)
        if (_find(s, data() [xpos], 0, n) == npos)
        return xpos;
    return npos;
}
Example #28
0
static int _find_tier(int r_idx)
{
    int i;
    for (i = 0; i < _MAX_TIERS; i++)
    {
        if (_find(r_idx, _tiers[i].r_ids) >= 0) return i;
    }
    return -1;
}
Example #29
0
 void UpdateSystem::setDepth(UpdateComponent* comp, int depth)
 {
     auto it = _find(comp);
     if (it != _comps.end() && !it->remove && it->depth != depth)
     {
         it->depth = depth;
         ++_insert;
     }
 }
Example #30
0
int RegExMatch::get_end(const Variant &p_name) const {

	int id = _find(p_name);

	if (id < 0)
		return -1;

	return data[id].end;
}