std::vector<float> LexicalReorderingTableCompact::GetScore(const Phrase& f,
    const Phrase& e,
    const Phrase& c)
{
  std::string key;
  Scores scores;
  
  if(0 == c.GetSize())
    key = MakeKey(f, e, c);
  else
    for(size_t i = 0; i <= c.GetSize(); ++i)
    {
      Phrase sub_c(c.GetSubString(WordsRange(i,c.GetSize()-1)));
      key = MakeKey(f,e,sub_c);
    }
    
  size_t index = m_hash[key];
  if(m_hash.GetSize() != index)
  {
    std::string scoresString;
    if(m_inMemory)
      scoresString = m_scoresMemory[index];
    else
      scoresString = m_scoresMapped[index];
      
    BitWrapper<> bitStream(scoresString);
    for(size_t i = 0; i < m_numScoreComponent; i++)
      scores.push_back(m_scoreTrees[m_multipleScoreTrees ? i : 0]->Read(bitStream));

    return scores;
  }

  return Scores();
}
std::vector<float>  LexicalReorderingTableMemory::GetScore(const Phrase& f,
    const Phrase& e,
    const Phrase& c)
{
  //rather complicated because of const can't use []... as [] might enter new things into std::map
  //also can't have to be careful with words range if c is empty can't use c.GetSize()-1 will underflow and be large
  TableType::const_iterator r;
  std::string key;
  if(0 == c.GetSize()) {
    key = MakeKey(f,e,c);
    r = m_Table.find(key);
    if(m_Table.end() != r) {
      return r->second;
    }
  } else {
    //right try from large to smaller context
    for(size_t i = 0; i <= c.GetSize(); ++i) {
      Phrase sub_c(c.GetSubString(WordsRange(i,c.GetSize()-1)));
      key = MakeKey(f,e,sub_c);
      r = m_Table.find(key);
      if(m_Table.end() != r) {
        return r->second;
      }
    }
  }
  return Scores();
}
	bool DisplayPostProcess::CreateFromLuaConfig(CreateInfoRef _rInfo)
	{
		LuaObjectRef rLuaObject = *_rInfo.m_pLuaObject;
		LuaObject oRenderTargets = rLuaObject["render_targets"];
		const UInt uRTCount = UInt(oRenderTargets.GetCount());
		string strMaterialName;
		Scripting::Lua::Get(rLuaObject, "name", m_strName, m_strName);
		Scripting::Lua::Get(rLuaObject, "immediate_write", m_bImmediateWrite, m_bImmediateWrite);
		Scripting::Lua::Get(rLuaObject, "material", strMaterialName, strMaterialName);
		m_uMaterialNameKey = MakeKey(strMaterialName);

		bool bResult = true;

		if (false != bResult)
		{
			if (0 < uRTCount)
			{
				m_vRTTypes.resize(uRTCount);
				m_vRTNames.resize(uRTCount);
				m_vRTIndexes.resize(uRTCount);

				for (UInt i = 0 ; uRTCount > i ; ++i)
				{
					LuaObject oRenderTarget = oRenderTargets[i + 1];
					const string strRTType = oRenderTarget["type"].GetString();
					const Key uRTTypeKey = MakeKey(strRTType);
					if (s_uTypeTex2DKey == uRTTypeKey)
					{
						const UInt uRTIndex = UInt(oRenderTarget["index"].GetInteger());
						const string strRTName = oRenderTarget["name"].GetString();
						const Key uRTNameKey = MakeKey(strRTName);
						DisplayTexturePtr pTexture = m_rDisplay.GetTextureManager()->Get(uRTNameKey);
						m_mTextures[uRTNameKey] = pTexture;
						bResult = (NULL != pTexture);
						m_vRTTypes[i] = uRTTypeKey;
						m_vRTNames[i] = uRTNameKey;
						m_vRTIndexes[i] = uRTIndex;
					}
					else if (s_uTypeGBufferKey == uRTTypeKey)
					{
						const UInt uRTIndex = UInt(oRenderTarget["index"].GetInteger());
						m_vRTTypes[i] = uRTTypeKey;
						m_vRTNames[i] = uRTIndex;
						m_vRTIndexes[i] = uRTIndex;
					}
					if (false == bResult)
					{
						break;
					}
				}
			}
		}

		return bResult;
	}
Exemple #4
0
const dMaterialPairManager::dMaterialPair* dMaterialPairManager::GetPair (int materialId_0, int materialId_1, int threadIndex) const
{
	unsigned key = MakeKey (materialId_0, materialId_1);

	if (m_cachedKeys[threadIndex] != key) {
		m_cachedKeys[threadIndex] = key;

		int index0 = 0;
		int index2 = m_entryCount - 1;
		unsigned key0 = m_keys[index0];
		unsigned key2 = m_keys[index2];
		while ((index2 - index0) > 4) {
			int index1 = (index0 + index2) >> 1;
			unsigned key1 = m_keys[index1];

			if (key < key1) {
				index2 = index1;
				key2 = key1;
			} else {
				index0 = index1;
				key0 = key1;
			}
		}

		index2 = dMin (m_entryCount, index2 + 4);
		for (int i = index0; (i <= index2) && (m_keys[i] <= key); i ++) {
			if (m_keys[i] == key) {
				m_cachedMaterial[threadIndex] = &m_pool[i];
				return m_cachedMaterial[threadIndex];
			}
		}
		m_cachedMaterial[threadIndex] = &m_default;
	}
Exemple #5
0
void dMaterialPairManager::AddPair (int materialId_0, int materialId_1, const dMaterialPair& pair)
{
	if (m_entryCount >= m_maxCount) {
		// the interaction pool is full we need to reallocate a larger Pool 
		unsigned* const newKeys = new unsigned[m_maxCount * 2];
		dMaterialPair* const newPool = new dMaterialPair[m_maxCount * 2];

		memcpy (newKeys, m_keys, m_entryCount * sizeof (unsigned));
		memcpy (newPool, m_pool, m_entryCount * sizeof (dMaterialPair));

		delete[] m_keys;
		delete[] m_pool;

		m_keys = newKeys;
		m_pool = newPool;
		m_maxCount *= 2;
	}

	unsigned key = MakeKey (materialId_0, materialId_1);
	int index = m_entryCount;
	for ( ; (index > 0) && m_keys[index-1] > key; index --) {
		m_keys[index] = m_keys[index - 1];
		m_pool[index] = m_pool[index - 1];
	}
	m_keys[index] = key;
	m_pool[index] = pair;
	m_entryCount ++;
}
Exemple #6
0
TSocketNode* CMainCtrl::GetSocketNode(unsigned int unClientIP, unsigned short usClientPort,char* szSrcMQ)
{
	char szKey[1024];
	ssize_t iKeyLen = (ssize_t)MakeKey(unClientIP,usClientPort,szSrcMQ,szKey);
	ssize_t iObjIdx = -1;
	return  (TSocketNode*)m_stSocketNodeHash.GetObjectByKey((void *)szKey,iKeyLen,iObjIdx);
}
Exemple #7
0
unsigned int SummaryCommand :: CalcFreqs() {

	mFreqMap.clear();
	unsigned int  mode = 0;

	for ( unsigned int i = 0; i < mRows.size(); i++ ) {
		string key = MakeKey( mRows.at(i) );
		FreqMap::iterator it = mFreqMap.find( key );
		if ( it == mFreqMap.end() ) {
			mFreqMap.insert( std::make_pair( key, FreqMapEntry( i )));
			if ( mode == 0 ) {
				mode = 1;
			}
		}
		else {
			it->second.mFreq++;
			it->second.mIndex.push_back( i );
			if ( mode < it->second.mFreq ) {
				mode = it->second.mFreq ;
			}
		}
	}

	return mode;
}
	DisplaySurfacePtr DisplaySurfaceManager::Get(const string& _strName)
	{
		const Key uKey = MakeKey(_strName);
		DisplaySurfacePtrMap::iterator iPair = m_mSurfaces.find(uKey);
		DisplaySurfacePtr pResult = (m_mSurfaces.end() != iPair) ? iPair->second : NULL;
		return pResult;
	}
Exemple #9
0
int FName::NameManager::FindName (const char *text, bool noCreate)
{
	if (!Inited)
	{
		InitBuckets ();
	}

	if (text == NULL)
	{
		return 0;
	}

	unsigned int hash = MakeKey (text);
	unsigned int bucket = hash % HASH_SIZE;
	int scanner = Buckets[bucket];

	// See if the name already exists.
	while (scanner >= 0)
	{
		if (NameArray[scanner].Hash == hash && stricmp (NameArray[scanner].Text, text) == 0)
		{
			return scanner;
		}
		scanner = NameArray[scanner].NextHash;
	}

	// If we get here, then the name does not exist.
	if (noCreate)
	{
		return 0;
	}

	return AddName (text, hash, bucket);
}
Exemple #10
0
void JoinCommand :: WriteJoinRows( IOManager & io, const CSVRow & row ) {

	string key = MakeKey( row, true );

	MapType::const_iterator pos = mRowMap.lower_bound( key );
	MapType::const_iterator last = mRowMap.upper_bound( key );

	if ( mOuterJoin && pos == last ) {
		io.WriteRow( row );
	}
	else if ( mInvert ) {
		if ( pos == last ) {
			io.WriteRow( row );
		}
		return;
	}
	else {
		while( pos != last ) {
			const CSVRow & jr = pos->second;
			CSVRow newrow = row;
			for ( unsigned int i = 0; i < jr.size(); i++ ) {
				newrow.push_back( jr[i] );
			}
			io.WriteRow( newrow );
			++pos;
		}
	}
}
Exemple #11
0
static void
DesEncrypt( u_char *clear, /* IN  8 octets */
            u_char *key,   /* IN  7 octets */
            u_char *cipher /* OUT 8 octets */)
{
  u_char des_key[8];
  u_char crypt_key[66];
  u_char des_input[66];

  MakeKey(key, des_key);

  Expand(des_key, crypt_key);
  setkey((char*)crypt_key);

#if 0
  CHAPDEBUG(LOG_INFO, ("DesEncrypt: 8 octet input : %02X%02X%02X%02X%02X%02X%02X%02X\n",
             clear[0], clear[1], clear[2], clear[3], clear[4], clear[5], clear[6], clear[7]));
#endif

  Expand(clear, des_input);
  encrypt((char*)des_input, 0);
  Collapse(des_input, cipher);

#if 0
  CHAPDEBUG(LOG_INFO, ("DesEncrypt: 8 octet output: %02X%02X%02X%02X%02X%02X%02X%02X\n",
             cipher[0], cipher[1], cipher[2], cipher[3], cipher[4], cipher[5], cipher[6], cipher[7]));
#endif
}
Exemple #12
0
BOOL CVqf::SetField(char id1,char id2,char id3,char id4,const unsigned char *szData,DWORD dwSize)
{
	DWORD id = MakeKey(id1,id2,id3,id4);
	m_fields.erase(id);

	if(dwSize == 0)
	{
		return TRUE;
	}

	//mapに追加
	m_fields.insert(pair<DWORD,CVqfTag>(id,CVqfTag()));
	map<DWORD,CVqfTag>::iterator p = m_fields.find(id);
	if(p != m_fields.end())
	{
		p->second.SetData(szData,dwSize);
		unsigned char *data = p->second.GetData();
		if(!data)
		{
			//空のフィールドは作らない
			m_fields.erase(id);
		}
	}
	else
	{
		return FALSE;
	}
	return TRUE;
}
Exemple #13
0
void FWadCollection::InitHashChains (void)
{
	char name[8];
	unsigned int i, j;

	// Mark all buckets as empty
	memset (FirstLumpIndex, 255, NumLumps*sizeof(FirstLumpIndex[0]));
	memset (NextLumpIndex, 255, NumLumps*sizeof(NextLumpIndex[0]));
	memset (FirstLumpIndex_FullName, 255, NumLumps*sizeof(FirstLumpIndex_FullName[0]));
	memset (NextLumpIndex_FullName, 255, NumLumps*sizeof(NextLumpIndex_FullName[0]));

	// Now set up the chains
	for (i = 0; i < (unsigned)NumLumps; i++)
	{
		uppercopy (name, LumpInfo[i].lump->Name);
		j = LumpNameHash (name) % NumLumps;
		NextLumpIndex[i] = FirstLumpIndex[j];
		FirstLumpIndex[j] = i;

		// Do the same for the full paths
		if (LumpInfo[i].lump->FullName.IsNotEmpty())
		{
			j = MakeKey(LumpInfo[i].lump->FullName) % NumLumps;
			NextLumpIndex_FullName[i] = FirstLumpIndex_FullName[j];
			FirstLumpIndex_FullName[j] = i;
		}
	}
}
Exemple #14
0
static void DesEncrypt(
	u_char *clear,	/* IN  8 octets */
	u_char *key,	/* IN  7 octets */
	u_char *cipher	/* OUT 8 octets */
)
{
	des_cblock		des_key;
	des_key_schedule	key_schedule;
	
	MakeKey(key, des_key);
	
	des_set_key(&des_key, key_schedule);
	
#if 0
	CHAPDEBUG((LOG_INFO, "DesEncrypt: 8 octet input : %02X%02X%02X%02X%02X%02X%02X%02X\n",
	       clear[0], clear[1], clear[2], clear[3], clear[4], clear[5], clear[6], clear[7]));
#endif
	
	des_ecb_encrypt((des_cblock *)clear, (des_cblock *)cipher, key_schedule, 1);
	
#if 0
	CHAPDEBUG((LOG_INFO, "DesEncrypt: 8 octet output: %02X%02X%02X%02X%02X%02X%02X%02X\n",
	       cipher[0], cipher[1], cipher[2], cipher[3], cipher[4], cipher[5], cipher[6], cipher[7]));
#endif
}
Exemple #15
0
//创建频道对象
int32_t CChannelMgt::CreateChannel(const ChannelID channelID, ChannelPool::CIndex*& pIndex)
{
	//创建对象
	pIndex = m_channelPool.CreateObject();
	if (NULL == pIndex)
	{
		return E_RS_CREATECHANNEL;
	}

	//建立索引
	ChannelList::Key key = MakeKey(channelID);
	ChannelList::CIndex* pListIndex = m_channelList.Insert(key, pIndex->Index());
	if (NULL == pListIndex)
	{
		m_channelPool.DestroyObject(pIndex);
		pIndex = NULL;
		return E_RS_CREATECHANNELINDEX;
	}

	//将索引保存到附加数据表中
	int32_t ret = pIndex->SetAdditionalData(enmAdditionalIndex_HashListIndex, (uint32_t)pListIndex->Index());
	if (0 > ret)
	{
		m_channelList.Erase(pListIndex);
		m_channelPool.DestroyObject(pIndex);
		pIndex = NULL;
		return ret;
	}

	return S_OK;
}
Exemple #16
0
int ConfigFile::ValueHandler(void* user, const char* section, const char* name, const char* value)
{
	ConfigFile* reader = (ConfigFile*)user;

	// Add the value to the lookup map
	std::string key = MakeKey(section, name);
	if (reader->Values[key].size() > 0)
		reader->Values[key] += "\n";
	reader->Values[key] += value;

	// Insert the section in the sections set
	reader->Sections.insert(section);

	// Add the value to the values set
	std::string sectionKey = section;
	std::transform(sectionKey.begin(), sectionKey.end(), sectionKey.begin(), ::tolower);

	std::set<std::string>* fieldsSet;
	std::map<std::string, std::set<std::string>*>::iterator fieldSetIt = reader->Fields.find(sectionKey);
	if (fieldSetIt == reader->Fields.end())
	{
		fieldsSet = new std::set<std::string>();
		reader->Fields.insert(std::pair<std::string, std::set<std::string>*>(sectionKey, fieldsSet));
	}
	else {
		fieldsSet = fieldSetIt->second;
	}
	fieldsSet->insert(name);

	return 1;
}
Exemple #17
0
bool CChannel::IsRoomInChannel(const RoomIndex nRoomIndex)
{
	RoomIndexList::Key key = MakeKey(nRoomIndex);
	RoomIndexList::CIndex *pIndex = m_sRoomIndexList.Find(key);

	return NULL == pIndex;
}
Exemple #18
0
	bool FindCell(int x, int y) const
	{
		int theX = (x + m_width) % m_width;
		int theY = (y + m_height) % m_height;
		const auto& it = m_cellMap.find(MakeKey(theX, theY));
		return it != m_cellMap.end();			
	}
FTextureID FTextureManager::AddTexture (FTexture *texture)
{
	int bucket;
	int hash;

	if (texture == NULL) return FTextureID(-1);

	// Later textures take precedence over earlier ones

	// Textures without name can't be looked for
	if (texture->Name[0] != 0)
	{
		bucket = int(MakeKey (texture->Name) % HASH_SIZE);
		hash = HashFirst[bucket];
	}
	else
	{
		bucket = -1;
		hash = -1;
	}

	TextureHash hasher = { texture, hash };
	int trans = Textures.Push (hasher);
	Translation.Push (trans);
	if (bucket >= 0) HashFirst[bucket] = trans;
	return (texture->id = FTextureID(trans));
}
// Find a string by name. pentry1 is a pointer to a pointer to it, and entry1 is a
// pointer to it. Return NULL for entry1 if it wasn't found.
void FStringTable::FindString (const char *name, StringEntry **&pentry1, StringEntry *&entry1)
{
	DWORD bucket = MakeKey (name) & (HASH_SIZE - 1);
	StringEntry **pentry = &Buckets[bucket], *entry = *pentry;

	while (entry != NULL)
	{
		int cmpval = stricmp (entry->Name, name);
		if (cmpval == 0)
		{
			pentry1 = pentry;
			entry1 = entry;
			return;
		}
		if (cmpval == 1)
		{
			pentry1 = pentry;
			entry1 = NULL;
			return;
		}
		pentry = &entry->Next;
		entry = *pentry;
	}
	pentry1 = pentry;
	entry1 = entry;
}
std::string  LexicalReorderingTableCompact::MakeKey(const Phrase& f,
    const Phrase& e,
    const Phrase& c) const
{
  return MakeKey(Trim(f.GetStringRep(m_FactorsF)),
                 Trim(e.GetStringRep(m_FactorsE)),
                 Trim(c.GetStringRep(m_FactorsC)));
}
Exemple #22
0
OpenSSLKeyPair* OpenSSLKeyPair::Generate() {
  EVP_PKEY* pkey = MakeKey();
  if (!pkey) {
    LogSSLErrors("Generating key pair");
    return NULL;
  }
  return new OpenSSLKeyPair(pkey);
}
Exemple #23
0
int INIReader::ValueHandler(void* user, const char* section, const char* name, const char* value)
{
	INIReader* reader = (INIReader*)user;
	std::string key = MakeKey(section, name);
	if (reader->_values[key].size() > 0)
		reader->_values[key] += "\n";
	reader->_values[key] += value;
	return 1;
}
std::string
LexicalReorderingTableMemory::MakeKey(const Phrase& f,
                                      const Phrase& e,
                                      const Phrase& c) const
{
  return MakeKey(auxClearString(f.GetStringRep(m_FactorsF)),
                 auxClearString(e.GetStringRep(m_FactorsE)),
                 auxClearString(c.GetStringRep(m_FactorsC)));
}
Exemple #25
0
unsigned char *CVqf::GetField(char id1,char id2,char id3,char id4,DWORD *pdwSize)
{
	map<DWORD,CVqfTag>::iterator p = m_fields.find(MakeKey(id1,id2,id3,id4));
	if(p == m_fields.end())
	{
		return NULL;
	}
	*pdwSize = p->second.GetSize();
	return p->second.GetData();
}
Exemple #26
0
/* Do the DesEncryption */
void
DesEncrypt(unsigned char *clear, unsigned char *key, unsigned char *cipher)
{
  des_cblock des_key;
  des_key_schedule key_schedule;

  MakeKey(key, des_key);
  des_set_key(&des_key, key_schedule);
  des_ecb_encrypt((des_cblock *) clear, (des_cblock *) cipher, key_schedule, 1);
}
Exemple #27
0
bool ezImageConversion::IsConvertible(ezImageFormat::Enum sourceFormat, ezImageFormat::Enum targetFormat)
{
  if (!s_conversionTableValid)
  {
    RebuildConversionTable();
  }

  ezUInt32 tableIndex = MakeKey(sourceFormat, targetFormat);
  return s_conversionTable.Contains(tableIndex);
}
Exemple #28
0
int32_t CChannel::DeleteRoom(const RoomIndex nRoomIndex)
{
	RoomIndexList::Key key = MakeKey(nRoomIndex);
	int32_t ret = m_sRoomIndexList.Erase(key);
	if (0 <= ret)
	{
		--m_nCurRoomCount;
	}

	return S_OK;
}
Exemple #29
0
void SummaryCommand :: DoFreq( IOManager & io ) {
	CalcFreqs();

	for ( unsigned int i = 0; i < mRows.size(); i++ ) {
		string key = MakeKey( mRows.at(i) );
		unsigned int n = mFreqMap.find( key )->second.mFreq;
		CSVRow r = mRows.at(i);
		r.insert( r.begin(), ALib::Str( n ) );
		io.WriteRow( r );
	}
}
int ServiceConfig::ValueHandler(void* user, const char* section, const char* name, const char* value)
{
    ServiceConfig* reader = static_cast<ServiceConfig*>(user);
    string key = MakeKey(section, name);

    if (reader->_values[key].size() > 0)
        reader->_values[key] += "\n";

    reader->_values[key] += value;
    return 1;
}