Beispiel #1
0
static int dump_file(struct tree_state *t, char *name, char *file)
{
	struct file_state f;
	int fd;
	Elf_Scn *scn;
	GElf_Shdr shdr;

	if ((dup_mode == HIDE_DUPS) && seen(t, name))
		return 0;

	indent(t); printf("%s", name);

	if ((dup_mode == PRUNE_DUPS) && seen(t, name)) {
		printf("...\n");
		return 0;
	} else {
		printf(":\n");
	}

	see(t, name);

	f.t = t;

	fd = open(file, O_RDONLY);
	if (fd < 0) {
		unix_err("open(%s) failed", file);
		return -1;
	}

	f.e = elf_begin(fd, ELF_C_READ, NULL);
	if (!f.e) {
		elf_err("elf_begin failed on %s", file);
		return -1;
	}

	scn = find_scn(&f, SHT_STRTAB, NULL, &shdr);
	f.strtab_data = elf_getdata(scn, NULL);
	if (!f.strtab_data) {
		app_err("%s has no strtab section", file);
		return -1;
	}

	scn = NULL;
	while ((scn = find_scn(&f, SHT_DYNAMIC, scn, &shdr))) {
		dump_dynamic(&f, scn, &shdr);
	}

	elf_end(f.e);
	close(fd);

	return 0;
}
point overmapbuffer::find_closest(const tripoint& origin, const std::string& type, int& dist, bool must_be_seen)
{
    int max = (dist == 0 ? OMAPX : dist);
    const int z = origin.z;
    // expanding box
    for (dist = 0; dist <= max; dist++) {
        // each edge length is 2*dist-2, because corners belong to one edge
        // south is +y, north is -y
        for (int i = 0; i < dist*2-1; i++) {
            //start at northwest, scan north edge
            int x = origin.x - dist + i;
            int y = origin.y - dist;
            if (check_ot_type(type, x, y, z)) {
                if (!must_be_seen || seen(x, y, z)) {
                    return point(x, y);
                }
            }

            //start at southeast, scan south
            x = origin.x + dist - i;
            y = origin.y + dist;
            if (check_ot_type(type, x, y, z)) {
                if (!must_be_seen || seen(x, y, z)) {
                    return point(x, y);
                }
            }

            //start at southwest, scan west
            x = origin.x - dist;
            y = origin.y + dist - i;
            if (check_ot_type(type, x, y, z)) {
                if (!must_be_seen || seen(x, y, z)) {
                    return point(x, y);
                }
            }

            //start at northeast, scan east
            x = origin.x + dist;
            y = origin.y - dist + i;
            if (check_ot_type(type, x, y, z)) {
                if (!must_be_seen || seen(x, y, z)) {
                    return point(x, y);
                }
            }
        }
    }
    dist = -1;
    return overmap::invalid_point;
}
Beispiel #3
0
void dijkstras(int64_t s){
    int64_t n = es.size();
    dist.assign(n,0);
    pred.assign(n,{-1,0});
    vector<bool> seen (n);
    priority_queue<pii> Q;
    dist[s] = INF;
    Q.push({0,s});

    while(!Q.empty()){
        int64_t cur = Q.top().second;
        Q.pop();
        if(seen[cur]) continue;
        seen[cur] = true;

        for(int i = 0; i < es[cur].size(); i++){
            int64_t t = es[cur][i],
                    c = ec[cur][i];

            if(seen[t] || min(dist[cur],c) <= dist[t]) continue;

            dist[t] = min(dist[cur],c);
            pred[t] = {cur,i};
            Q.push({dist[t],t});
        }
    }
}
Beispiel #4
0
int relativeSign(iterator b1, iterator e1, iterator b2, iterator e2)
{
    assert((int)(e2-b2) == (int)(e1-b1));

    int sign = 1;
    int n = (int)(e1-b1);
    std::vector<bool> seen(n, false);

    for (int i = 0;i < n;i++)
    {
        if (seen[i]) continue;
        int j = i;
        while (true)
        {
            int k;
            for (k = 0;k < n && (!(*(b1+k) == *(b2+j)) || seen[k]);k++);
            assert(k < n);
            j = k;
            seen[j] = true;
            if (j == i) break;
            sign = -sign;
        }
    }

    return sign;
}
Beispiel #5
0
void dijkstras(int64_t s){
    int64_t N = es.size();
    priority_queue<pii> Q;
    vector<bool> seen (N,false);

    dist.assign(N,INF);
    pred.assign(N,{-1,0});

    dist[s] = 0;
    Q.push({0,s});

    while(!Q.empty()){
        int64_t cur = Q.top().second;
        Q.pop();
        if(seen[cur]) continue;
        seen[cur] = true;

        for(int i = 0; i < es[cur].size(); i++){
            int64_t t = es[cur][i],
                    c = ecost[cur][i];

            if(seen[t] || dist[cur] + c >= dist[t]) continue;
 			//Add EXTRA CHECKS here!
            if(ecap[cur][i] == 0) continue;

            dist[t] = dist[cur] + c;
            pred[t] = {cur,i};
            Q.push({-dist[t],t});
        }
    }
}
//Traverse the graph by adding all unseen nodes to a list of unseen nodes
//then asking the derived algorithm for the next node
//Allow the derived algorithm to react to finding nodes whether or not they are 
int Traversal::traverse(const GraphNode& node)
{
	if (node.id == 0)
		return m_initial;
	//add connections to unprocessed if not seen 
	for (auto i : node.edges)
	{
		if (m_seen.find(i) == m_seen.end())
		{
			m_seen.insert(i);
			m_unprocessed.push_back(i);
			seen(i, node.id);
		}
		else
		{
			alreadySeen(i, node.id);
		}
	}

	if (node.id == m_target)
		return -1;

	int next = getNext();
	return next;
}
bool LocalBiconnectedMerger::canMerge( Graph &G, node parent, node mergePartner, int testStrength )
{
	if ( parent->degree() <= 2 || mergePartner->degree() <= 2 || m_isCut[parent] || m_isCut[mergePartner] ) {
		return true;
	}

	unsigned int nodeLimit = (int)log((double)G.numberOfNodes()) * 2 + 50;
	unsigned int visitedNodes = 0;
	m_realNodeMarks.clear();
	HashArray<node, int> nodeMark(-1);

	HashArray<node, bool> seen(false);
	seen[parent] = true;
	seen[mergePartner] = true;

	HashArray<node, int> neighborStatus(0);
	neighborStatus[parent] = -1;
	neighborStatus[mergePartner] = -1;

	List<node> bfsQueue;
	List<node> neighbors;
	int minIndex = numeric_limits<int>::max();
	adjEntry adj;
	forall_adj(adj, parent) {
		node temp = adj->twinNode();
		bfsQueue.pushBack(temp);
		nodeMark[temp] = temp->index();
		if(neighborStatus[temp] == 0) {
			neighbors.pushBack(temp);
			neighborStatus[temp] = 1;
			if (temp->index() < minIndex) {
				minIndex = temp->index();
			}
		}
	}
Beispiel #8
0
 int removeStones(vector<vector<int>>& stones) {
     int N = stones.size();
     vector<vector<int>> graph(N, vector<int>(N));
     for (int i = 0; i < N; ++i) {
         for (int j = i + 1; j < N; ++j) {
             if (stones[i][0] == stones[j][0] || stones[i][1] == stones[j][1]) {
                 graph[i][++graph[i][0]] = j;
                 graph[j][++graph[j][0]] = i;
             }
         }
     }
     int ans = 0;
     vector<bool> seen(N);
     for (int i = 0; i < N; ++i) {
         if (seen[i]) continue;
         stack<int> s;
         s.push(i);
         seen[i] = true;
         --ans;
         while (s.size()) {
             int node = s.top();
             s.pop();
             ++ans;
             for (int j = 1; j <= graph[node][0]; ++j) {
                 int n = graph[node][j];
                 if (!seen[n]) {
                     s.push(n);
                     seen[n] = true;
                 }
             }
         }
     }
     return ans;
 }
Beispiel #9
0
//Wyrmgus start
//static void UnitsOnTileUnmarkSeen(const CPlayer &player, CMapField &mf, int cloak)
static void UnitsOnTileUnmarkSeen(const CPlayer &player, CMapField &mf, int cloak, int ethereal)
//Wyrmgus end
{
	//Wyrmgus start
//	_TileSeen<false> seen(player, cloak);
	_TileSeen<false> seen(player, cloak, ethereal);
	//Wyrmgus end
	mf.UnitCache.for_each(seen);
}
Beispiel #10
0
/* Gets the index of a frame, either returning an existing index if we've seen
 * it before or adding it if not. */
static MVMuint64 get_frame_idx(MVMThreadContext *tc, MVMHeapSnapshotState *ss,
        MVMFrame *frame) {
    MVMuint64 idx;
    if (!seen(tc, ss, frame, &idx)) {
        idx = push_workitem(tc, ss, MVM_SNAPSHOT_COL_KIND_FRAME, frame);
        saw(tc, ss, frame, idx);
    }
    return idx;
}
Beispiel #11
0
// Retorna falso si hay un ciclo de costo negativo alcanzable
// desde s.  Si retorna verdadero, entonces d[i] contiene la
// distancia más corta para ir de s a i.  Si se quiere
// determinar la existencia de un costo negativo que no
// necesariamente sea alcanzable desde s, se crea un nuevo
// nodo A y nuevo nodo B. Para todo nodo original u se crean
// las aristas dirigidas (A, u) con peso 1 y (u, B) con peso
// 1. Luego se corre el algoritmo de Bellman-Ford iniciando en
// A.
bool bellman(int s, int n){
  for (int i=0; i<n; ++i){
    d[i] = oo;
    p[i] = -1;
  }

  d[s] = 0;
  for (int i=0, changed = true; i<n-1 && changed; ++i){
    changed = false;
    for (int u=0; u<n; ++u){
      for (int k=0; k<g[u].size(); ++k){
        int v = g[u][k].v, w = g[u][k].w;
        if (d[u] + w < d[v]){
          d[v] = d[u] + w;
          p[v] = u;
          changed = true;
        }
      }
    }
  }

  for (int u=0; u<n; ++u){
    for (int k=0; k<g[u].size(); ++k){
      int v = g[u][k].v, w = g[u][k].w;
      if (d[u] + w < d[v]){
        //Negative weight cycle!

        //Finding the actual negative cycle. If not needed
        //return false immediately.
        vector<bool> seen(n, false);
        deque<int> cycle;
        int cur = v;
        for (; !seen[cur]; cur = p[cur]){
          seen[cur] = true;
          cycle.push_front(cur);
        }
        cycle.push_front(cur);
        //there's a negative cycle that goes from
        //cycle.front() until it reaches itself again
        printf("Negative weight cycle reachable from s:\n");
        int i = 0;
        do{
          printf("%d ", cycle[i]);
          i++;
        }while(cycle[i] != cycle[0]);
        printf("\n");
        // Negative weight cycle found

        return false;
      }
    }
  }
  return true;
}
Beispiel #12
0
int seen(Node *root, int code){
	if(code < 0)
		die("Invalid code passed to trie.c");
	if(root[code].pref == 0) {
		root[code].seen = root[code].seen + 1;
		return 1;
	}
	root[code].seen = root[code].seen + 1;
	seen(root, root[code].pref);
	return 1;
}
Beispiel #13
0
 void GCodeParser::debug() {
   SERIAL_ECHOPAIR("Command: ", command_ptr);
   SERIAL_ECHOPAIR(" (", command_letter);
   SERIAL_ECHO(codenum);
   SERIAL_ECHOLNPGM(")");
   #if ENABLED(FASTER_GCODE_PARSER)
     SERIAL_ECHO(" args: \"");
     for (char c = 'A'; c <= 'Z'; ++c)
       if (seen(c)) { SERIAL_CHAR(c); SERIAL_CHAR(' '); }
   #else
     SERIAL_ECHOPAIR(" args: \"", command_args);
   #endif
   SERIAL_ECHOPGM("\"");
   if (string_arg) {
     SERIAL_ECHOPGM(" string: \"");
     SERIAL_ECHO(string_arg);
     SERIAL_CHAR('"');
   }
   SERIAL_ECHOPGM("\n\n");
   for (char c = 'A'; c <= 'Z'; ++c) {
     if (seen(c)) {
       SERIAL_ECHOPAIR("Code '", c); SERIAL_ECHOPGM("':");
       if (has_value()) {
         SERIAL_ECHOPAIR("\n    float: ", value_float());
         SERIAL_ECHOPAIR("\n     long: ", value_long());
         SERIAL_ECHOPAIR("\n    ulong: ", value_ulong());
         SERIAL_ECHOPAIR("\n   millis: ", value_millis());
         SERIAL_ECHOPAIR("\n   sec-ms: ", value_millis_from_seconds());
         SERIAL_ECHOPAIR("\n      int: ", value_int());
         SERIAL_ECHOPAIR("\n   ushort: ", value_ushort());
         SERIAL_ECHOPAIR("\n     byte: ", (int)value_byte());
         SERIAL_ECHOPAIR("\n     bool: ", (int)value_bool());
         SERIAL_ECHOPAIR("\n   linear: ", value_linear_units());
         SERIAL_ECHOPAIR("\n  celsius: ", value_celsius());
       }
       else
         SERIAL_ECHOPGM(" (no value)");
       SERIAL_ECHOPGM("\n\n");
     }
   }
 }
Beispiel #14
0
 SparseTable<T>& get() {
   std::string hash = typehash<T>();
   typedef SparseTable<T> TYPETORETURN;
   if (seen(hash))
   {
     return *std::static_pointer_cast<TYPETORETURN>(m_components[hash]);
   }
   auto pdata = std::make_shared<TYPETORETURN>();
   m_indextables.emplace_back(&pdata->getBitfield());
   m_components[hash] = pdata; // cast to void* implicit
   return *pdata;
 }
Beispiel #15
0
// Detect contiguous terrain tiles and store them in the regions list
void HexMap::findRegions()
{
	// new tiles to query
	multimap<int, sf::Vector2i> frontier;
	int i = (int)(mapSize_.x*mapSize_.y);
	HexTile* h = nullptr;
	sf::Vector2i p;
	std::unique_ptr<bool> seen(new bool[i]);
	for (int a = 0; a < i; a++) {
		seen.get()[a] = false;
	}
	std::deque<sf::Vector2i> peaks;
	std::deque<Region> regions;

	Region* currentRegion;
	for (int r = 0; r < mapSize_.y; r++) {
		for (int q = 0, qoff = (int)-floor(r / 2.0); q < mapSize_.x; q++, qoff++) {
			i = q + mapSize_.x * r;
			if (seen.get()[i]) {
				continue;
			}
			regions.emplace_back(1, sf::Vector2i(qoff, r));
			currentRegion = &regions.back();
			h = &getAxial(qoff, r);
			frontier.insert(make_pair(0, sf::Vector2i(qoff, r)));
			VectorSet adj;
			while (!frontier.empty()) {
				for (auto f : frontier) {
					clipToBounds(neighbors(f.second, adj));
				}
				frontier.clear();
				for (auto n : adj) {
					p = axialToOffset(n);
					i = p.x + p.y * mapSize_.x;
					if (seen.get()[i]) {
						continue;
					}
					HexTile& t = getAxial(n.x, n.y);
					if (t.height >= 200) {
						peaks.push_back(n);
					}
					if (t.hts == h->hts) {
						frontier.insert(make_pair(0, n));
						seen.get()[i] = true;
						(*currentRegion).size++;
					}
				}
				adj.clear();
			}
		}
	}
}
bool overmapbuffer::reveal(const point &center, int radius, int z)
{
    bool result = false;
    for (int i = -radius; i <= radius; i++) {
        for (int j = -radius; j <= radius; j++) {
            if(!seen(center.x + i, center.y + j, z)) {
                result = true;
                set_seen(center.x + i, center.y + j, z, true);
            }
        }
    }
    return result;
}
Beispiel #17
0
static int
find_trace (basic_block bb, basic_block *trace)
{
  int i = 0;
  edge e;

  if (dump_file)
    fprintf (dump_file, "Trace seed %i [%i]", bb->index, bb->frequency);

  while ((e = find_best_predecessor (bb)) != NULL)
    {
      basic_block bb2 = e->src;
      if (seen (bb2) || (e->flags & (EDGE_DFS_BACK | EDGE_COMPLEX))
	  || find_best_successor (bb2) != e)
	break;
      if (dump_file)
	fprintf (dump_file, ",%i [%i]", bb->index, bb->frequency);
      bb = bb2;
    }
  if (dump_file)
    fprintf (dump_file, " forward %i [%i]", bb->index, bb->frequency);
  trace[i++] = bb;

  /* Follow the trace in forward direction.  */
  while ((e = find_best_successor (bb)) != NULL)
    {
      bb = e->dest;
      if (seen (bb) || (e->flags & (EDGE_DFS_BACK | EDGE_COMPLEX))
	  || find_best_predecessor (bb) != e)
	break;
      if (dump_file)
	fprintf (dump_file, ",%i [%i]", bb->index, bb->frequency);
      trace[i++] = bb;
    }
  if (dump_file)
    fprintf (dump_file, "\n");
  return i;
}
Beispiel #18
0
vlong
du(char *name, Dir *dir)
{
	int fd, i, n;
	Dir *buf, *d;
	String *file;
	vlong nk, t;

	if(dir == nil)
		return warn(name);

	if((dir->qid.type&QTDIR) == 0)
		return dirval(dir, blkmultiple(dir->length));

	fd = open(name, OREAD);
	if(fd < 0)
		return warn(name);
	nk = 0;
	while((n=dirread(fd, &buf)) > 0) {
		d = buf;
		for(i = n; i > 0; i--, d++) {
			if((d->qid.type&QTDIR) == 0) {
				nk += dufile(name, d);
				continue;
			}

			if(strcmp(d->name, ".") == 0 ||
			   strcmp(d->name, "..") == 0 ||
			   /* !readflg && */ seen(d))
				continue;	/* don't get stuck */

			file = s_copy(name);
			s_append(file, "/");
			s_append(file, d->name);

			t = du(s_to_c(file), d);

			nk += t;
			t = dirval(d, t);
			if(!sflag)
				printamt(t, s_to_c(file));
			s_free(file);
		}
		free(buf);
	}
	if(n < 0)
		warn(name);
	close(fd);
	return dirval(dir, nk);
}
Beispiel #19
0
boost::dynamic_bitset<> backedgeTargets(const Vunit& unit,
                                        const jit::vector<Vlabel>& rpoBlocks) {
  boost::dynamic_bitset<> ret(unit.blocks.size());
  boost::dynamic_bitset<> seen(unit.blocks.size());

  for (auto label : rpoBlocks) {
    seen.set(label);
    for (auto target : succs(unit.blocks[label])) {
      if (seen.test(target)) ret.set(target);
    }
  }

  return ret;
}
void ompl::geometric::BasicPRMmodif::constructSolution(const Milestone* start, const Milestone* goal)
{
    const unsigned int N = milestones_.size();
    std::vector<double> dist(N, std::numeric_limits<double>::infinity());
    std::vector<int>    prev(N, -1);
    std::vector<int>    seen(N, 0);

    dist[goal->index] = 0.0;
    for (unsigned int i = 0 ; i < N ; ++i)
    {
        double minDist = std::numeric_limits<double>::infinity();
        int index = -1;
        for (unsigned int j = 0 ; j < N ; ++j)
            if (seen[j] == 0 && dist[j] < minDist)
            {
                minDist = dist[j];
                index = j;
            }
        if (index < 0)
            break;
        seen[index] = 1;

        for (unsigned int j = 0 ; j < milestones_[index]->adjacent.size() ; ++j)
        {
            const unsigned int idx = milestones_[index]->adjacent[j]->index;
            double altDist = dist[index] + milestones_[index]->costs[j];
            if (altDist < dist[idx])
            {
                dist[idx] = altDist;
                prev[idx] = index;
            }
        }
    }
    if (prev[start->index] >= 0)
    {
        PathGeometric *p = new PathGeometric(si_);
        int pos = start->index;
        do
        {
            p->states.push_back(si_->cloneState(milestones_[pos]->state));
            pos = prev[pos];
        } while (pos >= 0);
        pdef_->getGoal()->setSolutionPath(base::PathPtr(p));
        lastStart_ = start;
        lastGoal_ = goal;
    }
    else
        throw Exception(name_, "Internal error in computing shortest path");
}
Beispiel #21
0
/**
 * Traverses the nodes list starting from the 'start' node, and sets up
 * correct parent-child information. This involves removing the 
 * identified 'parent' node from the 'children_' vector and assigning it
 * to the parent_ field.
 * Then it redoes the entire nodes vector (with due care for indexing of
 * children and parents)
 * so that it is in the correct order for a depth-first traversal.
 * This means that you can take any entry in the list, and the immediately
 * following entries will be all the descendants, if any.
 *
 * Static func
 */
void NeuroNode::traverse( vector< NeuroNode >& nodes, unsigned int start )
{
	vector< unsigned int > seen( nodes.size(), ~0 );
	vector< NeuroNode > tree;
	tree.reserve( nodes.size() );
	seen[ start ] = 0;
	tree.push_back( nodes[ start ] );
	tree.back().parent_ = ~0;
	nodes[start].innerTraverse( tree, nodes, seen );

	if ( tree.size() < nodes.size() ) {
		cout << "Warning: NeuroNode::traverse() unable to traverse all nodes:" << tree.size() << " < numNodes = " << nodes.size() << endl;
	}
	nodes = tree;
}
Beispiel #22
0
city_reference overmapbuffer::closest_known_city( const tripoint &center )
{
    const auto cities = get_cities_near( center, omt_to_sm_copy( OMAPX ) );
    const auto it = std::find_if( cities.begin(), cities.end(),
    [this]( const city_reference & elem ) {
        const tripoint p = sm_to_omt_copy( elem.abs_sm_pos );
        return seen( p.x, p.y, p.z );
    } );

    if( it != cities.end() ) {
        return *it;
    }

    return city_reference::invalid;
}
Beispiel #23
0
/**
 * Registers standard transliterators with the system.  Called by
 * Transliterator during initialization.  Scan all current targets and
 * register those that are scripts T as Any-T/V.
 */
void AnyTransliterator::registerIDs() {

    UErrorCode ec = U_ZERO_ERROR;
    Hashtable seen(TRUE, ec);

    int32_t sourceCount = Transliterator::_countAvailableSources();
    for (int32_t s=0; s<sourceCount; ++s) {
        UnicodeString source;
        Transliterator::_getAvailableSource(s, source);

        // Ignore the "Any" source
        if (source.caseCompare(ANY, 3, 0 /*U_FOLD_CASE_DEFAULT*/) == 0) continue;

        int32_t targetCount = Transliterator::_countAvailableTargets(source);
        for (int32_t t=0; t<targetCount; ++t) {
            UnicodeString target;
            Transliterator::_getAvailableTarget(t, source, target);

            // Only process each target once
            if (seen.geti(target) != 0) continue;
            ec = U_ZERO_ERROR;
            seen.puti(target, 1, ec);
            
            // Get the script code for the target.  If not a script, ignore.
            UScriptCode targetScript = scriptNameToCode(target);
            if (targetScript == USCRIPT_INVALID_CODE) continue;

            int32_t variantCount = Transliterator::_countAvailableVariants(source, target);
            // assert(variantCount >= 1);
            for (int32_t v=0; v<variantCount; ++v) {
                UnicodeString variant;
                Transliterator::_getAvailableVariant(v, source, target, variant);
                
                UnicodeString id;
                TransliteratorIDParser::STVtoID(UnicodeString(TRUE, ANY, 3), target, variant, id);
                ec = U_ZERO_ERROR;
                AnyTransliterator* t = new AnyTransliterator(id, target, variant,
                                                             targetScript, ec);
                if (U_FAILURE(ec)) {
                    delete t;
                } else {
                    Transliterator::_registerInstance(t);
                    Transliterator::_registerSpecialInverse(target, UnicodeString(TRUE, NULL_ID, 4), FALSE);
                }
            }
        }
    }
}
Beispiel #24
0
  /*
   * Checks if the given decomposition constitutes a tree using DFS
   */
  bool is_tree() {
    if ((num_vertices > 0) && num_vertices - 1 != num_edges) {
      return false;
    } else if (num_vertices == 0) {
      return (num_edges == 0);
    }

    std::vector<int> seen(num_vertices, 0);
    unsigned seen_size = 0;

    bool cycle = !tree_dfs(seen,0,-1,seen_size);
    if (cycle || seen_size != num_vertices) {
      return false;
    }
    return true;
  }
Beispiel #25
0
/* Gets the index of a collectable, either returning an existing index if we've
 * seen it before or adding it if not. */
static MVMuint64 get_collectable_idx(MVMThreadContext *tc,
        MVMHeapSnapshotState *ss, MVMCollectable *collectable) {
    MVMuint64 idx;
    if (!seen(tc, ss, collectable, &idx)) {
        if (collectable->flags & MVM_CF_STABLE)
            idx = push_workitem(tc, ss, MVM_SNAPSHOT_COL_KIND_STABLE, collectable);
        else if (collectable->flags & MVM_CF_TYPE_OBJECT)
            idx = push_workitem(tc, ss, MVM_SNAPSHOT_COL_KIND_TYPE_OBJECT, collectable);
        else if (collectable->flags & MVM_CF_FRAME)
            idx = push_workitem(tc, ss, MVM_SNAPSHOT_COL_KIND_FRAME, collectable);
        else
            idx = push_workitem(tc, ss, MVM_SNAPSHOT_COL_KIND_OBJECT, collectable);
        saw(tc, ss, collectable, idx);
    }
    return idx;
}
Beispiel #26
0
 std::vector<Edge> get_shortest_edges(int goal) {
   std::vector<Edge> edges;
   std::vector<bool> seen(D_.size(), false);
   std::queue<int> Q;
   Q.push(goal);
   seen[goal] = true;
   while (!Q.empty()) {
     int u = Q.front(); Q.pop();
     for (const Edge* edge : D_[u].edgesTo) {
       edges.push_back(*edge);
       if (!seen[edge->from])
         Q.push(edge->from);
     }
   }
   return edges;
 }
Beispiel #27
0
bool NetworkWithAlgorithms::CheckBiconnectivity()
{
    ensureExp(nodesNumber>0, "Попытка проверки двусвязности пустой сети");
    int time = 0;
    QVector <int> seen(nodesNumber, 0);
    QVector <int> low(nodesNumber, 0);
    try
    {
        biConSearchDFS(0, -1, time, seen, low);
        return true;
    }
    catch(Exceptions x)
    {
        return false;
    }
}
Beispiel #28
0
int
main()
{
	session_t sess;
	datum id;
	time_t create_time, last_seen;
	bool do_allow;
	char *reason;

	openlog("dorian/query", LOG_PID, LOG_MAIL);
	for (;;) {
		do_allow = false;
		if ((sess = sess_req(stdin)) == NULL)
			break;

		/* white listing */
		for_each(i, whitelist_prefix)
			if (!strncasecmp(whitelist_prefix[i], sess->attr[Krecipient],
						strlen(whitelist_prefix[i]))) {
				do_allow = true;
				reason = "whitelist address";
				break;
			}

		if (!do_allow) {
			sess_derive_key(sess, &id);
			{
				if (seen(id, &create_time, &last_seen)) {
					if (create_time < expired()) {
						bump(id, create_time);
						do_allow = true;
						reason = "in database";
					}
				} else
					add(id);
			}
			free(id.dptr);
		}
		sess_free(&sess);
		if (do_allow)
			allow(reason);
		else
			defer();
	}
	closelog();
	return 0;
}
Beispiel #29
0
    int openLock(vector<string>& deadends, string target) {
        const int z = stoi(target);
        vector<bool> seen(10000, false);
        vector<int> u;
        vector<int> v;
        int distance = 0;

        for (const auto& deadend : deadends) {
            seen[stoi(deadend)] = true;
        }

        const auto enqueue = [&](int x) {
            if (!seen[x]) {
                seen[x] = true;
                v.push_back(x);
            }
        };

        if (seen[0]) {
            return -1;
        }
        u.push_back(0);

        while (!u.empty()) {
            for (const auto x : u) {
                if (x == z) {
                    return distance;
                }

                int position = 1;
                for (int i = 0; i < 4; i++) {
                    const int digit = (x / position) % 10;
                    enqueue((digit == 0) ? (x + (9 * position)) : (x - position));
                    enqueue((digit == 9) ? (x - (9 * position)) : (x + position));
                    position *= 10;
                }
            }

            u.clear();
            swap(u, v);
            distance++;
        }

        return -1;
    }
std::vector<point> overmapbuffer::find_all(const tripoint& origin, const std::string& type, int dist, bool must_be_seen)
{
    std::vector<point> result;
    int max = (dist == 0 ? OMAPX / 2 : dist);
    for (dist = 0; dist <= max; dist++) {
        for (int x = origin.x - dist; x <= origin.x + dist; x++) {
            for (int y = origin.y - dist; y <= origin.y + dist; y++) {
                if (must_be_seen && !seen(x, y, origin.z)) {
                    continue;
                }
                if (check_ot_type(type, x, y, origin.z)) {
                    result.push_back(point(x, y));
                }
            }
        }
    }
    return result;
}