当前位置: 首页>>代码示例>>C++>>正文


C++ NFA::outVertices方法代码示例

本文整理汇总了C++中NFA::outVertices方法的典型用法代码示例。如果您正苦于以下问题:C++ NFA::outVertices方法的具体用法?C++ NFA::outVertices怎么用?C++ NFA::outVertices使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NFA的用法示例。


在下文中一共展示了NFA::outVertices方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: pivotStates

std::vector<std::vector<NFA::VertexDescriptor>> pivotStates(NFA::VertexDescriptor source, const NFA& graph) {
  std::vector<std::vector<NFA::VertexDescriptor>> ret(256);
  ByteSet permitted;

  for (const NFA::VertexDescriptor ov : graph.outVertices(source)) {
    graph[ov].Trans->getBytes(permitted);
    for (uint32_t i = 0; i < 256; ++i) {
      if (permitted[i] && std::find(ret[i].begin(), ret[i].end(), ov) == ret[i].end()) {
        ret[i].push_back(ov);
      }
    }
  }
  return ret;
}
开发者ID:jonstewart,项目名称:liblightgrep,代码行数:14,代码来源:utility.cpp

示例2: if

std::pair<uint32_t,std::bitset<256*256>> bestPair(const NFA& graph) {
  std::set<std::pair<uint32_t,NFA::VertexDescriptor>> next;
  next.emplace(0, 0);

  std::vector<std::bitset<256*256>> b;

  uint32_t lmin = std::numeric_limits<uint32_t>::max()-1;

  uint32_t depth;
  NFA::VertexDescriptor h;

  while (!next.empty()) {
    std::tie(depth, h) = *next.begin();
    next.erase(next.begin());

    // lmin + 1 still gets us one transition followed by any byte;
    // > lmin + 1 would have to accept everytyhing, so is useless
    if (depth > lmin + 1) {
      break;
    }

    if (graph[h].IsMatch && depth < lmin) {
      lmin = depth;
    }

    // put successors in the queue if they're at lmin + 1 or less
    if (depth < lmin + 1) {
      for (const NFA::VertexDescriptor t : graph.outVertices(h)) {
        next.emplace(depth+1, t);
      }
    }

    // ensure that b[depth] exists
    if (b.size() <= depth) {
      b.resize(depth+1);
    }
  
    // we use this pointer for getting sub-bitsets 
    uint8_t* const bb = reinterpret_cast<uint8_t* const>(&b[depth]);
 
    for (const NFA::VertexDescriptor t0 : graph.outVertices(h)) {
      ByteSet first;
      graph[t0].Trans->orBytes(first);

      if (graph[t0].IsMatch) {
        // match; record each first byte followed by any byte
        for (uint32_t s = 0; s < 256; ++s) {
          *reinterpret_cast<std::bitset<256>*>(bb + (s << 5)) |= first;
        }
      }
      else {
        // no match; record each first byte followed by each second byte
        for (const NFA::VertexDescriptor t1 : graph.outVertices(t0)) {
          ByteSet second;
          graph[t1].Trans->orBytes(second);

          for (uint32_t s = 0; s < 256; ++s) {
            if (second.test(s)) {
              *reinterpret_cast<std::bitset<256>*>(bb + (s << 5)) |= first;
            }
          }
        }
      }
    }
  }

  if (b.size() < lmin) {
    // Don't go beyond the end of the vector. This can happen with some
    // tests where we have no match states.
    lmin = b.size();
  }
  else if (lmin < b.size()) {
    // Don't start pairs after offset lmin-1, as [lmin,lmin+2) is
    // guaranteed to be informationless.
    b.resize(lmin);
  }

  // Return the offset and bitset for the best two-byte window
  const auto i = std::min_element(b.begin(), b.end(),
    [](const std::bitset<256*256>& l, const std::bitset<256*256>& r) {
      return l.count() < r.count();
    }
  );

  return {i-b.begin(), *i};
}
开发者ID:jonstewart,项目名称:liblightgrep,代码行数:86,代码来源:utility.cpp


注:本文中的NFA::outVertices方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。