Example #1
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;
     }
   }
 }
Example #2
0
  EvaluateResult evaluate(struct w_query_ctx* ctx, FileResult* file) override {
    if (!set.empty()) {
      bool matched;
      w_string str;

      if (wholename) {
        str = w_query_ctx_get_wholename(ctx);
        if (caseSensitive == CaseSensitivity::CaseInSensitive) {
          str = str.piece().asLowerCase();
        }
      } else {
        str = caseSensitive == CaseSensitivity::CaseInSensitive
                  ? file->baseName().asLowerCase()
                  : file->baseName().asWString();
      }

      matched = set.find(str) != set.end();

      return matched;
    }

    w_string_piece str;

    if (wholename) {
      str = w_query_ctx_get_wholename(ctx);
    } else {
      str = file->baseName();
    }

    if (caseSensitive == CaseSensitivity::CaseInSensitive) {
      return w_string_equal_caseless(str, name);
    }
    return str == name;
  }
Example #3
0
std::shared_ptr<Settings> Settings::create(
    std::shared_ptr<SettingsStorageInterface> settingsStorage,
    std::unordered_set<std::shared_ptr<GlobalSettingsObserverInterface>> globalSettingsObserver,
    std::shared_ptr<registrationManager::CustomerDataManager> dataManager) {
    if (!settingsStorage) {
        ACSDK_ERROR(LX("createFailed").d("reason", "settingsStorageNullReference").d("return", "nullptr"));
        return nullptr;
    }

    if (globalSettingsObserver.empty()) {
        ACSDK_ERROR(LX("createFailed").d("reason", "emptysettingsGlobalObserver").d("return", "nullptr"));
        return nullptr;
    }

    for (auto observer : globalSettingsObserver) {
        if (!observer) {
            ACSDK_ERROR(LX("createFailed").d("reason", "settingsGlobalObserverNullReference").d("return", "nullptr"));
            return nullptr;
        }
    }

    auto settingsObject = std::shared_ptr<Settings>(new Settings(settingsStorage, globalSettingsObserver, dataManager));

    if (!settingsObject->initialize()) {
        ACSDK_ERROR(LX("createFailed").d("reason", "Initialization error."));
        return nullptr;
    }

    return settingsObject;
}
Example #4
0
void pal::setup_api_sets(const std::unordered_set<pal::string_t>& api_sets)
{
    if (api_sets.empty())
    {
        return;
    }

    pal::string_t path;

    (void) getenv(_X("PATH"), &path);

    // We need this ugly hack, as the PInvoked DLL's static dependencies can come from
    // some other NATIVE_DLL_SEARCH_DIRECTORIES and not necessarily side by side. However,
    // CoreCLR.dll loads PInvoke DLLs with LOAD_WITH_ALTERED_SEARCH_PATH. Note that this
    // option cannot be combined with LOAD_LIBRARY_SEARCH_USER_DIRS, so the AddDllDirectory
    // doesn't help much in telling CoreCLR where to load the PInvoke DLLs from.
    // So we resort to modifying the PATH variable on our own hoping Windows loader will do the right thing.
    for (const auto& as : api_sets)
    {
        // AddDllDirectory is still needed for Standalone App's CoreCLR load.
        ::AddDllDirectory(as.c_str());

        // Path patch is needed for static dependencies of a PInvoked DLL load out of the nuget cache.
        path.push_back(PATH_SEPARATOR);
        path.append(as);
    }

    trace::verbose(_X("Setting PATH=%s"), path.c_str());

    ::SetEnvironmentVariableW(_X("PATH"), path.c_str());
}
Example #5
0
mod_manager::mod_manager()
{
    // Insure obsolete_mod_list is initialized.
    if( obsolete_mod_list.empty() && file_exist(FILENAMES["obsolete-mods"]) ) {
        load_obsolete_mods(FILENAMES["obsolete-mods"]);
    }
}
Example #6
0
bool  find_symbols(expression const  e, std::function<bool(symbol)> const  selector,
                   std::unordered_set<symbol,symbol::hash>&  output)
{
    if (selector(get_symbol(e)))
        output.insert(get_symbol(e));
    for (uint64_t  i = 0ULL; i < num_parameters(e); ++i)
        find_symbols(argument(e,i),selector,output);
    return !output.empty();
}
void editor_coordinates_gui::perform(
	editor_setup& setup,
	const vec2i screen_size,
	const vec2i mouse_pos,
   	const std::unordered_set<entity_id>& all_selected
) {
	using namespace augs::imgui;

	auto coordinates = make_scoped_window(ImGuiWindowFlags_AlwaysAutoResize);

	if (!coordinates) {
		return;
	}

	const auto settings = setup.settings;
	auto& v = setup.view();

	if (const auto current_eye = setup.find_current_camera_eye()) {
		const auto cone = camera_cone(*current_eye, screen_size);
		const auto world_cursor_pos = cone.to_world_space(mouse_pos);

		text("Grid size: %x/%x", v.grid.unit_pixels, settings.grid.render.get_maximum_unit());

		text("Cursor: %x", world_cursor_pos);
		text("View center: %x", vec2(current_eye->transform.pos).discard_fract());
		text("Camera AABB: %x", cone.get_visible_world_rect_aabb());

		{
			auto zoom = current_eye->zoom * 100.f;

			if (slider("Zoom: ", zoom, 1.f, 1000.f, "%.3f%%")) {
				if (!v.panned_camera.has_value()) {
					v.panned_camera = current_eye;
				}

				zoom = std::clamp(zoom, 1.f, 1000.f);
				v.panned_camera->zoom = zoom / 100.f;
			}
		}
	}

	text("Rect select mode: %x", format_enum(v.rect_select_mode));

	if (!all_selected.empty()) {
		text("Selected %x entities", all_selected.size());

		if (const auto aabb = setup.find_selection_aabb()) {
			const auto size = aabb->get_size();
			text("AABB:   %x x %x pixels\ncenter: %x\nlt:     %x\nrb:     %x", size.x, size.y, aabb->get_center(), aabb->left_top(), aabb->right_bottom());
		}
	}
	else {
		text("No entity selected");
	}
}
GMsg VectorBuffer::EraseFeatureFromInteraction(
        const feature_ptr &src, const string &proj,
        const std::unordered_set<long> &targets,
        const std::unordered_set<long> &immunes)
{
    GRect ext = MapnikUtils::Box2d2GRect(src->envelope());
    unordered_map<long, feature_ptr> fs = GetFeaturesInRect(
                proj, ext, _config_app().VIEW_VECTORBUFFER_SELECTION_MAX);
    unordered_map<long, feature_ptr> edited_in_clipping;
    unordered_set<long> removed_in_clipping;
    for (unordered_map<long, feature_ptr>::const_iterator it = fs.begin();
         it != fs.end(); it++)
    {
        feature_ptr f = it->second;
        if (immunes.find(f->id()) != immunes.end()) continue;
        if (!targets.empty() && targets.find(f->id()) == targets.end()) continue;
        if (MapnikUtils::contains(
                    src, f, wkbPolygon, _book->GetGeomType(), proj, _layer->proj()))
        {
            removed_in_clipping.insert(it->first);
        }
        else if (MapnikUtils::intersects(
                    src, f, wkbPolygon, _book->GetGeomType(), proj, _layer->proj()))
        {
            feature_ptr clipped = MapnikUtils::difference(
                        f, src, _book->GetGeomType(), wkbPolygon, _layer->proj(), proj);
            if (clipped != nullptr) {
                edited_in_clipping.insert(pair<long, feature_ptr>(it->first, clipped));
            }
        }
    }

    unsigned int num = removed_in_clipping.size() + edited_in_clipping.size();
    if (num == 0) return G_NOERR;
    _undoStack->beginMacro(num == 1 ? "Erase feature" : "Erase features");
    for (unordered_set<long>::const_iterator it = removed_in_clipping.begin();
         it != removed_in_clipping.end(); it++)
    {
        _undoStack->push(new VBCommandDeleteFeature(this, *it));
    }
    for (unordered_map<long, feature_ptr>::const_iterator it = edited_in_clipping.begin();
         it != edited_in_clipping.end(); it++)
    {
        long fid = it->first;
        feature_ptr f = it->second;
        Q_ASSERT(_deletedFeatures.find(fid) == _deletedFeatures.end());
        f->put<value_unicode_string>(
                    _config_app().VIEW_VECTORBUFFER_FIELD_EDITED,
                    transcoder("utf-8").transcode("edited"));
        _undoStack->push(new VBCommandEditFeature(this, fid, f));
    }
    _undoStack->endMacro();
    return G_NOERR;
}
Example #9
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();
}
Example #10
0
static bool codetester_module_cleanup(KviModule *)
{
    while(!g_pCodeTesterWindowList.empty())
    {
        auto w = g_pCodeTesterWindowList.begin();

        if (w == g_pCodeTesterWindowList.end())
            break;

        (*w)->close(); // deleted path!
    }
    return true;
}
Example #11
0
	virtual void global_initialize(m3bp::Task &task) override {
		EXPECT_FALSE(m_global_initialized);
		EXPECT_TRUE(m_thread_local_initialized.empty());

		const auto num_iports = input_ports().size();
		for(m3bp::identifier_type i = 0; i < num_iports; ++i){
			const auto &iport = input_ports()[i];
			if(iport.movement() == m3bp::Movement::BROADCAST){
				m_broadcasted[i] = read_input(task.input(i));
			}
		}
		m_global_initialized = true;
	}
Example #12
0
//------------------------------------------------------------------------------
std::vector<Entity*> Scene::getTaggedEntities(const std::string & tag)
{
	std::vector<Entity*> entities;

	u32 tagIndex = m_tagManager.getTagIndex(tag);
	if (tagIndex == TagManager::INVALID_INDEX)
		return entities;

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

	entities.reserve(taggedEntities.size());
    for (auto it = taggedEntities.begin(); it != taggedEntities.end(); ++it)
        entities.push_back(*it);

    return entities;
}
Example #13
0
 void operator()(msgpack::object::with_zone& o, const std::unordered_set<T>& v) const {
     o.type = msgpack::type::ARRAY;
     if(v.empty()) {
         o.via.array.ptr = nullptr;
         o.via.array.size = 0;
     } else {
         uint32_t size = checked_get_container_size(v.size());
         msgpack::object* p = static_cast<msgpack::object*>(o.zone.allocate_align(sizeof(msgpack::object)*size));
         msgpack::object* const pend = p + size;
         o.via.array.ptr = p;
         o.via.array.size = size;
         typename std::unordered_set<T>::const_iterator it(v.begin());
         do {
             *p = msgpack::object(*it, o.zone);
             ++p;
             ++it;
         } while(p < pend);
     }
 }
Example #14
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;
 }
Example #15
0
	virtual ~TestProcessorBase(){
		EXPECT_FALSE(m_global_initialized);
		EXPECT_TRUE(m_thread_local_initialized.empty());
	}
Example #16
0
static bool links_module_can_unload(KviModule *)
{
	return (g_pLinksWindowList.empty());
}
Example #17
0
static bool codetester_module_can_unload(KviModule *)
{
    return g_pCodeTesterWindowList.empty();
}
Example #18
0
int compute_evc_bound_using_sukp(Dataset &dataset,
		const std::unordered_set<const std::set<int>*> &collection, const
		stats_config &stats_conf, std::pair<int,int> &result) {
	std::ifstream dataset_s(dataset.get_path());
	if(! dataset_s.good()) {
		std::cerr << "ERROR: cannot open dataset file" << std::endl;
		dataset_s.close();
		std::exit(EXIT_FAILURE);
	}
	if (collection.empty()) {
		result.first = 0;
		result.second = 0;
		return 1;
	}
	// The following is called U in the pseudocode
	std::unordered_set<int> items;
	int collection_size = 0;
	for (const std::set<int> *itemset : collection) {
		items.insert(itemset->begin(), itemset->end());
		++collection_size;
	}
	// The following is called L in the pseudocode
	std::map<int, int, bool (*)(int,int)> intersection_sizes_counts(reverse_int_comp);
	// The following is called D_C in the pseudocode
	std::set<std::set<int> > intersections;
	std::string line;
	int size = 0;
	while (std::getline(dataset_s, line)) {
		++size;
		const std::set<int> tau = string2itemset(line);
		std::vector<int> intersection_v(tau.size());
		std::vector<int>::iterator it;
		it = std::set_intersection(
				tau.begin(), tau.end(), items.begin(), items.end(),
				intersection_v.begin());
		if (it != intersection_v.begin() && it - intersection_v.begin() != items.size()) {
			std::set<int> intersection(intersection_v.begin(), it);
			std::pair<std::set<std::set<int> >::iterator, bool> insertion_pair = intersections.insert(intersection);
			if (insertion_pair.second) { // intersection was not already in intersections
				std::map<int, int, bool (*)(int,int)>::iterator intersection_it = intersection_sizes_counts.find(intersection.size());
				if (intersection_it == intersection_sizes_counts.end()) { // we've never seen an intersection of this size
					int prev_value = 0; // We add an element with key equal to the intersection size, and value equal to the value of the element with key immediately larger thn this one, or 0 if there is no such element.
					if (! intersection_sizes_counts.empty()) {
						auto longer_intersection_it = intersection_sizes_counts.lower_bound(intersection.size());
						if (longer_intersection_it != intersection_sizes_counts.begin()) {
							--longer_intersection_it;
							prev_value = longer_intersection_it->second;
						}
					}
					intersection_it = (intersection_sizes_counts.emplace(intersection.size(), prev_value)).first;
				}
				// Exploit the sorted nature (in decreasing order) of the map
				for (; intersection_it != intersection_sizes_counts.end(); ++intersection_it) {
					intersection_sizes_counts[intersection_it->first] += 1;
				}
			}
		}
	}
	dataset_s.close();
	dataset.set_size(size); // Set size in the database object
	// We do not need a counter 'i' like in the pseudocode, we can use an
	// iterator that exploits the sorted nature of the map
	std::map<int, int, bool (*)(int,int)>::iterator it = intersection_sizes_counts.begin();
	IloEnv env;
	IloModel model(env);
	if (get_CPLEX_model(model, env, items, collection, it->first, stats_conf.use_antichain) == -1) {
		std::cerr << "ERROR: something went wrong while building the CPLEX model" << std::endl;
		env.end();
		std::exit(EXIT_FAILURE);
	}
	IloCplex cplex(model);
	// Set parameters, like max runtime and tolerance gaps
	set_CPLEX_params(cplex);
	// Redirect output to null stream
	cplex.setOut(env.getNullStream());
	// Iterate over the possible lengths
	while (true) {
		// The following is q in the pseudocode
		double profit = get_SUKP_profit(cplex);
		if (profit == -1.0) {
			std::cerr << "ERROR: something went wrong while solving the SUKP" << std::endl;
			env.end();
			std::exit(EXIT_FAILURE);
		}
		// This is b in the pseudocode
		int bound =  ((int) floor(log2(profit))) + 1;
		if (bound <= it->second) {
			result.first = bound;
			result.second = -1;
			env.end();
			return 1;
		} else {
			++it;
			if (it != intersection_sizes_counts.end()) {
				if (it->first == 1) {
					result.first = 1;
					result.second = -1;
					env.end();
					return 1;
				}
				set_capacity(model, it->first);
			} else {
				env.end();
				break;
			}
		}
	}
	--it;
	// XXX TODO The following needs to be checked a bit: it may not be the best.
	result.first = (int) floor(fmin(it->second, log2(collection_size)));
	result.second = -1;
	env.end();
	return 1;
}
Example #19
0
	virtual void global_finalize(m3bp::Task &task) override {
		EXPECT_TRUE(m_global_initialized);
		EXPECT_TRUE(m_thread_local_initialized.empty());
		m_global_initialized = false;
		if(!task.is_cancelled()){ validate_broadcast_inputs(task); }
	}
Example #20
0
 ~DefaultFileSystem()
 {
     DF3D_ASSERT(m_sources.empty());
 }
Example #21
0
Stats::Stats(
		Dataset &dataset,
		const std::unordered_set<const std::set<int> *> &collection, const stats_config &stats_conf, Itemset *root) {
	std::ifstream dataset_s(dataset.get_path());
	if (stats_conf.cnt_method == COUNT_SUKP) {
		std::pair<int, int> result;
		compute_evc_bound_using_sukp(dataset, collection, stats_conf, result);
		evc_bound = result.first;
		max_supp = result.second;
		return;
	}
	if(! dataset_s.good()) {
		std::cerr << "ERROR: cannot open dataset file" << std::endl;
		dataset_s.close();
		std::exit(EXIT_FAILURE);
	}
	if (collection.empty()) {
		evc_bound = 0;
		max_supp = 0;
		return;
	}
	// The following is called U in the pseudocode
	std::set<int> items;
	for (const std::set<int> *itemset : collection) {
		items.insert(itemset->begin(), itemset->end());
	}
	// The following is called T in the pseudocode. The name is a little
	// confusing, because the keys are not really the sizes of the
	// intersections, but rather are the values
	// \lfloor\log_2 \ell_\tau\rfloor + 1,
	// where \ell_tau is the number of itemsets in C that appear in \tau.
	std::map<int, std::forward_list<const std::set<int> *>, bool (*)(int,int)>
		intersections_by_size(reverse_int_comp);
	// The following is called L in the pseudocode
	std::set<std::set<int>> intersections;
	std::string line;
	int size = 0;
	// This is the first loop in the pseudocode, to populate T and L
	while (std::getline(dataset_s, line)) {
		++size;
		const std::set<int> tau = string2itemset(line);
		std::vector<int> intersection_v(tau.size());
		std::vector<int>::iterator it;
		it = std::set_intersection(
				tau.begin(), tau.end(), items.begin(), items.end(),
				intersection_v.begin());
		if (it != intersection_v.begin() && it - intersection_v.begin() != items.size()) {
			std::set<int> intersection(intersection_v.begin(), it);
			std::pair<std::set<std::set<int> >::iterator, bool> insertion_pair = intersections.insert(intersection);
			if (insertion_pair.second) { // intersection was not already in intersections
				int itemsets_in_tau_log = intersection.size();
				if (stats_conf.cnt_method == COUNT_EXACT) {
					int itemsets_in_tau = 0;
					if (stats_conf.use_antichain) {
						itemsets_in_tau = get_largest_antichain_size(intersection, collection, root);
					} else {
						itemsets_in_tau = find_itemsets_in_transaction(intersection, collection, root);
					}
					itemsets_in_tau_log = ((int) floor(log2(itemsets_in_tau))) + 1;
				}
				if (intersections_by_size.find(itemsets_in_tau_log) == intersections_by_size.end()) {
					std::forward_list<const std::set<int> *> v(1, &(*insertion_pair.first));
					intersections_by_size[itemsets_in_tau_log] = v;
				} else {
					intersections_by_size[itemsets_in_tau_log].push_front(&(*insertion_pair.first));
				}
			}
		}
	}
	dataset_s.close();
	dataset.set_size(size); // Set size in the database object
	//itemsets_supps.clear(); XXX I never know if this is a good idea
	evc_bound = compute_evc_bound(intersections_by_size, stats_conf);
	max_supp = -1;
}
Example #22
0
static bool links_module_cleanup(KviModule *)
{
	while (!g_pLinksWindowList.empty())
		(*g_pLinksWindowList.begin())->die();
	return true;
}