Example #1
0
std::unordered_map<T, std::pair<U, V>> zip(const std::unordered_map<T, U>& a, const std::unordered_map<T, V>& b) {
    assert(a.size() == b.size());
    std::unordered_map<T, std::pair<U, V>> c;
    for (const auto& e : a)
        c[e.first] = std::make_pair(a.at(e.first), b.at(e.first));
    return std::move(c);
}
Example #2
0
error_code cellVideoOutGetState(u32 videoOut, u32 deviceIndex, vm::ptr<CellVideoOutState> state)
{
	cellSysutil.trace("cellVideoOutGetState(videoOut=%d, deviceIndex=%d, state=*0x%x)", videoOut, deviceIndex, state);

	if (deviceIndex) return CELL_VIDEO_OUT_ERROR_DEVICE_NOT_FOUND;

	switch (videoOut)
	{
	case CELL_VIDEO_OUT_PRIMARY:
		state->state = CELL_VIDEO_OUT_OUTPUT_STATE_ENABLED;
		state->colorSpace = CELL_VIDEO_OUT_COLOR_SPACE_RGB;
		state->displayMode.resolutionId = g_video_out_resolution_id.at(g_cfg.video.resolution); // TODO
		state->displayMode.scanMode = CELL_VIDEO_OUT_SCAN_MODE_PROGRESSIVE;
		state->displayMode.conversion = CELL_VIDEO_OUT_DISPLAY_CONVERSION_NONE;
		state->displayMode.aspect = g_video_out_aspect_id.at(g_cfg.video.aspect_ratio); // TODO
		state->displayMode.refreshRates = CELL_VIDEO_OUT_REFRESH_RATE_59_94HZ;
		return CELL_OK;

	case CELL_VIDEO_OUT_SECONDARY:
		*state = { CELL_VIDEO_OUT_OUTPUT_STATE_DISABLED }; // ???
		return CELL_OK;
	}

	return CELL_VIDEO_OUT_ERROR_UNSUPPORTED_VIDEO_OUT;
}
Example #3
0
ReadCompGraph genReadComparisonGraph(const std::vector<T> & reads,
		aligner & alignerObj,
		std::unordered_map<std::string, std::unique_ptr<aligner>>& aligners,
		std::mutex & alignerLock, uint32_t numThreads) {
	std::function<
			comparison(const T &, const T &,
					std::unordered_map<std::string, std::unique_ptr<aligner>>&, aligner&)> getMismatchesFunc =
			[&alignerLock](const T & read1, const T & read2,
					std::unordered_map<std::string, std::unique_ptr<aligner>>& aligners,
					aligner &alignerObj) {
				alignerLock.lock();
				auto threadId = estd::to_string(std::this_thread::get_id());
				//std::cout << threadId<< std::endl;
				if(aligners.find(threadId) == aligners.end()) {
					aligners.emplace(threadId, std::make_unique<aligner>(alignerObj));
				}
				alignerLock.unlock();
				aligners.at(threadId)->alignCache(getSeqBase(read1),getSeqBase(read2), false);
				aligners.at(threadId)->profilePrimerAlignment(getSeqBase(read1), getSeqBase(read2));
				return aligners.at(threadId)->comp_;
			};
	auto distances = getDistanceNonConst(reads, numThreads, getMismatchesFunc,
			aligners, alignerObj);
	return ReadCompGraph(distances, reads);
}
Example #4
0
inline std::pair<bool, AgentPos> help_findAroundDirection(const std::unordered_map<AgentPos, bool>& versionMap, bool iscover, const AgentPos& mypos)
{
    AgentPos around[4] = {{mypos.x+1, mypos.y},{mypos.x-1, mypos.y},{mypos.x, mypos.y+1},{mypos.x, mypos.y-1}};
    std::vector<AgentPos> founds;
    AgentPos notInThree;
    for (auto pos : around) {
        if (iscover) {
            if (versionMap.at(pos) == false) founds.push_back(pos);
            else notInThree = pos;
        } else {
            if (versionMap.at(pos) == true) founds.push_back(pos);
            else notInThree = pos;
        }
    }
    if (founds.size() == 4) {
        return {false, {0,0}};
    } else if (founds.size() > 0 && founds.size() == 3) {
        int x = mypos.x == notInThree.x ? mypos.x : notInThree.x < mypos.x ? mypos.x+1: mypos.x -1;
        int y = mypos.y == notInThree.y ? mypos.y : notInThree.y < mypos.y ? mypos.y +1:mypos.y -1;
        return {true, {x,y}};
    } else if (founds.size() > 0) {
        return {true, founds[static_cast<int>(rand_0_1()*100)%founds.size()]};
    } else {
        return {false, {0,0}};
    }
}
Example #5
0
void Chain::sample(  std::unordered_map<nat,TopologyFile> &paramId2TopFile ,  ParameterFile &pFile ) const
{
  auto blParamsUnfixed=  std::vector<AbstractParameter*>{} ; 
  AbstractParameter *topoParamUnfixed = nullptr; 
  
  for(auto &param : _params  ) 
    {
      if(param->getCategory() == Category::BRANCH_LENGTHS && param->getPrior()->needsIntegration() )
	blParamsUnfixed.push_back(param); 
      else if(param->getCategory() == Category::TOPOLOGY && param->getPrior()->needsIntegration() )
	topoParamUnfixed = param  ; 
    }

  if(blParamsUnfixed.size() > 0)
    {
      for(auto &param : blParamsUnfixed)
	{
	  nat myId = param->getId(); 
	  auto &f = paramId2TopFile.at(myId); 
	  f.sample(_traln, getGeneration(), param); 
	}
    }
  else if(topoParamUnfixed != nullptr)
    {
      auto &f = paramId2TopFile.at(topoParamUnfixed->getId()); 
      f.sample(_traln, getGeneration(), topoParamUnfixed); 
    }

  pFile.sample( _traln, _params, getGeneration(), _prior.getLnPrior()); 
}
Example #6
0
bool Shader::CompileFromSource(const std::string& pathToFile, const EShaderStage& type, ID3D10Blob *& ref_pBob, std::string& errMsg, const std::vector<ShaderMacro>& macros)
{
	const StrUtil::UnicodeString Path = pathToFile;
	const WCHAR* PathStr = Path.GetUnicodePtr();
	ID3D10Blob* errorMessage = nullptr;

	int i = 0;
	std::vector<D3D10_SHADER_MACRO> d3dMacros(macros.size() + 1);
	std::for_each(RANGE(macros), [&](const ShaderMacro& macro)
	{
		d3dMacros[i++] = D3D10_SHADER_MACRO({ macro.name.c_str(), macro.value.c_str() });
	});
	d3dMacros[i] = { NULL, NULL };

	if (FAILED(D3DCompileFromFile(
		PathStr,
		d3dMacros.data(),
		SHADER_INCLUDE_HANDLER,
		SHADER_ENTRY_POINT_LOOKUP.at(type),
		SHADER_COMPILER_VERSION_LOOKUP.at(type),
		SHADER_COMPILE_FLAGS,
		0,
		&ref_pBob,
		&errorMessage)))
	{

		errMsg = GetCompileError(errorMessage, pathToFile);
		return false;
	}
	return true;
}
Example #7
0
error_code cellVideoOutGetDeviceInfo(u32 videoOut, u32 deviceIndex, vm::ptr<CellVideoOutDeviceInfo> info)
{
	cellSysutil.warning("cellVideoOutGetDeviceInfo(videoOut=%d, deviceIndex=%d, info=*0x%x)", videoOut, deviceIndex, info);

	if (deviceIndex) return CELL_VIDEO_OUT_ERROR_DEVICE_NOT_FOUND;

	// Use standard dummy values for now.
	info->portType = CELL_VIDEO_OUT_PORT_HDMI;
	info->colorSpace = CELL_VIDEO_OUT_COLOR_SPACE_RGB;
	info->latency = 100;
	info->availableModeCount = 1;
	info->state = CELL_VIDEO_OUT_DEVICE_STATE_AVAILABLE;
	info->rgbOutputRange = 1;
	info->colorInfo.blueX = 0xFFFF;
	info->colorInfo.blueY = 0xFFFF;
	info->colorInfo.greenX = 0xFFFF;
	info->colorInfo.greenY = 0xFFFF;
	info->colorInfo.redX = 0xFFFF;
	info->colorInfo.redY = 0xFFFF;
	info->colorInfo.whiteX = 0xFFFF;
	info->colorInfo.whiteY = 0xFFFF;
	info->colorInfo.gamma = 100;
	info->availableModes[0].aspect = g_video_out_aspect_id.at(g_cfg.video.aspect_ratio);
	info->availableModes[0].conversion = CELL_VIDEO_OUT_DISPLAY_CONVERSION_NONE;
	info->availableModes[0].refreshRates =  CELL_VIDEO_OUT_REFRESH_RATE_60HZ;
	info->availableModes[0].resolutionId = g_video_out_resolution_id.at(g_cfg.video.resolution);
	info->availableModes[0].scanMode = CELL_VIDEO_OUT_SCAN_MODE_PROGRESSIVE;
	return CELL_OK;
}
Example #8
0
std::vector<std::pair<std::pair<DocId, DocId>, double>>
computeSimilarities(std::unordered_map<DocId, Document> docs) {
  DocSimilarities result = computeIntersections(docs);

  result.forEach([&docs, &result] (DocId id1, DocId id2, double similarity) mutable {
    double docsUnion = docs.at(id1).data.size() + docs.at(id2).data.size() - similarity;
    result.setSimilarity(id1, id2, similarity / docsUnion);
  });

  return result.pairs();
}
Example #9
0
void GateModule::init(const std::unordered_map<std::string, std::string>& config)
{
	std::string name = config.at("name");
	std::string ip = config.at("ip");
	std::string port = config.at("port");
	std::string thread_num = config.at("net_thread_num");

	set_name(name);

	init_net(std::stoi(thread_num));

	listen(ip, port);
}
Example #10
0
// 10^nを漢数字に変換する
std::string KanjiOf10ToPower(int n) {
  const std::unordered_map<int, std::string> kanji_scale_map = {
    {0, "一"}, {1, "十"}, {2, "百"}, {3, "千"},
    {4, "万"},
    {8, "億"},
  };

  const int base = n % 4;  // 一, 十, 百, 千の4つ
  const int scale = n / 4 * 4; // ex) n = 5, 5 / 4 = 1, 1 * 4 = 4

  return (base == 0 && n > 0 ? "" : kanji_scale_map.at(base))  // n = 4 とか 8 のときは '一' を省略
    + (scale > 0 ? kanji_scale_map.at(scale) : "");
}
Example #11
0
LUMAFunction selectLumaFunction(unsigned width, unsigned height, unsigned bits, int opt) {
    LUMAFunction luma = luma_functions.at(KEY(width, height, bits, Scalar));

#if defined(MVTOOLS_X86)
    if (opt) {
        try {
            luma = luma_functions.at(KEY(width, height, bits, SSE2));
        } catch (std::out_of_range &) { }
    }
#endif

    return luma;
}
Example #12
0
 int unsub()
 {
     std::string sig(cmd + UNSUB_LEN);
     if (subs.count(sig) > 0)
     {
         subs.at(sig).erase(socket);
         if (subs.at(sig).size() == 0)
         {
             subs.erase(sig);
             signals.erase(sig);
         }
     }
     return sig.length();
 }
Example #13
0
error_code cellVideoOutGetResolutionAvailability(u32 videoOut, u32 resolutionId, u32 aspect, u32 option)
{
	cellSysutil.warning("cellVideoOutGetResolutionAvailability(videoOut=%d, resolutionId=0x%x, aspect=%d, option=%d)", videoOut, resolutionId, aspect, option);

	switch (videoOut)
	{
	case CELL_VIDEO_OUT_PRIMARY: return not_an_error(
		resolutionId == g_video_out_resolution_id.at(g_cfg.video.resolution)
		&& (aspect == CELL_VIDEO_OUT_ASPECT_AUTO || aspect == g_video_out_aspect_id.at(g_cfg.video.aspect_ratio))
	);
	case CELL_VIDEO_OUT_SECONDARY: return not_an_error(0);
	}

	return CELL_VIDEO_OUT_ERROR_UNSUPPORTED_VIDEO_OUT;
}
Example #14
0
http::doc action(const std::string &verb, const std::unordered_map<std::string, std::string> &args)
{
	if (verb == "refresh")
	{
		volumes.refresh();
		return http::redirect("/");
	}
	else if (verb == "pref")
	{
		std::string old_basedir = prefs::get("basedir");
		for (const std::pair<const std::string, std::string> &kvpair : args)
		{
			try { prefs::set(kvpair.first, kvpair.second); }
			catch (std::out_of_range &e) { continue; }
		}
		prefs::write();
		if (prefs::get("basedir") != old_basedir) volumes.init(prefs::get("basedir"));
		return http::redirect("/");
	}
	else if (verb == "add")
	{
		for (const std::string & reqarg : {"home", "location", "id"}) if (! args.count(reqarg)) return error("Volume Creation Failed", "Required parameter “" + reqarg + "” is missing.");
		std::string srcdir = args.at("location");
		std::string id = args.at("id");
		std::unordered_map<std::string, std::string> info;
		info["home"] = args.at("home");
		for (const std::string &property : {"title", "favicon"}) if (args.count(property)) info[property] = args.at(property);
		std::unordered_set<std::string> keynames{};
		for (const std::pair<const std::string, std::string> &pair : args)
		{
			std::smatch match{};
			if (std::regex_search(pair.first, match, std::regex{"^key_(.*)$"})) keynames.insert(match[1]);
		}
		for (const std::string &key : keynames) if (args.count("key_" + key) && args.count("value_" + key)) info[args.at("key_" + key)] = args.at("value_" + key);
		try { Volume::create(srcdir, prefs::get("basedir"), id, info); }
		catch(std::runtime_error &e) { return error("Volume Creation Failed", e.what()); }
		volumes.refresh();
		return http::redirect("/");
	}
	else if (verb == "quit") std::exit(0);
	/*else if (verb == "debug")
	{
		std::stringstream buf{};
		for (const std::pair<const std::string, std::string> &arg : args) buf << arg.first << " = " << arg.second << "\n";
		return http::doc{"text/plain", buf.str()};
	}*/
	else return error("Bad Request", "Unknown action “" + verb + "”");
}
Example #15
0
 static PedType findPedType(const std::string& name) {
     static const std::unordered_map<std::string, PedType> pedTypes{
         // III
         {"PLAYER1", PLAYER1},
         {"PLAYER2", PLAYER2},
         {"PLAYER3", PLAYER3},
         {"PLAYER4", PLAYER4},
         {"CIVMALE", CIVMALE},
         {"CIVFEMALE", CIVFEMALE},
         {"COP", COP},
         {"GANG1", GANG1},
         {"GANG2", GANG2},
         {"GANG3", GANG3},
         {"GANG4", GANG4},
         {"GANG5", GANG5},
         {"GANG6", GANG6},
         {"GANG7", GANG7},
         {"GANG8", GANG8},
         {"GANG9", GANG9},
         {"EMERGENCY", EMERGENCY},
         {"FIREMAN", FIREMAN},
         {"CRIMINAL", CRIMINAL},
         {"PROSTITUTE", PROSTITUTE},
         {"SPECIAL", SPECIAL},
     };
     return pedTypes.at(name);
 }
Example #16
0
 ~client_t()
 {
     std::cerr << "~client_t" << std::endl;
     for (auto it = signals.begin(); it != signals.end(); ++it)
     {
         if (subs.count(*it) > 0)
         {
             subs.at(*it).erase(socket);
             if (subs.at(*it).empty())
             {
                 subs.erase(*it);
             }
         }
     }
     delete[] cmd;
 }
Example #17
0
User* obtain_user(std::string name) {
  try {
    return &UserTable.at(name);
  } catch(const std::out_of_range &oor) {
    return NULL;
  }
}
Example #18
0
string tokname(tok t)
{
	struct tokhash {
		std::size_t operator()(tok t) const
		{ return static_cast<std::size_t>(t); }
	};

	static const std::unordered_map<tok, string, tokhash> names = {
		{ tok::STRING,  "string" },
		{ tok::LABEL,   "label" },
		{ tok::BYTE,    "byte" },
		{ tok::INT,     "int" },
		{ tok::FLOAT,   "float" },
		{ tok::ARRAY,   "array" },
		{ tok::NEWLINE, "new line" },
		{ tok::END,     "end of file" },
		{ tok::ARG,     ".arg" },
		{ tok::DATA,    ".data" },
		{ tok::EXPORT,  ".export" },
		{ tok::EXTERN,  ".extern" },
		{ tok::IMPORT,  ".import" },
		{ tok::MODULE,  ".module" },
		{ tok::STR,     ".str" },
		{ tok::SUB,     ".sub" },
		{ tok::VAR,     ".var" },
	};

	return names.at(t);
}
Example #19
0
		UIElement* getelement(Element::UIType type)
		{
			if (elements.count(type))
				return elements.at(type).get();
			else
				return nullptr;
		}
Example #20
0
DexMethod* method_from_s_expr(const s_expr& e) {
  s_expr tail;
  s_patn({s_patn("method")}, tail)
      .must_match(e, "method definitions must start with 'method'");

  s_expr access_tokens;
  std::string method_name;
  s_patn({s_patn(access_tokens), s_patn(&method_name)}, tail)
      .must_match(tail, "Expecting access list and method name");

  auto method = static_cast<DexMethod*>(DexMethod::make_method(method_name));
  DexAccessFlags access_flags = static_cast<DexAccessFlags>(0);
  for (size_t i = 0; i < access_tokens.size(); ++i) {
    access_flags |= string_to_access_table.at(access_tokens[i].str());
  }

  s_expr code_expr;
  s_patn({s_patn(code_expr)}, tail).match_with(tail);
  always_assert_log(code_expr.is_list(), "Expecting code listing");
  bool is_virtual = !is_static(access_flags) && !is_private(access_flags);
  method->make_concrete(
      access_flags, ircode_from_s_expr(code_expr), is_virtual);

  return method;
}
Example #21
0
JSValueRef JSCExecutor::nativeStartWorker(
    JSContextRef ctx,
    JSObjectRef function,
    JSObjectRef thisObject,
    size_t argumentCount,
    const JSValueRef arguments[],
    JSValueRef *exception) {
  if (argumentCount != 3) {
    *exception = createErrorString(ctx, "Got wrong number of args");
    return JSValueMakeUndefined(ctx);
  }

  std::string scriptFile = Value(ctx, arguments[0]).toString().str();

  JSValueRef worker = arguments[1];
  JSValueRef globalObj = arguments[2];

  JSCExecutor *executor;
  try {
    executor = s_globalContextRefToJSCExecutor.at(JSContextGetGlobalContext(ctx));
  } catch (std::out_of_range& e) {
    *exception = createErrorString(ctx, "Global JS context didn't map to a valid executor");
    return JSValueMakeUndefined(ctx);
  }

  int workerId = executor->addWebWorker(scriptFile, worker, globalObj);

  return JSValueMakeNumber(ctx, workerId);
}
Example #22
0
JSValueRef JSCExecutor::nativeTerminateWorker(
    JSContextRef ctx,
    JSObjectRef function,
    JSObjectRef thisObject,
    size_t argumentCount,
    const JSValueRef arguments[],
    JSValueRef *exception) {
  if (argumentCount != 1) {
    *exception = createErrorString(ctx, "Got wrong number of args");
    return JSValueMakeUndefined(ctx);
  }

  double workerDouble = JSValueToNumber(ctx, arguments[0], exception);
  if (workerDouble != workerDouble) {
    *exception = createErrorString(ctx, "Got invalid worker id");
    return JSValueMakeUndefined(ctx);
  }

  JSCExecutor *executor;
  try {
    executor = s_globalContextRefToJSCExecutor.at(JSContextGetGlobalContext(ctx));
  } catch (std::out_of_range& e) {
    *exception = createErrorString(ctx, "Global JS context didn't map to a valid executor");
    return JSValueMakeUndefined(ctx);
  }

  executor->terminateOwnedWebWorker((int) workerDouble);

  return JSValueMakeUndefined(ctx);
}
Example #23
0
JSValueRef JSCExecutor::nativeRequire(
  JSContextRef ctx,
  JSObjectRef function,
  JSObjectRef thisObject,
  size_t argumentCount,
  const JSValueRef arguments[],
  JSValueRef *exception) {

  if (argumentCount != 1) {
    *exception = makeJSCException(ctx, "Got wrong number of args");
    return JSValueMakeUndefined(ctx);
  }

  JSCExecutor *executor;
  try {
    executor = s_globalContextRefToJSCExecutor.at(JSContextGetGlobalContext(ctx));
  } catch (std::out_of_range& e) {
    *exception = makeJSCException(ctx, "Global JS context didn't map to a valid executor");
    return JSValueMakeUndefined(ctx);
  }

  double moduleId = JSValueToNumber(ctx, arguments[0], exception);
  if (moduleId <= (double) std::numeric_limits<uint32_t>::max() && moduleId >= 0.0) {
    try {
      executor->loadModule(moduleId);
    } catch (JSModulesUnbundle::ModuleNotFound&) {
      *exception = makeInvalidModuleIdJSCException(ctx, arguments[0], exception);
    }
  } else {
    *exception = makeInvalidModuleIdJSCException(ctx, arguments[0], exception);
  }
  return JSValueMakeUndefined(ctx);
}
Example #24
0
JSValueRef JSCExecutor::nativeFlushQueueImmediate(
    JSContextRef ctx,
    JSObjectRef function,
    JSObjectRef thisObject,
    size_t argumentCount,
    const JSValueRef arguments[],
    JSValueRef *exception) {
  if (argumentCount != 1) {
    *exception = createErrorString(ctx, "Got wrong number of args");
    return JSValueMakeUndefined(ctx);
  }

  JSCExecutor *executor;
  try {
    executor = s_globalContextRefToJSCExecutor.at(JSContextGetGlobalContext(ctx));
  } catch (std::out_of_range& e) {
    *exception = createErrorString(ctx, "Global JS context didn't map to a valid executor");
    return JSValueMakeUndefined(ctx);
  }

  std::string resStr = Value(ctx, arguments[0]).toJSONString();

  executor->flushQueueImmediate(resStr);

  return JSValueMakeUndefined(ctx);
}
Example #25
0
auto Graph<T, E>::dijkstra_min_edge(const std::vector<Node<T, E>>& s,
				    const std::unordered_map<T, E>& weights) const {
    const T* min_node1 = nullptr;
    const T* min_node2 = nullptr;
    const E* min_weight = nullptr;
    
    for (const auto& s_node : s) {
	for (const auto& neighbor : s_node.neighbors) {
	    const auto found = std::any_of(std::begin(s), std::end(s),
					   [&neighbor] (const auto& n) {
					       return neighbor.first == n.value;
					   });

	    if (!found) {
		const auto weight = weights.at(s_node.value) + neighbor.second;
		
		if (min_node1 == nullptr || weight < *min_weight) {
		    min_node1 = &s_node.value;
		    min_node2 = &neighbor.first;
		    min_weight = &neighbor.second;
		} 
	    }
	}
    }

    return std::make_tuple(*min_node1, *min_node2, *min_weight);
}
Example #26
0
TypeGroup groupOfType(const string& type)
{
  if (isPlSqlType(type)) {
      return TYPES.at(type);
    }
  return TypeGroup::Unknown;
}
		/**
		 * @brief Construct result, by packing process.
		 */
		void constructResult()
		{
			if (result.empty() == false)
				return;

			// 제품과 포장지 그룹, Product와 WrapperGroup의 1:1 매칭
			for (size_t i = 0; i < size(); i++)
			{
				const std::shared_ptr<Wrapper> &wrapper = at(i);
				if (result.count(wrapper->key()) == 0)
				{
					WrapperGroup *wrapperGroup = new WrapperGroup(wrapper);
					result.insert({ wrapper->key(), std::shared_ptr<WrapperGroup>(wrapperGroup) });
				}

				std::shared_ptr<WrapperGroup> wrapperGroup = result.at(wrapper->key());
				std::shared_ptr<Instance> instance = instanceArray->at(i);

				if (wrapperGroup->allocate(instance) == false)
				{
					// 일개 제품 크기가 포장지보다 커서 포장할 수 없는 경우, 
					// 현재의 염기서열은 유효하지 못하여 폐기됨
					valid = false;
					return;
				}
			}

			// 유효한 염기서열일 때,
			for (auto it = result.begin(); it != result.end(); it++)
			{
				it->second->optimize(); // 세부적(그룹별)으로 bin-packing을 실시함
				price += it->second->getPrice(); // 더불어 가격도 합산해둔다
			}
			valid = true;
		};
Example #28
0
/**
 * This function clears the queue statistics
 * @param ndi_port_id
 * @param ndi_queue_id
 * @param list of queue counter types to clear
 * @param number of queue counter types specified
 * return standard error
 */
t_std_error ndi_qos_clear_queue_stats(ndi_port_t ndi_port_id,
                                ndi_obj_id_t ndi_queue_id,
                                BASE_QOS_QUEUE_STAT_t *counter_ids,
                                uint_t number_of_counters)
{
    sai_status_t sai_ret = SAI_STATUS_FAILURE;
    nas_ndi_db_t *ndi_db_ptr = ndi_db_ptr_get(ndi_port_id.npu_id);
    if (ndi_db_ptr == NULL) {
        NDI_LOG_TRACE(ev_log_t_NDI, "NDI-QOS",
                      "npu_id %d not exist\n", ndi_port_id.npu_id);
        return STD_ERR(QOS, CFG, 0);
    }

    std::vector<sai_queue_stat_counter_t> counter_id_list;
    std::vector<uint64_t> counters(number_of_counters);

    for (uint_t i= 0; i<number_of_counters; i++) {
        counter_id_list.push_back(nas2sai_queue_counter_type.at(counter_ids[i]));
    }
    if ((sai_ret = ndi_sai_qos_queue_api(ndi_db_ptr)->
                        clear_queue_stats(ndi2sai_queue_id(ndi_queue_id),
                                &counter_id_list[0],
                                number_of_counters))
                         != SAI_STATUS_SUCCESS) {
        NDI_LOG_TRACE(ev_log_t_NDI, "NDI-QOS",
                "queue clear stats fails: npu_id %u\n",
                ndi_port_id.npu_id);
        return STD_ERR(QOS, CFG, sai_ret);
    }

    return STD_ERR_OK;

}
	Reviewer_pp build(const std::string &profilename, const std::string &userid){
		if (lookup.find(userid) != lookup.end()) return lookup.at(userid);
		Reviewer_pp p(new Reviewer(++idr,profilename, userid));
		lookup[userid] = p;
		rm[p->id] = p;
		return p;
	}
Example #30
0
void get_largest_graph_component (vertex_map_t &v,
        std::unordered_map <osm_id_t, int> &com,
        int &largest_id)
{
    // initialize components map
    for (auto it = v.begin (); it != v.end (); ++ it)
        com.insert (std::make_pair (it -> first, -1));

    std::unordered_set <osm_id_t> all_verts, component, nbs_todo, nbs_done;
    for (auto it = v.begin (); it != v.end (); ++ it)
        all_verts.insert (it -> first);
    osm_id_t vt = (*all_verts.begin ());
    nbs_todo.insert (vt);
    int compnum = 0;
    while (all_verts.size () > 0)
    {
        vt = (*nbs_todo.begin ());
        component.insert (vt);
        com.at (vt) = compnum;
        all_verts.erase (vt);

        osm_vertex_t vtx = v.find (vt)->second;
        std::unordered_set <osm_id_t> nbs = vtx.get_all_neighbours ();
        for (auto n: nbs)
        {
            component.insert (n);
            com.at (n) = compnum;
            if (nbs_done.find (n) == nbs_done.end ())
                nbs_todo.insert (n);
        }
        nbs_done.insert (vt);
        nbs_todo.erase (vt);

        if (nbs_todo.size () == 0 && all_verts.size () > 0)
        {
            nbs_todo.insert (*all_verts.begin ());
            compnum++;
        }
    }

    std::vector <int> comp_sizes (compnum, 0);
    for (auto c: com)
        comp_sizes [c.second]++;
    auto maxi = std::max_element (comp_sizes.begin (), comp_sizes.end ());
    largest_id = std::distance (comp_sizes.begin (), maxi);
    //int maxsize = comp_sizes [largest_id];
}