예제 #1
0
size_t
hash_value(const HmdRequestKey& key)
{
   std::size_t seed = 0;

   boost::hash<std::string> stringHash;

   const TwsApi::Contract& contract = key.contract();

   boost::hash_combine(seed, stringHash(contract.symbol));
   boost::hash_combine(seed, stringHash(contract.secType));
   boost::hash_combine(seed, stringHash(contract.exchange));
   boost::hash_combine(seed, stringHash(contract.currency));

   return seed;
}
 vector<string> findRepeatedDnaSequences(string s) {
     vector<string> result;
     if(s.length() < 10) {
         return result;
     }
     unordered_map <int, int> Map;
     
     string substr = s.substr(0, 10);
     int hash = stringHash(substr);
     Map[hash]++;
     
     for(int i = 10; i < s.length(); ++i) {
         int newHash = updateHash(hash, s[i]);
         Map[newHash]++;
         hash = newHash;
     }
     
     for(auto it = Map.begin(); it != Map.end(); ++it) {
         if(it->second > 1) {
             string str = hashToStr(it->first);
             result.push_back(str);
         }
     }
     return result;
 }
예제 #3
0
파일: file.cpp 프로젝트: bitshifter/Gource
RFile::RFile(std::string name, vec3f colour, vec2f pos, int tagid) : Pawn(name,pos,tagid) {
    hidden = true;
    icon = texturemanager.grab("file.png");
    size = gGourceFileDiameter;
    radius = size * 0.5f;

    speed = 5.0f;
    nametime = 4.0f;
    name_interval = nametime;

    namecol     = vec3f(1.0f, 1.0f, 1.0f);
    file_colour = colour;

    last_action = 0.0f;
    removing=false;

    shadow = true;

    distance = 0.0f;

    this->fullpath = name;
    this->name = name;
    path_hash = 0;

    setPath();

    namelist = glGenLists(1);

    setSelected(false);

    dir = 0;

    if(path.size()) path_hash = stringHash(path);
}
예제 #4
0
void IconFromUrlReader::parseTransformedStream(QByteArray transformedData){

    //Create iconfrom raw data
    QPixmap pm;
    pm.loadFromData(transformedData);
    QIcon ic;
    ic.addPixmap(pm);

    //Get path for image cache
    QDir baseDir(PUSER_APP_DIR);
    QString iconPath = baseDir.absoluteFilePath(ICON_SUBDIR_NAME);
    QDir d(iconPath);
    if(!d.exists()){ d.mkdir(iconPath); }
    int id = stringHash(getRequestURL());
    QString iconName = iconPath + PATH_SEP + "netcached" + QString("%1").arg(id);

    //Create thumbnail for image
    QPixmap thumbMap = ic.pixmap(QSize(64,64));
    thumbMap.save(iconName);

    //Connect to item
    m_filt.setOverrideIcon(iconName);
    m_results.append(m_filt);

}
vec2 vec2Hash(const std::string& str) {
    int hash = stringHash(str);

    int x = ((hash/7) % 255) - 127;
    int y = ((hash/3) % 255) - 127;

    vec2 v = normalise(vec2(x, y));

    return v;
}
예제 #6
0
void StringSet::rehashAll() {
	m_hashTableLoad = 0;
	size_t pos = 0;
	while (pos < m_data.size()) {
		const char* str = getString(pos);
		int len = strlen(str);
		addHashNoRehash(stringHash(str, len), pos);
		pos += len + 1;
	}
}
예제 #7
0
int StringSet::addStringL(const char* s, int slen) {
	int hash = stringHash(s, slen);
	int pos = findStringL(s, slen, hash);
	if (pos == -1) {
		pos = m_data.size();
		addHash(hash, pos);
		m_data.insert(m_data.end(), s, s + slen + 1);
	}
	return pos;
}
예제 #8
0
s32 ShaderProgram::getUniformLocation(const String& name) const
{
	const u64 hash = stringHash(name);

	if (has(m_uniformLocations, hash))
		return get(m_uniformLocations, hash, 0);

	s32 loc = glGetUniformLocation(handle, cString(name));
	set(m_uniformLocations, hash, loc);
	return loc;
}
vec3 vec3Hash(const std::string& str) {
    int hash = stringHash(str);

    int x = ((hash/7) % 255) - 127;
    int y = ((hash/3) % 255) - 127;
    int z = hash % 255;

    vec3 v = normalise(vec3(x, y, z));

    return v;
}
예제 #10
0
vec3 colourHash(const std::string& str) {
    int hash = stringHash(str);

    int r = (hash/7) % 255;
    if(r<0) r=0;
    int g = (hash/3) % 255;
    if(g<0) g=0;
    int b = hash % 255;

    vec3 colour = normalise(vec3(r, g, b));

    return colour;
}
예제 #11
0
uint64_t fileExtHash(string file, string ext)
{
	uint64_t hash1 = 0, hash2 = 0, hash3 = 0;
	auto len = file.length();

	if (len > 0)
		hash1 = file[len - 1] + (len > 2 ? (file[len - 2] << 8) : 0) + (len << 16) + (file[0] << 24);

	if (len > 3)
		hash2 = stringHash(file.substr(1, len - 3));

	if (ext.length() > 0)
	{
		hash3 = stringHash(ext);

		if		(ext == ".kf")	hash1 |= 0x80;
		else if (ext == ".nif") hash1 |= 0x8000;
		else if (ext == ".dds") hash1 |= 0x8080;
		else if (ext == ".wav") hash1 |= 0x80000000;
	}

	hash2 = (hash2 + hash3) & 0xFFFFFFFF;
	return (hash2 << 32) + hash1;
}
예제 #12
0
파일: process.c 프로젝트: vanjac/Minus
void flushWord(wordLen)
{
  word[wordLen] = 0;
  unsigned long hash = stringHash(word, wordLen);
  int i;
  bool matchFound = FALSE;
  Keyword match;
  for(i = 0; i < numKeywords; i++) {
    Keyword k = keywords[i];
    if(k.nameHash == hash) {
      matchFound = TRUE;
      match = k;
    }
  }

  if(matchFound)
    processAddString(match.value, match.valueSize);
  else
    processAddString(word, WORD_SIZE);
}
예제 #13
0
파일: file.cpp 프로젝트: Br3nda/Gource
RFile::RFile(const std::string & name, const vec3f & colour, const vec2f & pos, int tagid) : Pawn(name,pos,tagid) {
    hidden = true;
    size = gGourceFileDiameter;
    radius = size * 0.5;

    setGraphic(gGourceSettings.file_graphic);

    speed = 5.0;
    nametime = 4.0;
    name_interval = nametime;

    namecol     = vec3f(1.0, 1.0, 1.0);
    file_colour = colour;

    last_action = 0.0;
    expiring=false;
    removing=false;

    shadow = true;

    distance = 0;

    this->fullpath = name;
    this->name = name;

    path_hash = 0;

    setPath();

    namelist = glGenLists(1);

    font = 0;
    setSelected(false);

    dir = 0;

    if(path.size()) path_hash = stringHash(path);
}
//-----------------------------------------------------------------------------
GpuProgramPtr ProgramManager::createGpuProgram(Program* shaderProgram, 
											   ProgramWriter* programWriter,
											   const String& language,
											   const String& profiles,
											   const StringVector& profilesList,
											   const String& cachePath)
{

	
#if OGRE_PLATFORM == OGRE_PLATFORM_ANDROID
	Ogre::StringSerialiser sourceCodeStringStream;
#else
	std::stringstream sourceCodeStringStream;
#endif
	_StringHash stringHash;
	uint32 programHashCode;
	String programName;

	// Generate source code.
	programWriter->writeSourceCode(sourceCodeStringStream, shaderProgram);

	// Generate program hash code.
	programHashCode = static_cast<uint32>(stringHash(sourceCodeStringStream.str()));

	// Generate program name.
	programName = StringConverter::toString(programHashCode);
	
	if (shaderProgram->getType() == GPT_VERTEX_PROGRAM)
	{
		programName += "_VS";
	}
	else if (shaderProgram->getType() == GPT_FRAGMENT_PROGRAM)
	{
		programName += "_FS";
	}

	HighLevelGpuProgramPtr pGpuProgram;

	// Try to get program by name.
	pGpuProgram = HighLevelGpuProgramManager::getSingleton().getByName(programName);

	// Case the program doesn't exist yet.
	if (pGpuProgram.isNull())
	{
		// Create new GPU program.
		pGpuProgram = HighLevelGpuProgramManager::getSingleton().createProgram(programName,
			ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, language, shaderProgram->getType());

		// Case cache directory specified -> create program from file.
		if (cachePath.empty() == false)
		{
			const String  programFullName = programName + "." + language;
			const String  programFileName = cachePath + programFullName;	
			std::ifstream programFile;
			bool		  writeFile = true;


			// Check if program file already exist.
			programFile.open(programFileName.c_str());

			// Case no matching file found -> we have to write it.
			if (!programFile)
			{			
				writeFile = true;
			}
			else
			{
				writeFile = false;
				programFile.close();
			}

			// Case we have to write the program to a file.
			if (writeFile)
			{
				std::ofstream outFile(programFileName.c_str());

				if (!outFile)
					return GpuProgramPtr();

				outFile << sourceCodeStringStream.str();
				outFile.close();
			}

			pGpuProgram->setSourceFile(programFullName);
		}

		// No cache directory specified -> create program from system memory.
		else
		{
			pGpuProgram->setSource(sourceCodeStringStream.str());
		}
		
		
		pGpuProgram->setParameter("entry_point", shaderProgram->getEntryPointFunction()->getName());

		// HLSL program requires specific target profile settings - we have to split the profile string.
		if (language == "hlsl")
		{
			StringVector::const_iterator it = profilesList.begin();
			StringVector::const_iterator itEnd = profilesList.end();
			
			for (; it != itEnd; ++it)
			{
				if (GpuProgramManager::getSingleton().isSyntaxSupported(*it))
				{
					pGpuProgram->setParameter("target", *it);
					break;
				}
			}
		}
		
		pGpuProgram->setParameter("profiles", profiles);
		pGpuProgram->load();
	
		// Case an error occurred.
		if (pGpuProgram->hasCompileError())
		{
			pGpuProgram.setNull();
			return GpuProgramPtr(pGpuProgram);
		}

		// Add the created GPU program to local cache.
		if (pGpuProgram->getType() == GPT_VERTEX_PROGRAM)
		{
			mVertexShaderMap[programName] = pGpuProgram;			
		}
		else if (pGpuProgram->getType() == GPT_FRAGMENT_PROGRAM)
		{
			mFragmentShaderMap[programName] = pGpuProgram;	
		}				
	}
	
	return GpuProgramPtr(pGpuProgram);
}
예제 #15
0
int main() {

	const int SIZE = 9973;
	string input;
	ifstream inFile;
	string one;
	string two;
	string three;
	string four;
	string five;
	string six;
	string seven;
	string option;

	//array of Binary Search Tree objects where each index is a hashed string
	BSTree obs[SIZE];
	
	/*
	Set of the top 99 most common words in the english language
	This set of words wont be added to our hash table
	"The" is missing from this set because it is needed for a required query
	*/
	set<string> words{"be", "to", "of", "and", "a", "in", "that", "have", "i", "it", "for", "not", "on", "with", "he", "as", "you", "do", "at",
		"this", "but", "his", "by", "from", "they", "we", "say", "her", "she", "or", "an", "will", "my", "one", "all", "would", "there", "their", "what", "so",
		"up", "out", "if", "about", "who", "get", "which", "go", "me", "when", "make", "can", "like", "time", "no", "just", "him", "know", "take", "people", "into",
		"year", "your", "good", "some", "could", "them", "see", "other", "than", "then", "now", "look", "only", "come", "its", "over", "think", "also", "back",
		"after", "use", "two", "how", "our", "work", "first", "well", "way", "even", "new", "want", "because", "any", "these", "give", "day", "most", "us"};

	//set of all files that contain the words we are indexing
	set<string> file{ "cranfield0032", "cranfield0016", "cranfield0040", "cranfield0008", "cranfield0024", "cranfield0036", "cranfield0044"
		, "cranfield0004", "cranfield0012", "cranfield0020", "cranfield0028", "cranfield0034", "cranfield0038", "cranfield0042", "cranfield0048" 
		, "cranfield0002", "cranfield0006", "cranfield0010", "cranfield0014", "cranfield0018", "cranfield0022", "cranfield0026", "cranfield0030" 
		, "cranfield0033", "cranfield0035", "cranfield0037", "cranfield0039", "cranfield0041", "cranfield0043", "cranfield0046", "cranfield0049" 
		, "cranfield0001", "cranfield0003", "cranfield0005", "cranfield0007", "cranfield0009", "cranfield0011", "cranfield0013", "cranfield0015" 
		, "cranfield0017", "cranfield0019", "cranfield0021", "cranfield0023", "cranfield0025", "cranfield0027", "cranfield0029", "cranfield0031" 
		, "cranfield0045", "cranfield0047", "cranfield0050"};
	
	//auto increment over the set named file
	for (auto f : file) {
		inFile.open(f);
		while (inFile >> input) {
			//if the line begins with < or . or - or if the word is containined in the set named words then skip to next word
			if (input.at(0) == '<' || words.count(input) || input.at(0) == '.' || input.at(0) == '-') {
				inFile.ignore(1, '\n');
			}
			else {
				//if the file is not already contained in the tree then add the filename to the tree
				if (obs[stringHash(input)].search(f, obs[stringHash(input)].Root()) == false) {
					obs[stringHash(input)].insertNode(f);
				}				
			}
		}
		inFile.close();
	}

	//ask for user input then store in strings using stringstream
	cout << "Enter a Query or Type Q or q to Quit" << endl;
	getline(cin, option);
	stringstream ss(option);

	while (true) {
		getline(ss, one, ' ');
		getline(ss, two, ' ');
		getline(ss, three, ' ');
		getline(ss, four, ' ');
		getline(ss, five, ' ');
		getline(ss, six, ' ');
		getline(ss, seven, ' ');

		//Prints out query for one word
		if (two == "") {
			cout << one << " is found in the following files:" << endl;
			obs[stringHash(one)].inOrder(obs[stringHash(one)].Root());					
		}
		//Print out query for two words with an AND inbetween e.g. (flow AND stream)
		else if (two == "AND" && four == "") {
			cout << one << " " << two << " " << three << " are found in the following files:" << endl;
			for (auto f : file) {
				if (obs[stringHash(one)].search(f, obs[stringHash(one)].Root()) == true && obs[stringHash(three)].search(f, obs[stringHash(three)].Root()) == true) {
					cout << f << endl;
				}
			}
		}
		//Print out query for two words with an OR inbetween e.g. (flow OR stream)
		else if (two == "OR" && four == "") {
			cout << one << " " << two << " " << three << " are found in the following files:" << endl;
			for (auto f : file) {
				if (obs[stringHash(one)].search(f, obs[stringHash(one)].Root()) == true || obs[stringHash(three)].search(f, obs[stringHash(three)].Root()) == true) {
					cout << f << endl;
				}
			}
		}
		//Prints out query for three words with AND inbetween e.g. (the AND boundary AND layer)
		else if (two == "AND" && four == "AND" && six == "") {
			cout << one << " " << two << " " << three << " " << four << " " << five << " are found in the following files:" << endl;
			for (auto f : file) {
				if (obs[stringHash(one)].search(f, obs[stringHash(one)].Root()) == true && obs[stringHash(three)].search(f, obs[stringHash(three)].Root()) == true && obs[stringHash(five)].search(f, obs[stringHash(five)].Root()) == true) {
					cout << f << endl;
				}
			}
		}
		//Prints out query for three words with OR inbetween e.g. (the OR boundary OR layer)
		//It is also important to understand that OR statements will print out the file name if that file contains any of the words in your query
		else if (two == "OR" && four == "OR" && six == "") {
			cout << one << " " << two << " " << three << " " << four << " " << five << " are found in the following files:" << endl;
			for (auto f : file) {
				if (obs[stringHash(one)].search(f, obs[stringHash(one)].Root()) == true || obs[stringHash(three)].search(f, obs[stringHash(three)].Root()) == true || obs[stringHash(five)].search(f, obs[stringHash(five)].Root()) == true) {
					cout << f << endl;
				}
			}
		}
		//Prints out query for one grouping of two words or another word e.g ((flow AND stream) OR velocity)
		//if either return true then the filename is printed to the query
		else if (two == "AND" && four == "OR" && six == "") {
			cout << one << " " << two << " " << three << " " << four << " " << five << " are found in the following files:" << endl;
			for (auto f : file) {
				if ((obs[stringHash(one)].search(f, obs[stringHash(one)].Root()) == true && obs[stringHash(three)].search(f, obs[stringHash(three)].Root()) == true) || obs[stringHash(five)].search(f, obs[stringHash(five)].Root()) == true) {
					cout << f << endl;
				}
			}
		}
		//Prints out query for two groupings of words with AND between the words in the groups and OR between the main groupings e.g (reynolds AND number OR reynolds AND numbers)
		//This will print out in this format ((reynolds AND number) OR (reynolds AND numbers)) where if either group returns true the filename will be printed
		else if (two == "AND" && four == "OR" && six == "AND") {
			cout << one << " " << two << " " << three << " " << four << " " << five << " " << six << " " << seven << " are found in the following files:" << endl;
			for (auto f : file) {
				if ((obs[stringHash(one)].search(f, obs[stringHash(one)].Root()) == true && obs[stringHash(three)].search(f, obs[stringHash(three)].Root()) == true) || (obs[stringHash(five)].search(f, obs[stringHash(five)].Root()) == true && obs[stringHash(seven)].search(f, obs[stringHash(seven)].Root()))) {
					cout << f << endl;
				}
			}
		}
		//Prints out query for two groupings of words with OR between the words in the groups and OR between the main groupings e.g (reynolds OR number OR reynolds OR numbers)
		//This will print out in this format ((reynolds OR number) OR (reynolds OR numbers)) where if either group returns true the filename will be printed
		else if (two == "OR" && four == "OR" && six == "OR") {
			cout << one << " " << two << " " << three << " " << four << " " << five << " " << six << " " << seven << " are found in the following files:" << endl;
			for (auto f : file) {
				if ((obs[stringHash(one)].search(f, obs[stringHash(one)].Root()) == true || obs[stringHash(three)].search(f, obs[stringHash(three)].Root()) == true) || (obs[stringHash(five)].search(f, obs[stringHash(five)].Root()) == true || obs[stringHash(seven)].search(f, obs[stringHash(seven)].Root()))) {
					cout << f << endl;
				}
			}
		}
		
		//If input == Q or == q then the program exits
		if (option == "Q" || option == "q") {
			break;
		}
		//empty all saved strings ask for user input then restore strings from stringstream
		else {
			one.clear();
			two.clear();
			three.clear();
			four.clear();
			five.clear();
			six.clear();
			seven.clear();

			cout << "Enter a Query or Type Q or q to Quit" << endl;
			getline(cin, option);
			stringstream ss(option);
			getline(ss, one, ' ');
			getline(ss, two, ' ');
			getline(ss, three, ' ');
			getline(ss, four, ' ');
			getline(ss, five, ' ');
			getline(ss, six, ' ');
			getline(ss, seven, ' ');
		}
	}

	return 0;
}
예제 #16
0
void CRandomGenerator::resetSeed()
{
	boost::hash<std::string> stringHash;
	auto threadIdHash = stringHash(boost::lexical_cast<std::string>(boost::this_thread::get_id()));
	setSeed(threadIdHash * std::time(nullptr));
}
예제 #17
0
void QHashedCStringRef::computeHash() const
{
    m_hash = stringHash(m_data, m_length);
}
예제 #18
0
void QHashedString::computeHash() const
{
    m_hash = stringHash(constData(), length());
}
예제 #19
0
void ShaderProgram::bindAttribLocation(s32 location, const String& name)
{
	glBindAttribLocation(handle, location, cString(name));
	set(m_attribLocations, stringHash(name), location);
}
예제 #20
0
파일: process.c 프로젝트: vanjac/Minus
void processFile(FILE * file)
{
  bool inKeyword = FALSE;
  int wordLen = 0;
  
  int c;
  while((c = fgetc(file)) != EOF) {
    
    if(isWhitespace(c)) {
      whitespace = TRUE;
    }
    
    else if(c == '\n') {
      if(!lineIsEmpty) {
	flushWord(wordLen);
	wordLen = 0;
	processAddChar('\n');
      }
      lineIsEmpty = TRUE;
    }
    
    else if(c == '#' && lineIsEmpty) {
      while(c != EOF && c != '\n')
	c = fgetc(file);
    }
    
    else if(c == '"') {
      flushWhitespace(&wordLen);
      
      c = fgetc(file);
      bool addWhitespace = FALSE;
      while(c != EOF && c != '"') {
	lineIsEmpty = FALSE;

	if(addWhitespace)
	  processAddChar(' ');
	
        char cString[4];
	sprintf(cString, "%d", c);
	processAddString(cString, sizeof(cString) / sizeof(char));
        addWhitespace = TRUE;
	
	c = fgetc(file);
      }
      whitespace = FALSE;
    }

    else if(c == '`' && lineIsEmpty) {
      char fileName[256];
      int i;
      for(i = 0; i < sizeof(fileName)/sizeof(char) - 1; i++) {
	c = fgetc(file);
	if(c == EOF || c == '\n') {
	  fileName[i] = 0;
	  break;
	}
	fileName[i] = c;
      }
      fileName[sizeof(fileName)/sizeof(char)-1] = 0;
      FILE * newFile = readFile(fileName);
      processFile(newFile);
      fclose(newFile);
    }

    else if(c == '$') {
      if(inKeyword) { //complete the current keyword
        flushWord(wordLen);
	wordLen = 0;
	
	Keyword * kPtr = (Keyword *)(currentOutStream.data);
	Keyword k = *kPtr;
	processedProgramStream(&currentOutStream);
	inKeyword = FALSE;
	lineIsEmpty = TRUE;
      } else { // not in keyword, start a new one
	//allocate memory for a new keyword...
	if(numKeywords >= MAX_KEYWORDS)
	  error("Max keywords reached!");
	if(numKeywords >= keywordsSize) {
	  keywordsSize += KEYWORD_BLOCK;
	  keywords = (Keyword *)realloc(keywords,
					keywordsSize * sizeof(Keyword));
	  if(keywords == NULL)
	    error("Couldn't allocate keyword memory!");
	}
	numKeywords++;

	Keyword * k = &keywords[numKeywords - 1];

	//get name
	char name[KEYWORD_NAME_LEN];
	int i = 0;
	char c;
	while((c = fgetc(file)) != EOF
	      && !isWhitespace(c)
	      && c != '\n') {
	  if(i >= KEYWORD_NAME_LEN)
	    error("Keyword name too long!");
	  name[i++] = c;
	}
	name[i] = 0;
	(*k).nameHash = stringHash(name, i);

        keywordStream(k, &currentOutStream);
	inKeyword = TRUE;

	whitespace = FALSE;
	lineIsEmpty = FALSE;
      }
    }
    
    else {
      flushWhitespace(&wordLen);
      whitespace = FALSE;
      lineIsEmpty = FALSE;

      if(wordLen >= WORD_SIZE)
	error("Maximum word size reached!");
      word[wordLen++] = c;
    }
	
  }

  if(!lineIsEmpty) {
    flushWord(wordLen);
    processAddChar('\n'); // end with a newline
    lineIsEmpty = TRUE;
  }
}
예제 #21
0
int StringSet::findString(const char* s) const {
	int len = strlen(s);
	return findStringL(s, len, stringHash(s, len));
}
예제 #22
0
bool StringSet::containsString(const char* s) const {
	int len = strlen(s);
	return findStringL(s, len, stringHash(s, len)) != -1;
}