예제 #1
0
	void set_union(std::unordered_set<key_type>& key1,
                   std::unordered_set<key_type>& key2, 
                   std::unordered_set<key_type>& final_set) {
		for(auto it = key1.begin(); it != key1.end(); ++it) {
			final_set.insert(*it);
		}
		for(auto it = key2.begin(); it != key2.end(); ++it) {
			final_set.insert(*it);
		}
	}
/*
 *	Measure the time it takes for android_lookupEventFormat_len
 */
static void BM_lookupEventFormat(benchmark::State& state) {
  prechargeEventMap();

  std::unordered_set<uint32_t>::const_iterator it = set.begin();

  while (state.KeepRunning()) {
    size_t len;
    android_lookupEventFormat_len(map, &len, (*it));
    ++it;
    if (it == set.end()) it = set.begin();
  }
}
예제 #3
0
void DirectedGraph<T>::
insert(T const &node, std::unordered_set<T> const &adjacent)
{
    _nodes.insert(node);
    _nodes.insert(adjacent.begin(), adjacent.end());

    auto it = _adjacency.find(node);
    if (it == _adjacency.end()) {
        _adjacency.insert(std::make_pair(node, adjacent));
    } else {
        it->second.insert(adjacent.begin(), adjacent.end());
    }
}
예제 #4
0
std::vector<FocusedIntervalQuery> ExpSetupHelper::genSearchQueries(vector<std::vector<std::string> > templates,
                                                                   double queryZipfParam,
                                                                   int numQueries,
                                                                   uint64_t& tsStart,
                                                                   uint64_t& tsEnd,
                                                                   double delta,
                                                                   std::unordered_set<int64_t> const & vertices)
{
    std::vector<core::FocusedIntervalQuery> queries;

    std::vector<int64_t> vertexList;
    std::copy(vertices.begin(), vertices.end(),
               std::back_inserter(vertexList));

    int numQueryTypes = templates.size();
    util::ZipfRand queryGen_(queryZipfParam, numQueryTypes);
    unsigned seed = time(NULL);
    queryGen_.setSeed(seed++);

    // use a random start node for the interval query
    size_t vertexIdMean = (vertices.size()) / 2;
    double vertexIdStdDev = vertexIdMean - 1;
    util::NormalRand vertexIdGen(vertexIdMean, vertexIdStdDev,
                           0, vertices.size()-1);


    // use a random start time for the interval query
    double offset = (delta * (tsEnd - tsStart));

    size_t timeMean = tsStart + (((tsEnd - offset) - tsStart) / 2);

    double timeStdDev = timeMean - 1;
    util::NormalRand timeGen(timeMean, timeStdDev,
                           tsStart, tsStart+offset);



    std::cout << "tsStart " << tsStart << std::endl;
    std::cout << "tsEnd " << tsEnd << std::endl;
    std::cout << "timeMean " << timeMean << std::endl;
    std::cout << "offset " << offset << std::endl;

    int vertexIndex;
    int templateIndex;
    uint64_t start;
    uint64_t end;

    VertexId vi;
    for (int i = 0; i < numQueries; i++) {
        templateIndex = numQueryTypes > 1 ? queryGen_.getRandomValue() : 0;
        vertexIndex = vertexIdGen.getRandomValue();
        start = timeGen.getRandomValue();
        end = start + offset;
        vi = vertexList.at(vertexIndex);
        std::cout << "start " << start << std::endl;
        queries.push_back(FocusedIntervalQuery(
                              vi, start, end, templates[templateIndex]));
    }
    return queries;
}
예제 #5
0
void repository::distributor::create_recursively(
    const boost::filesystem::path &root, const bool strip) {
  try {
    std::unordered_set<std::string> ignore;
    const boost::filesystem::path index_path = root / format().name.get_index();
    if (boost::filesystem::is_regular_file(index_path)) {
      BUNSAN_LOG_DEBUG << "Found index file at " << root
                       << ", trying to create source package...";
      ignore.insert(format().name.get_index());
      create(root, strip);
      index index_;
      index_.load(index_path);
      const std::unordered_set<std::string> sources = index_.sources();
      ignore.insert(sources.begin(), sources.end());
    }
    for (boost::filesystem::directory_iterator i(root), end; i != end; ++i) {
      if (boost::filesystem::is_directory(*i) &&
          ignore.find(i->path().filename().string()) == ignore.end()) {
        create_recursively(i->path(), strip);
      }
    }
  } catch (distributor_create_recursively_error &) {
    throw;
  } catch (std::exception &) {
    BOOST_THROW_EXCEPTION(distributor_create_recursively_error()
                          << distributor_create_recursively_error::root(root)
                          << distributor_create_recursively_error::strip(strip)
                          << enable_nested_current());
  }
}
예제 #6
0
 void doWalkFunction(Function* func) {
   Flat::verifyFlatness(func);
   // Build the data-flow IR.
   graph.build(func, getModule());
   nodeUsers.build(graph);
   // Propagate optimizations through the graph.
   std::unordered_set<DataFlow::Node*> optimized; // which nodes we optimized
   for (auto& node : graph.nodes) {
     workLeft.insert(node.get()); // we should try to optimize each node
   }
   while (!workLeft.empty()) {
     //std::cout << "\n\ndump before work iter\n";
     //dump(graph, std::cout);
     auto iter = workLeft.begin();
     auto* node = *iter;
     workLeft.erase(iter);
     workOn(node);
   }
   // After updating the DataFlow IR, we can update the sets in
   // the wasm.
   // TODO: we also need phis, as a phi can flow directly into say
   //       a return or a call parameter.
   for (auto* set : graph.sets) {
     auto* node = graph.setNodeMap[set];
     auto iter = optimized.find(node);
     if (iter != optimized.end()) {
       assert(node->isExpr()); // this is a set, where the node is defined
       set->value = node->expr;
     }
   }
 }
 inline DirectedGraph::node_id chooseVictim(
     const std::unordered_set<DirectedGraph::node_id> &nodes_set) const {
   // TODO(Hakan): This is very inefficient scheme, however in the
   //              future, we can use the transaction's priority
   //              as the victim selection parameter.
   return *(nodes_set.begin());
 }
예제 #8
0
	VectorCodec(std::string corpus, int vecLength = 0) {
		for (int i = 0; i < corpus.length(); i++) {
			alphabet.emplace(corpus[i]);
		}
		nSymbols = alphabet.size();
				
		if (vecLength == 0) { //auto
			N = nSymbols;
		} else {
			N = vecLength;
		}
		vector.resize(N, 0.0f);
		
		for (int i = 0; i < 256; i++) { tableStoI[i] = 0; tableItoS[i] = 0; }
		
		int index = 0;
		for (auto itr = alphabet.begin(); itr != alphabet.end(); ++itr) {
			tableStoI[*itr] = index;
			tableItoS[index] = *itr;
			index++;
		}
		
		symbol = 0;
		symIndex = 0;
	}
예제 #9
0
std::vector<FocusedIntervalQuery> ExpSetupHelper::genQueries(vector<std::vector<std::string> > templates,
                                                             double queryZipfParam,
                                                             int numQueries,
                                                             uint64_t& tsStart,
                                                             uint64_t& tsEnd,
                                                             std::unordered_set<int64_t> const & vertices)
{
    std::vector<core::FocusedIntervalQuery> queries;

    std::vector<int64_t> vertexList;
    std::copy(vertices.begin(), vertices.end(),
               std::back_inserter(vertexList));

    int numQueryTypes = templates.size();
    util::ZipfRand queryGen_(queryZipfParam, numQueryTypes);
    unsigned seed = time(NULL);
    queryGen_.setSeed(seed++);

    // use a random start node for the interval query
    size_t vertexIdMean = (vertices.size()) / 2;
    double vertexIdStdDev = vertexIdMean - 1;
    util::NormalRand vertexIdGen(vertexIdMean, vertexIdStdDev,
                           0, vertices.size()-1);

    int vertexIndex;
    int templateIndex;
    for (int i = 0; i < numQueries; i++) {
        templateIndex = numQueryTypes > 1 ? queryGen_.getRandomValue() : 0;
        vertexIndex = vertexIdGen.getRandomValue();
        VertexId vi = vertexList.at(vertexIndex);
        queries.push_back(FocusedIntervalQuery(
                              vi, tsStart, tsEnd, templates[templateIndex]));
    }
    return queries;
}
double predict(const std::unordered_map<double, std::vector<double> > &model,
               const std::unordered_set<double> &label_set,
               const std::vector<double> &feats)
{
    // binary classification
    if (model.size() == 1) {
        std::unordered_set<double>::const_iterator lit = label_set.begin();
        const double label1 = *(lit++);
        const double label2 = *lit;
        const std::unordered_map<double, std::vector<double> >::const_iterator mit = model.find(label1);
        assert(mit != model.end());

        return hypothesis(mit->second, feats) > 0.5 ? label1 : label2;
    }

    double max_hyp = -1;
    double max_label = -1;
    for (std::unordered_map<double, std::vector<double> >::const_iterator it = model.begin();
         it != model.end();
         ++it)
    {
        double hyp = hypothesis(it->second, feats);
        if (hyp > max_hyp) {
            max_hyp = hyp;
            max_label = it->first;
        }
    }
    assert(max_hyp != -1);
    assert(max_label != -1);

    return max_label;
}
예제 #11
0
// Add a collection of timers to the data store.  The collection is emptied by
// this operation, since the timers are now owned by the store.
void TimerStore::add_timers(std::unordered_set<Timer*>& set)
{
  for (auto it = set.begin(); it != set.end(); ++it)
  {
    add_timer(*it);
  }
  set.clear();
}
예제 #12
0
파일: union.cpp 프로젝트: drzeus99/PPB-2.0
std::unordered_set<uint64_t> Union::operator() (const std::unordered_set<uint64_t>& first, const std::unordered_set<uint64_t>& second)
{
    std::unordered_set<uint64_t> answer(first);
    std::for_each(second.begin(), second.end(), [&answer] (const uint64_t val) {
             answer.insert(val);
             });
    return answer;
}
예제 #13
0
std::string findIncludeFile(std::string includeFileName, std::ostream& os, std::unordered_set<std::string>& includeSearchDirs)
{
    for(auto it = includeSearchDirs.begin(); it != includeSearchDirs.end(); ++it) 
    {
        boost::filesystem::path pathToFile(*it);
        pathToFile /= includeFileName;
        if(boost::filesystem::exists(pathToFile) && boost::filesystem::is_regular_file(pathToFile))
        {
            boost::filesystem::absolute(pathToFile);
            return pathToFile.string();
        }
    }
    std::cerr << "include file " << includeFileName << " not found, search path was: ";
    for(auto it = includeSearchDirs.begin(); it != includeSearchDirs.end(); ++it) 
        std::cerr << *it << " ";
    std::cerr << std::endl;
    exit(-1);
}
예제 #14
0
bithorde::RouteTrace ForwardedAsset::requestTrace(const std::unordered_set<uint64_t>& requesters) const
{
	bithorde::RouteTrace requesters_;
	requesters_.Add(sessionId());
	for (auto iter=requesters.begin(); iter != requesters.end(); iter++) {
		requesters_.Add(*iter);
	}
	return requesters_;
}
예제 #15
0
파일: prover.cpp 프로젝트: tpagram/sddtab
/*
 *	Determine whether two sets share any elements.
 */
bool Prover::shareAnElement(const std::unordered_set<SddLiteral>& firstSet,
					const std::unordered_set<SddLiteral>& secondSet) {
	if (firstSet.size() < secondSet.size()) {
		for (std::unordered_set<SddLiteral>::const_iterator it = firstSet.begin(); it != firstSet.end(); ++it) {
			if (secondSet.count(*it) != 0) {
				return true;
			}
		}
		return false;
	} else {
		for (std::unordered_set<SddLiteral>::const_iterator it = secondSet.begin(); it != secondSet.end(); ++it) {
			if (firstSet.count(*it) != 0) {
				return true;
			}
		}
		return false;
	}
}
예제 #16
0
	// Returns all the keys in keys1 - keys2
	void set_difference(std::unordered_set<key_type>& keys1, 
                        std::unordered_set<key_type>& keys2, 
                        std::unordered_set<key_type>& result) {
		for(auto it = keys1.begin(); it != keys1.end(); ++it) {
			if( keys2.find(*it) == keys2.end() ) {
				result.insert(*it);
			}
		}
	}
예제 #17
0
	void set_intersection(std::unordered_set<key_type>& key1, 
                          std::unordered_set<key_type>& key2, 
                          std::unordered_set<key_type>& intersection) {
		for(auto it1 = key1.begin(); it1 != key1.end(); ++it1) {
			if( key2.find(*it1) != key2.end() ) {
				intersection.insert(*it1);
			}
		}
	}
/*
 *	Measure the time it takes for android_lookupEventTagNum plus above
 */
static void BM_lookupEventTagNum(benchmark::State& state) {
  prechargeEventMap();

  std::unordered_set<uint32_t>::const_iterator it = set.begin();

  while (state.KeepRunning()) {
    size_t len;
    const char* name = android_lookupEventTag_len(map, &len, (*it));
    std::string Name(name, len);
    const char* format = android_lookupEventFormat_len(map, &len, (*it));
    std::string Format(format, len);
    state.ResumeTiming();
    android_lookupEventTagNum(map, Name.c_str(), Format.c_str(),
                              ANDROID_LOG_UNKNOWN);
    state.PauseTiming();
    ++it;
    if (it == set.end()) it = set.begin();
  }
}
예제 #19
0
std::string join_set_strings(const std::unordered_set<std::string>& db_types_all, const char* delim)
{
  std::string result;
  std::ostringstream s;
  std::copy(db_types_all.begin(), db_types_all.end(), std::ostream_iterator<std::string>(s, delim));
  result = s.str();
  if (result.length() > 0)
    result.erase(result.end()-strlen(delim), result.end());
  return result;
}
const DesignFlowStepSet FrontendFlowStepFactory::GenerateFrontendSteps(const std::unordered_set<FrontendFlowStepType> frontend_flow_step_types) const
{
   DesignFlowStepSet frontend_flow_steps;
   std::unordered_set<FrontendFlowStepType>::const_iterator frontend_flow_step_type, frontend_flow_step_type_end = frontend_flow_step_types.end();
   for(frontend_flow_step_type = frontend_flow_step_types.begin(); frontend_flow_step_type != frontend_flow_step_type_end; frontend_flow_step_type++)
   {
      frontend_flow_steps.insert(GenerateFrontendStep(*frontend_flow_step_type));
   }
   return frontend_flow_steps;
}
예제 #21
0
 bool wordBreak(std::string s, std::unordered_set<std::string> &dict) {
     if (dict.empty())
         return false;
     int len = s.size(), max_len = dict.begin()->size(), min_len = max_len;
     for (auto it = dict.begin(); it != dict.end(); ++it)
         if (it->size() > max_len)
             max_len = it->size();
         else if (it->size() < min_len)
             min_len = it->size();
     std::vector<int> flag(len + 1);
     flag[len] = 1;
     for (int i = len - 1; i >= 0; --i)
         for (int j = min_len; j <= std::min(max_len, len - i); ++j)
             if (flag[i + j] && dict.find(s.substr(i, j)) != dict.end()) {
                 flag[i] = 1;
                 break;
             }
     return flag[0] == 1;
 }
예제 #22
0
void checkResults(std::unordered_set<key_type>& expected, std::unordered_set<key_type>& actual) {
	if( expected.size() != actual.size() ) {
		printf("Expected: %zu, Actual: %zu\n", expected.size(), actual.size());
		return;
	}

	for(auto it1 = expected.begin(); it1 != expected.end(); ++it1 ) {
		assert( actual.find(*it1) != actual.end() );
	}
}
ATTID  AttributeSelectionHeuristic ::select(const std::unordered_set<ATTID> &atts) const {
    /*std::random_device r;
    std::default_random_engine e1(r());
    std::uniform_int_distribution<int> uniform_dist(0, atts.size()-1);
    int index = uniform_dist(e1);
    auto it = atts.begin();
    std::advance(it,index);
     */
    return *atts.begin();
}
void f_unordered_set() {
  std::unordered_set<int> C;
  std::unordered_set<int>::iterator USetI1 = C.begin();
  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when declaring iterators
  // CHECK-FIXES: auto USetI1 = C.begin();

  const std::unordered_set<int> D;
  std::unordered_set<int>::const_iterator USetI2 = D.begin();
  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when declaring iterators
  // CHECK-FIXES: auto USetI2 = D.begin();
}
예제 #25
0
파일: libkviterm.cpp 프로젝트: Cizzle/KVIrc
static bool term_module_cleanup(KviModule *)
{
#ifdef COMPILE_KDE4_SUPPORT
	while(!g_pTermWidgetList.empty())
		delete *g_pSocketSpyWindowList.begin();

	while(!g_pTermWindowList.empty())
		(*g_pTermWindowList.begin())->close();
#endif
	return true;
}
예제 #26
0
// Pop a set of timers, this function takes ownership of the timers and
// thus empties the passed in set.
void TimerHandler::pop(std::unordered_set<TimerPair>& timers)
{
  for (std::unordered_set<TimerPair>::iterator it = timers.begin();
                                               it != timers.end();
                                               ++it)
  {
    delete it->information_timer;
    pop(it->active_timer);
  }
  timers.clear();
}
예제 #27
0
Http::Http(int num):fpwUrl(NULL), maxthreadnum(num) {
	signal(SIGPIPE, &signalHandler);
	openFile(fpwUrl, "./text", "w+");
	openFile(fprArg, "./config", "r");
	openFile(test, "./test", "r");

	configInit();
	std::unordered_set<std::string>::iterator itr = jobUrl.begin();
	pthis = this;
	curl_global_init(CURL_GLOBAL_ALL);

	try {
		poolInit(maxthreadnum);
		while (true) {
			if (itr == jobUrl.end() || itr->empty()) {
				sleep(1);
				itr = jobUrl.begin();
				continue;
			}

			char* p = (char*)malloc(itr->size()+1);
			if (p == NULL) {
				std::cout << "continue url=" << *itr << std::endl;
				itr = jobUrl.erase(itr);
				continue;
			}
			memset(p, 0, itr->size()+1);
			memcpy(p, itr->c_str(), itr->size());
			poolAddWorker(workJob, (void*)p);
			std::cout << "加入任务" << std::endl; 
			//throw std::string("exit");				//测试
			pthread_mutex_lock(&(pthis->pthreadpool.queuelock));
			itr = jobUrl.erase(itr);
			pthread_mutex_unlock(&(pthis->pthreadpool.queuelock));
		}
	}
	catch (std::string& ex){
		std::cout << "catch=";
		std::cout << ex << std::endl;
	}
}
예제 #28
0
//------------------------------------------------------------------------------
Entity * Scene::getTaggedEntity(const std::string & tag)
{
	u32 tagIndex = m_tagManager.getTagIndex(tag);
	if (tagIndex == TagManager::INVALID_INDEX)
		return nullptr;

	const std::unordered_set<Entity*> taggedEntities = m_tagManager.getObjectsByTag(tagIndex);
	if (taggedEntities.empty())
		return nullptr;

	return *taggedEntities.begin();
}
예제 #29
0
 inline std::string PrettyPrint(const std::unordered_set<T, Hash, Predicate, Allocator>& settoprint, const bool add_delimiters=false, const std::string& separator=", ")
 {
     std::ostringstream strm;
     if (settoprint.size() > 0)
     {
         if (add_delimiters)
         {
             strm << "(";
             typename std::unordered_set<T, Hash, Predicate, Allocator>::const_iterator itr;
             for (itr = settoprint.begin(); itr != settoprint.end(); ++itr)
             {
                 if (itr != settoprint.begin())
                 {
                     strm << separator << PrettyPrint(*itr, add_delimiters, separator);
                 }
                 else
                 {
                     strm << PrettyPrint(*itr, add_delimiters, separator);
                 }
             }
             strm << ")";
         }
         else
         {
             typename std::unordered_set<T, Hash, Predicate, Allocator>::const_iterator itr;
             for (itr = settoprint.begin(); itr != settoprint.end(); ++itr)
             {
                 if (itr != settoprint.begin())
                 {
                     strm << separator << PrettyPrint(*itr, add_delimiters, separator);
                 }
                 else
                 {
                     strm << PrettyPrint(*itr, add_delimiters, separator);
                 }
             }
         }
     }
     return strm.str();
 }
예제 #30
0
        int end() {
                #if 0
                auto it = m_eh_array.begin();
                while (it != m_eh_array.end()) {
                        curl_multi_remove_handle(m_handler, *it);
                        curl_easy_cleanup(*it);

                        it += 1;
                }
                #endif

                return 0;
        }