예제 #1
0
/**
 * load a graph from the given string. string should follow the .lg format
 */
bool GraphX::loadFromString(string data, tr1::unordered_map<string, void* >& edgeToFreq)
{
	CL.clear();

	istringstream str(data);

	bool b = parseData(str, edgeToFreq);

	//destruct data in the 'edgeToFreq' structure
	for(tr1::unordered_map<string, void* >::iterator iter = edgeToFreq.begin();iter!=edgeToFreq.end();iter++)
	{
		delete ((Pattern*)iter->second);
	}
	edgeToFreq.clear();

	if(!b)
		return false;

	return true;
}
예제 #2
0
void addToCache (string request, string response) {
  
  string cacheKey = "";
  cacheKey.append (getReqType(request));
  cacheKey.append (getUri(request));
  cacheKey.append (getHost(request));

  // Critical Section
  pthread_mutex_lock(&cacheLock);
  try {
  if (cacheMap.size() < MAXCACHESIZE) {
    cacheMap.insert (make_pair<string, string>(cacheKey, response));
  } else {
    tr1::unordered_map<string,string>::const_iterator got = cacheMap.begin();
    cacheMap.erase (got);
    cacheMap.insert (make_pair<string, string>(cacheKey, response));
  }
  } catch (...) {
  }
  pthread_mutex_unlock(&cacheLock);
}