Example #1
0
void WeakMapData::DeadKeyCleaner::finalizeUnconditionally()
{
    if (m_liveKeyCount > m_target->m_map.size() / 2) {
        RELEASE_ASSERT(m_liveKeyCount <= m_target->m_map.size());
        int deadCount = m_target->m_map.size() - m_liveKeyCount;
        if (!deadCount)
            return;
        Vector<JSObject*> deadEntries;
        deadEntries.reserveCapacity(deadCount);
        for (auto it = m_target->m_map.begin(), end = m_target->m_map.end(); it != end; ++it) {
            if (Heap::isMarked(it->key))
                continue;
            deadEntries.uncheckedAppend(it->key);
        }
        for (size_t i = 0; i < deadEntries.size(); i++)
            m_target->m_map.remove(deadEntries[i]);
    } else {
        MapType newMap;
        for (auto it = m_target->m_map.begin(), end = m_target->m_map.end(); it != end; ++it) {
            if (!Heap::isMarked(it->key))
                continue;
            newMap.add(it->key, it->value);
        }
        m_target->m_map.swap(newMap);
    }
}
Example #2
0
std::string LLEventDetail::listenerNameForCoroImpl(const void* self_id)
{
    // First, if this coroutine was launched by LLCoros::launch(), find that name.
    std::string name(LLCoros::instance().getNameByID(self_id));
    if (! name.empty())
    {
        return name;
    }
    // Apparently this coroutine wasn't launched by LLCoros::launch(). Check
    // whether we have a memo for this self_id.
    typedef std::map<const void*, std::string> MapType;
    static MapType memo;
    MapType::const_iterator found = memo.find(self_id);
    if (found != memo.end())
    {
        // this coroutine instance has called us before, reuse same name
        return found->second;
    }
    // this is the first time we've been called for this coroutine instance
    name = LLEventPump::inventName("coro");
    memo[self_id] = name;
    LL_INFOS("LLEventCoro") << "listenerNameForCoroImpl(" << self_id << "): inventing coro name '"
                            << name << "'" << LL_ENDL;
    return name;
}
Example #3
0
File: main.cpp Project: riteme/test
int main(/*int argc, char *argv[]*/) {
    ios::sync_with_stdio(false);

    int n, m;
    MapType data;
    vector<unsigned> paths;
    cin >> n >> m;

    data.resize(n);
    for (int i = 0; i < n; i++) {
        data[i].resize(i + 1);
        for (int j = 0; j <= i; j++) { cin >> data[i][j]; }  // for
    }                                                        // for

    unsigned path;
    unsigned end = 0U;
    for (unsigned i = 0; i < n - 1; i++) { end = (end << 1) + 1U; }  // for
    for (path = 0U; path <= end; path++) { paths.push_back(path); }  // for

    for (auto p : paths) {
        if (ComputePath(p, n, data, m)) {
            PrintPath(p, n, data);
            cout << endl;
        }
    }  // foreach in paths

    return 0;
}  // function main
Example #4
0
 // Find the given object ID, or return NULL if not found.
 const X* search(const std::string &id) const
 {
   std::string id2 = toLower (id);
   if(list.find(id2) == list.end())
     return NULL;
   return &list.find(id2)->second;
 }
Example #5
0
int Location::readFromMessage(const MapType & msg)
{
    try {
        MapType::const_iterator I = msg.find("pos");
        MapType::const_iterator Iend = msg.end();
        if (I != Iend) {
            const Element & pos = I->second;
            if (pos.isList() && pos.List().size() == 3) {
                m_pos.fromAtlas(pos);
            } else {
                log(ERROR, "Malformed POS data");
            }
        }
        I = msg.find("orientation");
        if (I != Iend) {
            const Element & orientation = I->second;
            if (orientation.isList() && orientation.List().size() == 4) {
                m_orientation.fromAtlas(orientation);
            } else {
                log(ERROR, "Malformed ORIENTATION data");
            }
        }
    }
    catch (Atlas::Message::WrongTypeException&) {
        log(ERROR, "Location::readFromMessage: Bad location data");
        return -1;
    }
    return 0;
}
Example #6
0
	typename MapType::const_iterator findInTable(const MapType& map, const std::wstring& name, const SourcePos& pos, const ErrorCode notFoundError, const ErrorCode misspelledError)
	{
		typename MapType::const_iterator it(map.find(name));
		if (it == map.end())
		{
			const unsigned maxDist(3);
			std::wstring bestName;
			unsigned bestDist(std::numeric_limits<unsigned>::max());
			for (typename MapType::const_iterator jt(map.begin()); jt != map.end(); ++jt)
			{
				const std::wstring thatName(jt->first);
				const unsigned d(editDistance<std::wstring>(name, thatName, maxDist));
				if (d < bestDist && d < maxDist)
				{
					bestDist = d;
					bestName = thatName;
				}
			}
			if (bestDist < maxDist)
				throw TranslatableError(pos, misspelledError).arg(name).arg(bestName);
			else
				throw TranslatableError(pos, notFoundError).arg(name);
		}
		return it;
	}
Example #7
0
 void adjustRetentionTimes_(MapType& map, const String& trafo_out,
                            bool first_file)
 {
   map.updateRanges();
   TransformationDescription trafo;
   if (first_file) // no transformation necessary
   {
     rt_offset_ = map.getMax()[0] + rt_gap_;
     trafo.fitModel("identity");
   }
   else // subsequent file -> apply transformation
   {
     TransformationDescription::DataPoints points(2);
     double rt_min = map.getMin()[0], rt_max = map.getMax()[0];
     points[0] = make_pair(rt_min, rt_offset_);
     rt_offset_ += rt_max - rt_min;
     points[1] = make_pair(rt_max, rt_offset_);
     trafo.setDataPoints(points);
     trafo.fitModel("linear");
     MapAlignmentTransformer::transformRetentionTimes(map, trafo, true);
     rt_offset_ += rt_gap_;
   }
   if (!trafo_out.empty())
   {
     TransformationXMLFile().store(trafo_out, trafo);
   }
 }
Example #8
0
File: main.cpp Project: riteme/test
int main() {
    while (true) {
        unsigned size;
        vector<string> mapData;

        size = RequireInput<unsigned>(">");
        if (size == SIGNAL_EXIT) { break; }
        cin.ignore();
        for (unsigned i = 0; i != size; i++) { mapData.push_back(RequireInput<string>(">")); }  // for

        MapType map;

        for (unsigned x = 0; x != size; x++) {
            map.push_back(LineType());
            for (unsigned y = 0; y != size; y++) {
                switch (mapData[x][y]) {
                    case ElementSafe: map[x].push_back(ElementType::Safe); break;
                    case ElementWall: map[x].push_back(ElementType::Wall); break;
                }  // switch to mapData[x][y]
            }      // for
        }          // for

        Output(GetMaxNumberOfCastles(map, size));
        // PrintMap(map);
    }

    return 0;
}  // function main
Example #9
0
void printMap(MapType const& m)
{
  int originX = 0;
  int originY = 0;
  int dx = 0;
  int dy = 0;

  m.boundingBox(originX, originY, dx, dy);

  MapType::TileMap const& tiles = m.tileMap();
  
  std::vector<char> bigMap(dx * dy, ' ');

  MapType::TileMap::const_iterator first, last = tiles.end();
  for (first = tiles.begin(); first != last; ++first) {
    TileType& tile = *first->second;
    for (unsigned int x = 0; x < TileType::TileSize; ++x) {
      for (unsigned int y = 0; y < TileType::TileSize; ++y) {
        int xIndex = x + tile.originX() - originX;
        int yIndex = y + tile.originY() - originY;
        bigMap[xIndex + dx * yIndex] = tile.cell(x, y).a;
      }
    }
  }

  int index = 0;
  for (int y = originY; y < originY + dy; ++y) {
    for (int x = originX; x < originX + dx; ++x) {
      cout << bigMap[index] << flush;
      ++index;
    }
    cout << endl;
  }
}
Example #10
0
// Routine to compute optimal tic-tac-toe move.
int TicTacToe::chooseMove( Side s, int & bestRow, int & bestColumn,
                           int alpha, int beta, int depth )
{
    Side opp;             // The other side
    int reply;            // Value of opponent's reply
    int dc;               // Placeholder
    int simpleEval;       // Result of an immediate evaluation
    Position thisPosition = board;
    int value;
    static const int TABLE_DEPTH = 5;  // Max depth placed in Trans. table

    if( ( simpleEval = positionValue( ) ) != UNCLEAR )
        return simpleEval;

    if( depth == 0 )
        transpositions = MapType( );   // makeEmpty

    else if( depth >= 3 && depth <= TABLE_DEPTH )
    {
        MapItr itr = transpositions.find( thisPosition );
        if( itr != transpositions.end( ) )
            return (*itr).second;
    }

    if( s == COMPUTER )
    {
        opp = HUMAN; value = alpha;
    }
    else
    {
        opp = COMPUTER; value = beta;
    }

    for( int row = 0; row < 3; row++ )
        for( int column = 0; column < 3; column++ )
            if( squareIsEmpty( row, column ) )
            {
                place( row, column, s );
                reply = chooseMove( opp, dc, dc, alpha, beta, depth + 1 );
                place( row, column, EMPTY );
                if( s == COMPUTER && reply > value ||
                    s == HUMAN && reply < value )
                {
                    if( s == COMPUTER )
                        alpha = value = reply;
                    else
                        beta = value = reply;
                    
                    bestRow = row; bestColumn = column;
                    if( alpha >= beta )
                        goto Done;   // Refutation
                }
            }

  Done:
    if( depth <= TABLE_DEPTH )
        transpositions[ thisPosition ] = value;
    return value;
}
static inline typename MapType::mapped_type GetItem(const MapType& map, const typename MapType::key_type& key)
{
	typename MapType::const_iterator mapIt = map.find(key);
	if (mapIt != map.end())
		return mapIt->second;
	else
		return typename MapType::mapped_type();
}
void CableCompany::deleteCustomer(const string& name)
{
    auto it = mCustomers.find(name);
    if(it != mCustomers.end())
    {
        mCustomers.erase(name);
    }
}
void CableCompany::removeChannel(const string& name, int channel)
{
    auto it = mPackages.find(name);
    if(it != mPackages.end())
    {
        it->second.reset(channel);
    }
}
static typename MapType::MappedType valueForKey(const MapType& map, const typename MapType::KeyType& key)
{
    typename MapType::const_iterator it = map.find(key);
    if (it != map.end())
        return it->second;

    return defaultValueForKey<typename MapType::MappedType>(key);
}
Example #15
0
MapType CyPy_Element::dictAsElement(const Py::Dict& dict)
{
    MapType map;
    for (auto key : dict.keys()) {
        map.emplace(key.str(), asElement(dict.getItem(key)));
    }
    return map;
}
Example #16
0
 const_iterator find_checked(const K& k) const
 {
     const_iterator ret = map_.find(k);
     if (ret == map_.end())
     {
         gu_throw_fatal << "element " << k << " not found";
     }
     return ret;
 }
Example #17
0
void Admintest::test_addToMessage()
{
    MapType data;

    m_account->addToMessage(data);

    ASSERT_NOT_EQUAL(data.find("character_types"), data.end());
    ASSERT_EQUAL(data["character_types"], ListType());
}
Example #18
0
void Encoder::streamMessageElement(const MapType& obj)
{
    m_b.streamMessage();
    MapType::const_iterator I;
    for (I = obj.begin(); I != obj.end(); I++) {
        mapElementItem((*I).first, (*I).second);
    }
    m_b.mapEnd();
}
Example #19
0
void Encoder::listElementMapItem(const MapType& obj)
{
    m_b.listMapItem();
    MapType::const_iterator I;
    for (I = obj.begin(); I != obj.end(); I++) {
        mapElementItem(I->first, I->second);
    }
    m_b.mapEnd();
}
  void MapAlignmentAlgorithmIdentification::getRetentionTimes_(
    MapType & features, SeqToList & rt_data)
  {
    bool use_feature_rt = param_.getValue("use_feature_rt").toBool();
    for (typename MapType::Iterator feat_it = features.begin();
         feat_it != features.end(); ++feat_it)
    {
      if (use_feature_rt)
      {
        // find the peptide ID closest in RT to the feature centroid:
        String sequence;
        DoubleReal rt_distance = numeric_limits<DoubleReal>::max();
        bool any_good_hit = false;
        for (vector<PeptideIdentification>::iterator pep_it =
               feat_it->getPeptideIdentifications().begin(); pep_it !=
             feat_it->getPeptideIdentifications().end(); ++pep_it)
        {
          if (hasGoodHit_(*pep_it))
          {
            any_good_hit = true;
            DoubleReal current_distance =
              abs(double(pep_it->getMetaValue("RT")) - feat_it->getRT());
            if (current_distance < rt_distance)
            {
              sequence = pep_it->getHits()[0].getSequence().toString();
              rt_distance = current_distance;
            }
          }
        }

        if (any_good_hit)
          rt_data[sequence] << feat_it->getRT();

      }
      else
      {
        getRetentionTimes_(feat_it->getPeptideIdentifications(), rt_data);
      }
    }

    if (!use_feature_rt && param_.getValue("use_unassigned_peptides").toBool())
    {
      getRetentionTimes_(features.getUnassignedPeptideIdentifications(),
                         rt_data);
    }

    // remove duplicates (can occur if a peptide ID was assigned to several
    // features due to overlap or annotation tolerance):
    for (SeqToList::iterator rt_it = rt_data.begin();
         rt_it != rt_data.end(); ++rt_it)
    {
      DoubleList & rt_values = rt_it->second;
      sort(rt_values.begin(), rt_values.end());
      DoubleList::iterator it = unique(rt_values.begin(), rt_values.end());
      rt_values.resize(it - rt_values.begin());
    }
  }
Example #21
0
        // Find the given object ID, or return NULL if not found.
        const X* search (int id) const
        {
            typename MapType::const_iterator iter = list.find (id);

            if (iter == list.end())
                return NULL;

            return &iter->second;
        }
Example #22
0
void Encoder::mapElementMapItem(const std::string& name, const MapType& obj)
{
    m_b.mapMapItem(name);
    MapType::const_iterator I;
    for (I = obj.begin(); I != obj.end(); I++) {
        mapElementItem((*I).first, (*I).second);
    }
    m_b.mapEnd();
}
Example #23
0
    // Find the given object ID, or return NULL if not found.
    const X* search(const std::string &id) const
    {
        std::string id2 = toLower (id);

        typename MapType::const_iterator iter = list.find (id2);

        if (iter == list.end())
            return NULL;
        return &iter->second;
    }
Example #24
0
/// \brief Read attributes from an Atlas element
///
/// @param ent The Atlas map element containing the attribute values
void LocatedEntity::merge(const MapType & ent)
{
    const std::set<std::string> & imm = immutables();
    MapType::const_iterator Iend = ent.end();
    for (MapType::const_iterator I = ent.begin(); I != Iend; ++I) {
        const std::string & key = I->first;
        if (imm.find(key) != imm.end()) continue;
        setAttr(key, I->second);
    }
}
Example #25
0
    void ConfigFile::writeGroup( std::ofstream& out, const MapType& map ) const
    {
        MapType::const_iterator it = map.begin();
        const MapType::const_iterator end = map.end();

        while( it != end ){
            out << it->first << " = " << it->second << std::endl;
            it++;
        }
    }
Example #26
0
Appearance::MapType& Appearance::GetFonts(void)
{
  static MapType s_Fonts;
  if (s_Fonts.empty())
  {
    s_Fonts["font.listing"] = Information("Listing", "");
  }

  return s_Fonts;
}
 inline AtomType operator()( MapType const & arg ) const
 {
     AtomType obj;
     typedef typename MapType::const_iterator IT;
     IT it = arg.begin();
     for( ; arg.end() != it; ++it ) {
         obj.push( nativeToAtom( *it ) );
     }
     return obj;
 }
void LoadDefaultsDecoder::messageArrived(const MapType& o)
{
    MessageElementMap::const_iterator I = o.find("id");
    if (I == o.end()) {
        return;
    }
    
    std::string id(I->second.asString());
    m_objects[id] = o;
}
sensor_msgs::JointState getJointStatesMessage()
{
    sensor_msgs::JointState msg;
    msg.header.stamp = ros::Time::now();
    msg.name.resize(jointpositions.size());
    msg.position.resize(jointpositions.size());
    msg.velocity.resize(jointvelocities.size());
    msg.effort.resize(jointvelocities.size());


    MapType::const_iterator end = jointpositions.end();
    MapType::iterator iter = jointvelocities.begin();
    int count = 0;
    for (MapType::const_iterator it = jointpositions.begin(); it != end; ++it)
    {
        msg.name[count] = it->first;
        msg.position[count] = it->second;
        iter = jointvelocities.find(it->first);

        if (iter != jointvelocities.end() )
            msg.velocity[count] = iter->second;

        msg.effort[count] = 0;

        count++;
    }
    return msg;
}
Example #30
0
void AtlasStreamClient::output(const Root & ent) const
{
    MapType entmap = ent->asMessage();
    MapType::const_iterator Iend = entmap.end();
    for (MapType::const_iterator I = entmap.begin(); I != Iend; ++I) {
        const Element & item = I->second;
        std::cout << std::string(spacing(), ' ') << I->first << ": ";
        output(item, 1);
        std::cout << std::endl;
    }
}