Пример #1
0
PathMap TileGrid::calculatePossiblePaths(TilePos origin, int distance)
{
   PathMap out = {};
   DistanceMap dmap = {};

   // Add the origin point to the path map 
   out[origin] = { origin };
   dmap[origin] = 0;

   // Start the recursive search 
   recursivePathfind(origin, distance, out, dmap, false);

   // Remove the center tile from the map 
   out.erase(out.find(origin));
   
   return out;
}
Пример #2
0
void CodeAtlas::Modulizer::randomModularize()
{
	// collect global symbols
	typedef QHash<SymbolPath, int> PathMap;
	PathMap pathMap;
	SmartDepthIterator it(m_tree->getRoot(), SmartDepthIterator::PREORDER, SymbolInfo::All, SymbolInfo::All&~SymbolInfo::Block);
	for (SymbolNode::Ptr pNode; pNode = *it; ++it)
	{
		SymbolInfo info = pNode->getSymInfo();
		if (!info.isTopLevel())
			continue;

		int pathCount = pathMap.size();
		pathMap[pNode->getSymPath()] = pathCount;
	}

	RandomWalkClusterer randClusterer(1000,1000000);
	randClusterer.setVtxCount(pathMap.size());
	DependRawDataAttr::Ptr depAttr = m_tree->getRoot()->getAttr<DependRawDataAttr>();

	typedef DependRawDataAttr::DependPath DP;
	QList<DP>& dpList = depAttr->getDependPath();
	for (int i = 0; i < dpList.size(); ++i)
	{
		DP& dp = dpList[i];
		PathMap::Iterator pSrc = pathMap.find(dp.m_src.getTopLevelItemPath());
		PathMap::Iterator pTar = pathMap.find(dp.m_tar.getTopLevelItemPath());

		if (pSrc == pathMap.end() || pTar == pathMap.end())
		{
			continue;
		}

		int srcID = pSrc.value();
		int tarID = pTar.value();
		if (srcID == tarID)
		{
			continue;
		}
		float w=0.5;
// 		if (dp.m_type & Ref_Call)
// 		{
// 			w = 1;
// 		}
// 		else if (dp.m_type & Ref_Base)
// 		{
// 			w = 5;
// 		}
		if (dp.m_type & (Ref_Use|Ref_Modify))
		{
			w = 0.5;
		}
		else
		{
			continue;
		}

		randClusterer.addUndirectedEdge(srcID, tarID, w);
	}

	randClusterer.compute();

	for (PathMap::Iterator pP = pathMap.begin(); pP != pathMap.end(); ++pP)
	{
		SymbolNode::Ptr node = m_tree->findItem(pP.key());
		int clusterID = randClusterer.getClusterID(pP.value());
		qDebug() << node->getSymInfo().name() << " \t cID:" << clusterID << endl;

		UIElementAttr::Ptr uiAttr = node->getOrAddAttr<UIElementAttr>();
		uiAttr->clusterID() = clusterID;
	}
}
Пример #3
0
void
NetworkWindow::_ScanAddOns()
{
	BStringList paths;
	BPathFinder::FindPaths(B_FIND_PATH_ADD_ONS_DIRECTORY, "Network Settings",
		paths);

	// Collect add-on paths by name, so that each name will only be
	// loaded once.
	typedef std::map<BString, BPath> PathMap;
	PathMap addOnMap;

	for (int32 i = 0; i < paths.CountStrings(); i++) {
		BDirectory directory(paths.StringAt(i));
		BEntry entry;
		while (directory.GetNextEntry(&entry) == B_OK) {
			BPath path;
			if (entry.GetPath(&path) != B_OK)
				continue;

			if (addOnMap.find(path.Leaf()) == addOnMap.end())
				addOnMap.insert(std::pair<BString, BPath>(path.Leaf(), path));
		}
	}

	for (PathMap::const_iterator addOnIterator = addOnMap.begin();
			addOnIterator != addOnMap.end(); addOnIterator++) {
		const BPath& path = addOnIterator->second;

		image_id image = load_add_on(path.Path());
		if (image < 0) {
			printf("Failed to load %s addon: %s.\n", path.Path(),
				strerror(image));
			continue;
		}

		BNetworkSettingsAddOn* (*instantiateAddOn)(image_id image,
			BNetworkSettings& settings);

		status_t status = get_image_symbol(image,
			"instantiate_network_settings_add_on",
			B_SYMBOL_TYPE_TEXT, (void**)&instantiateAddOn);
		if (status != B_OK) {
			// No "addon instantiate function" symbol found in this addon
			printf("No symbol \"instantiate_network_settings_add_on\" found "
				"in %s addon: not a network setup addon!\n", path.Path());
			unload_add_on(image);
			continue;
		}

		BNetworkSettingsAddOn* addOn = instantiateAddOn(image, fSettings);
		if (addOn == NULL) {
			unload_add_on(image);
			continue;
		}

		fAddOns.AddItem(addOn);

		// Per interface items
		ItemMap::const_iterator iterator = fInterfaceItemMap.begin();
		for (; iterator != fInterfaceItemMap.end(); iterator++) {
			const BString& interface = iterator->first;
			BListItem* interfaceItem = iterator->second;

			uint32 cookie = 0;
			while (true) {
				BNetworkSettingsItem* item = addOn->CreateNextInterfaceItem(
					cookie, interface.String());
				if (item == NULL)
					break;

				fSettingsMap[item->ListItem()] = item;
				fListView->AddUnder(item->ListItem(), interfaceItem);
			}
			fListView->SortItemsUnder(interfaceItem, true,
				NetworkWindow::_CompareListItems);
		}

		// Generic items
		uint32 cookie = 0;
		while (true) {
			BNetworkSettingsItem* item = addOn->CreateNextItem(cookie);
			if (item == NULL)
				break;

			fSettingsMap[item->ListItem()] = item;
			fListView->AddUnder(item->ListItem(),
				_ListItemFor(item->Type()));
		}

		_SortItemsUnder(fServicesItem);
		_SortItemsUnder(fDialUpItem);
		_SortItemsUnder(fOtherItem);
	}

	fListView->SortItemsUnder(NULL, true,
		NetworkWindow::_CompareTopLevelListItems);
}