コード例 #1
0
int path_exists(int *maze, int rows, int columns, int x1, int y1, int x2, int y2)
{
	if (validPos(rows, columns, x1, y1, maze) && validPos(rows, columns, x2, y2, maze)){
		int *newMaze = dupMaze(maze, rows, columns);
		return pathFinder(newMaze, rows, columns, x1, y1, x2, y2);
	}
	return 0;
}
コード例 #2
0
ファイル: hash-collection.cpp プロジェクト: DerPapst/hhvm
void HashCollection::remove(StringData* key) {
  mutateAndBump();
  auto p = findForRemove(key, key->hash());
  if (validPos(p)) {
    erase(p);
  }
}
コード例 #3
0
ALWAYS_INLINE
void BaseSet::addImpl(int64_t k) {
  if (!raw) {
    mutate();
  }
  auto h = hashint(k);
  auto p = findForInsert(k, h);
  assert(p);
  if (validPos(*p)) {
    // When there is a conflict, the add() API is supposed to replace the
    // existing element with the new element in place. However since Sets
    // currently only support integer and string elements, there is no way
    // user code can really tell whether the existing element was replaced
    // so for efficiency we do nothing.
    return;
  }
  if (UNLIKELY(isFull())) {
    makeRoom();
    p = findForInsert(k, h);
  }
  auto& e = allocElm(p);
  e.setIntKey(k, h);
  e.data.m_type = KindOfInt64;
  e.data.m_data.num = k;
  updateNextKI(k);
  if (!raw) {
    ++m_version;
  }
}
コード例 #4
0
ファイル: hash-collection.cpp プロジェクト: DerPapst/hhvm
void HashCollection::eraseNoCompact(ssize_t pos) {
  assert(canMutateBuffer());
  assert(validPos(pos) && !isTombstone(pos));
  assert(m_size > 0);
  arrayData()->eraseNoCompact(pos);
  --m_size;
}
コード例 #5
0
ファイル: grid.hpp プロジェクト: catastropher/voxel
 bool shouldGeneratePoly(int x, int y, int z, int face, T& empty) {
   enum {
     FACE_TOP,
     FACE_BOTTOM,
     FACE_LEFT,
     FACE_BACK,
     FACE_RIGHT,
     FACE_FRONT
     
   };
   
   int offset[6][3] = {
     { 0, -1, 0 },
     { 0, 1, 0 },
     { -1, 0, 0 },
     { 0, 0, 1 },
     { 1, 0, 0 },
     { 0, 0, -1 }
   };
   
   x += offset[face][0];
   y += offset[face][1];
   z += offset[face][2];
   
   return !validPos(x, y, z) || get(x, y, z) == empty;
 }
コード例 #6
0
ALWAYS_INLINE
void BaseMap::setImpl(StringData* key, const TypedValue* val) {
  if (!raw) {
    mutate();
  }
  assert(val->m_type != KindOfRef);
  assert(canMutateBuffer());
retry:
  strhash_t h = key->hash();
  auto* p = findForInsert(key, h);
  assert(p);
  if (validPos(*p)) {
    auto& e = data()[*p];
    TypedValue old = e.data;
    cellDup(*val, e.data);
    tvRefcountedDecRef(old);
    return;
  }
  if (UNLIKELY(isFull())) {
    makeRoom();
    goto retry;
  }
  if (!raw) {
    ++m_version;
  }
  auto& e = allocElm(p);
  cellDup(*val, e.data);
  e.setStrKey(key, h);
  updateIntLikeStrKeys(key);
}
コード例 #7
0
ALWAYS_INLINE
void BaseMap::setImpl(int64_t h, const TypedValue* val) {
  if (!raw) {
    mutate();
  }
  assert(val->m_type != KindOfRef);
  assert(canMutateBuffer());
retry:
  auto p = findForInsert(h);
  assert(p);
  if (validPos(*p)) {
    auto& e = data()[*p];
    TypedValue old = e.data;
    cellDup(*val, e.data);
    tvRefcountedDecRef(old);
    return;
  }
  if (UNLIKELY(isFull())) {
    makeRoom();
    goto retry;
  }
  if (!raw) {
    ++m_version;
  }
  auto& e = allocElm(p);
  cellDup(*val, e.data);
  e.setIntKey(h);
  updateNextKI(h);
}
コード例 #8
0
bool ArrayOffsetProfile::update(int32_t pos, uint32_t count) {
  if (!m_init) init();

  if (!validPos(pos)) {
    m_untracked += count;
    return false;
  }

  for (auto i = 0; i < kNumTrackedSamples; ++i) {
    auto& line = m_hits[i];

    if (line.pos == pos) {
      line.count += count;
      return true;
    }
    if (line.pos == -1) {
      line.pos = pos;
      line.count = count;
      return true;
    }
  }

  m_untracked += count;
  return false;
}
コード例 #9
0
ファイル: hash-collection.cpp プロジェクト: DerPapst/hhvm
void HashCollection::remove(int64_t key) {
  mutateAndBump();
  auto p = findForRemove(key, hash_int64(key));
  if (validPos(p)) {
    erase(p);
  }
}
コード例 #10
0
ALWAYS_INLINE
void BaseSet::addImpl(StringData *key) {
  if (!raw) {
    mutate();
  }
  strhash_t h = key->hash();
  auto p = findForInsert(key, h);
  assert(p);
  if (validPos(*p)) {
    return;
  }
  if (UNLIKELY(isFull())) {
    makeRoom();
    p = findForInsert(key, h);
  }
  auto& e = allocElm(p);
  // This increments the string's refcount twice, once for
  // the key and once for the value
  e.setStrKey(key, h);
  cellDup(make_tv<KindOfString>(key), e.data);
  updateIntLikeStrKeys(key);
  if (!raw) {
    ++m_version;
  }
}
コード例 #11
0
int pathFinder(int *maze, int rows, int cols, int xPtr, int yPtr, int xDest, int yDest){
	*(maze + xPtr*cols + yPtr) = visited;
	if (xPtr == xDest && yPtr == yDest){
		return 1;
	}
	if (*(maze + (xPtr + 1)*cols + yPtr) != visited && validPos(rows, cols, xPtr + 1, yPtr, maze)){
		return pathFinder(maze, rows, cols, xPtr + 1, yPtr, xDest, yDest);
	}
	else if (*(maze + xPtr*cols + yPtr + 1) != visited && validPos(rows, cols, xPtr, yPtr + 1, maze)){
		return pathFinder(maze, rows, cols, xPtr, yPtr + 1, xDest, yDest);
	}
	else if (*(maze + xPtr*cols + yPtr - 1) != visited && validPos(rows, cols, xPtr, yPtr - 1, maze)){
		return pathFinder(maze, rows, cols, xPtr, yPtr - 1, xDest, yDest);
	}
	else if (*(maze + (xPtr - 1)*cols + yPtr) != visited && validPos(rows, cols, xPtr - 1, yPtr, maze)){
		return pathFinder(maze, rows, cols, xPtr - 1, yPtr, xDest, yDest);
	}
}
コード例 #12
0
ファイル: 052.N-QueensII.cpp プロジェクト: juniway/lint
 void solveNQ(int n, int irow, vector<int> &col, int &totSol) {
     if(irow == n) {
         totSol++;
         return;
     }
     
     for(int icol = 0; icol < n; ++icol) {
         if(validPos(col, irow, icol)) {
             col.push_back(icol);
             solveNQ(n, irow + 1, col, totSol);
             col.pop_back();
         }
     }
 }
コード例 #13
0
ファイル: struct-array.cpp プロジェクト: freeshare2011/hhvm
ArrayData* StructArray::RemoveStr(
  ArrayData* ad,
  const StringData* k,
  bool copy
) {
  auto structArray = asStructArray(ad);
  if (structArray->shape()->hasOffsetFor(k)) {
    auto const mixed = copy ? ToMixedCopy(structArray) : ToMixed(structArray);
    auto pos = mixed->findForRemove(k, k->hash());
    if (validPos(pos)) mixed->erase(pos);
    return mixed;
  }
  return copy ? Copy(structArray) : structArray;
}
コード例 #14
0
void ArrayOffsetProfile::reduce(ArrayOffsetProfile& l,
                                const ArrayOffsetProfile& r) {
  if (!r.m_init) return;

  Line scratch[2 * kNumTrackedSamples];
  auto n = uint32_t{0};

  for (auto i = 0; i < kNumTrackedSamples; ++i) {
    auto const& rline = r.m_hits[i];
    if (!validPos(rline.pos)) break;

    // Update `l'.  If `l' can't record the update, save it to scratch.
    if (!l.update(rline.pos, rline.count)) {
      scratch[n++] = rline;
    }
  }
  l.m_untracked += r.m_untracked;

  if (n == 0) return;
  assertx(n <= kNumTrackedSamples);

  // Sort the combined samples, then copy the top hits back into `l'.
  std::memcpy(&scratch[n], &l.m_hits[0],
              kNumTrackedSamples * sizeof(Line));
  std::sort(&scratch[0], &scratch[n + kNumTrackedSamples],
            [] (Line a, Line b) { return a.count > b.count; });
  std::memcpy(l.m_hits, scratch, kNumTrackedSamples);

  // Add the hits in the discarded tail to m_untracked.
  for (auto i = kNumTrackedSamples; i < n + kNumTrackedSamples; ++i) {
    auto const& line = scratch[i];
    if (!validPos(line.pos)) break;

    l.m_untracked += line.count;
  }
}
コード例 #15
0
ファイル: packed-array.cpp プロジェクト: Einkoro/hhvm
ArrayData* PackedArray::RemoveInt(ArrayData* adIn, int64_t k, bool copy) {
  assert(checkInvariants(adIn));
  if (size_t(k) < adIn->m_size) {
    // Escalate to mixed for correctness; unset preserves m_nextKI.
    //
    // TODO(#2606310): if we're removing the /last/ element, we
    // probably could stay packed, but this needs to be verified.
    auto const mixed = copy ? ToMixedCopy(adIn) : ToMixed(adIn);
    auto pos = mixed->findForRemove(k, false);
    if (validPos(pos)) mixed->erase(pos);
    return mixed;
  }
  // Key doesn't exist---we're still packed.
  return copy ? Copy(adIn) : adIn;
}
コード例 #16
0
ファイル: grid.hpp プロジェクト: catastropher/voxel
 void updateDeletedVoxelNeighbors(int x, int y, int z, std::vector<Triangle>& v, T empty) {
   int offset[6][3] = {
     { 0, -1, 0 },
     { 0, 1, 0 },
     { -1, 0, 0 },
     { 0, 0, 1 },
     { 1, 0, 0 },
     { 0, 0, -1 }
   };
   
   for(int i = 0; i < 6; ++i) {
     int xx = x + offset[i][0];
     int yy = y + offset[i][1];
     int zz = z + offset[i][2];
     
     if(validPos(xx, yy, zz) && get(xx, yy, zz) != 0 && shouldGeneratePoly(xx, yy, zz, Cube::oppositeFace(i), empty)) {
       TriangleRun* run = &triangle_run[index(xx, yy, zz)];
       
       while(run->next) {
         run = run->next;
       }
       
       TriangleRun* new_run = new TriangleRun;
       
       new_run->start = v.size();
       new_run->end = (int)v.size() - 1;
       
       Cube c;
       c.x_size = grid_dx;
       c.y_size = grid_dy;
       c.z_size = grid_dz;
       
       c.setPos(glm::vec3(xx * grid_dx, yy * grid_dy, zz * grid_dz));
       
       Quad q;
       Triangle a, b;
       
       c.getFace(Cube::oppositeFace(i)).triangulate(a, b);
       v.push_back(a);
       v.push_back(b);
       new_run->end += 2;
       
       run->next = new_run;
     }
   }
 }
コード例 #17
0
folly::Optional<uint32_t>
ArrayOffsetProfile::choose() const {
  Line hottest;
  uint32_t total = 0;

  if (!m_init) return folly::none;

  for (auto i = 0; i < kNumTrackedSamples; ++i) {
    auto const& line = m_hits[i];
    if (!validPos(line.pos)) break;

    if (line.count > hottest.count) hottest = line;
    total += line.count;
  }
  total += m_untracked;

  auto const bound = total * RuntimeOption::EvalHHIRMixedArrayProfileThreshold;
  return hottest.count >= bound
    ? folly::make_optional(safe_cast<uint32_t>(hottest.pos))
    : folly::none;
}
コード例 #18
0
ファイル: hash-collection.cpp プロジェクト: DerPapst/hhvm
HashCollection::Elm& HashCollection::allocElmFront(MixedArray::Inserter ei) {
  assert(MixedArray::isValidIns(ei) && !MixedArray::isValidPos(*ei));
  assert(m_size <= posLimit() && posLimit() < cap());
  // Move the existing elements to make element slot 0 available.
  memmove(data() + 1, data(), posLimit() * sizeof(Elm));
  incPosLimit();
  // Update the hashtable to reflect the fact that everything was
  // moved over one position
  auto* hash = hashTab();
  auto* hashEnd = hash + hashSize();
  for (; hash != hashEnd; ++hash) {
    if (validPos(*hash)) {
      ++(*hash);
    }
  }
  // Set the hash entry we found to point to element slot 0.
  (*ei) = 0;
  // Adjust m_pos so that is points at this new first element.
  arrayData()->m_pos = 0;
  // Adjust size to reflect that we're adding a new element.
  incSize();
  // Store the value into element slot 0.
  return data()[0];
}
コード例 #19
0
ファイル: Terrain.cpp プロジェクト: brainpower/Maximum-Fish
float Terrain::getTileElevation(glm::vec2 pos) const
{
	unsigned int index = geom::linear(pos, Size.x);
	if (!validPos(pos) || index > Tiles.size()) return -1;
	return Tiles[ index ]->getHeight();
}
コード例 #20
0
ファイル: Terrain.cpp プロジェクト: brainpower/Maximum-Fish
const std::shared_ptr<Tile>& Terrain::getTile( glm::vec2 pos ) const
{
	unsigned int index = geom::linear(pos, Size.x);
	if (!validPos(pos) || index >= Tiles.size()) return InvalidTile;
	return Tiles[ index ];
}