예제 #1
0
bool check ()
{
     TMap :: iterator  Iter , Iter2;
     Map2 = Map;
     string next;
     int  len = Ans.length () , len1;
     for ( Iter = Map2.begin (); Iter != Map2.end (); Iter ++ )
         for ( ; Iter->second; ) {
             Iter -> second --;
             len1 = Iter->first.length ();
             
             if ( len1 > len ) return false;
             if ( Ans.substr ( 0 , len1 ) == Iter->first ) {
                  next = Ans.substr ( len1 , len - len1 );
                  Iter2 = Map2.find ( next );
                  if ( Iter2 == Map2.end () || Iter2->second == 0 ) break;
                  Iter2->second --;
                  continue;
             }             
             if ( Ans.substr ( len - len1 , len1 ) == Iter->first ) {
                  next = Ans.substr ( 0 , len - len1 );
                  Iter2 = Map2.find ( next );
                  if ( Iter2 == Map2.end () || Iter2->second == 0 ) break;
                  Iter2->second --;
                  continue;
             }
             return false;
         }
     return true;
}
예제 #2
0
 iterator lower_bound(const key_type& key) {
     TMapIterator iter = m_Map.lower_bound(key);
     if ( iter != m_Map.end() && !m_Map.key_comp()(key, iter->first) ) {
         x_MarkUsed(iter);
     }
     return iterator(iter);
 }
예제 #3
0
 iterator find(const key_type& key) {
     TMapIterator iter = m_Map.find(key);
     if ( iter != m_Map.end() ) {
         x_MarkUsed(iter);
     }
     return iterator(iter);
 }
예제 #4
0
파일: 605a_3.cpp 프로젝트: vovaprog/algo
inline bool tryGetValue(TMap &m, TKey key, TValue &u)
{
    auto it = m.find(key);
    if(it!=m.end())
    {
        u = it->second;
        return true;
    }
    return false;
}
예제 #5
0
//----------------------------------------------------------------------------
void CIsoSurface::MakeUnique (std::vector<TVector3D>& rkVA,
    std::vector<TriangleKey>& rkTA)
{
    int iVQuantity = (int)rkVA.size();
    int iTQuantity = (int)rkTA.size();
    if ( iVQuantity == 0 || iTQuantity == 0 )
        return;

    // use a hash table to generate unique storage
    VMap kVMap;
    VMapIterator pkVIter;
    for (int iV = 0, iNextVertex = 0; iV < iVQuantity; iV++)
    {
        // keep only unique vertices
        std::pair<VMapIterator,bool> kResult = kVMap.insert( std::make_pair(rkVA[iV],iNextVertex) );
        if ( kResult.second == true )
            iNextVertex++;
    }

std::cerr << "Found " << kVMap.size() << " vertices" << std::endl;
    
    // use a hash table to generate unique storage
    TMap kTMap;
    TMapIterator pkTIter;
    for (int iT = 0, iNextTriangle = 0; iT < iTQuantity; iT++)
    {
        // replace old vertex indices by new ones
        TriangleKey& rkTri = rkTA[iT];
        pkVIter = kVMap.find(rkVA[rkTri.V[0]]);
        assert( pkVIter != kVMap.end() );
        rkTri.V[0] = pkVIter->second;
        pkVIter = kVMap.find(rkVA[rkTri.V[1]]);
        assert( pkVIter != kVMap.end() );
        rkTri.V[1] = pkVIter->second;
        pkVIter = kVMap.find(rkVA[rkTri.V[2]]);
        assert( pkVIter != kVMap.end() );
        rkTri.V[2] = pkVIter->second;

        // keep only unique triangles
        std::pair<TMapIterator,bool> kResult = kTMap.insert(
            std::make_pair(rkTri,iNextTriangle));
        if ( kResult.second == true )
            iNextTriangle++;
    }

    // pack the vertices
    rkVA.resize(kVMap.size());
    for (pkVIter = kVMap.begin(); pkVIter != kVMap.end(); pkVIter++)
        rkVA[pkVIter->second] = pkVIter->first;

    // pack the triangles
    rkTA.resize(kTMap.size());
    for (pkTIter = kTMap.begin(); pkTIter != kTMap.end(); pkTIter++)
        rkTA[pkTIter->second] = pkTIter->first;
}
예제 #6
0
 mapped_type& operator[](const key_type& key) {
     TMapIterator iter = m_Map.lower_bound(SNode(key));
     if ( iter == m_Map.end() || m_Map.key_comp()(key, iter->first) ) {
         // insert
         iter = m_Map.insert(iter, SNode(key, mapped_type()));
         x_MarkAdded(iter);
     }
     else {
         x_MarkUsed(iter);
     }
     // the underlying type is set<> so the value_type is unnecessary const
     return x_GetNode(iter).second;
 }
예제 #7
0
/**
 * insert
 */                                        
BOOST_AUTO_TEST_CASE_TEMPLATE(stest_insert, TMap, test_types) {
    // insert x values, insert them again, check values
    using char_tt = typename TMap::char_type; 
    
    const size_t nb_values = 100000;
    TMap set;
    typename TMap::iterator it;
    bool inserted;
    
    for(size_t i = 0; i < nb_values; i++) {
        std::tie(it, inserted) = set.insert(utils::get_key<char_tt>(i));
        
        BOOST_CHECK_EQUAL(it.key(), (utils::get_key<char_tt>(i)));
        BOOST_CHECK(inserted);
    }
    BOOST_CHECK_EQUAL(set.size(), nb_values);
    
    for(size_t i = 0; i < nb_values; i++) {
        std::tie(it, inserted) = set.insert(utils::get_key<char_tt>(i));
        
        BOOST_CHECK_EQUAL(it.key(), (utils::get_key<char_tt>(i)));
        BOOST_CHECK(!inserted);
    }
    
    for(size_t i = 0; i < nb_values; i++) {
        it = set.find(utils::get_key<char_tt>(i));
        
        BOOST_CHECK(it != set.end());
        BOOST_CHECK_EQUAL(it.key(), (utils::get_key<char_tt>(i)));
    }
    
    for(auto it = set.begin(); it != set.end(); ++it) {
        auto it_find = set.find(it.key());
        
        BOOST_CHECK(it_find != set.end());
        BOOST_CHECK_EQUAL(it_find.key(), it.key());
    }
}
예제 #8
0
void solve ()
{
     TMap  :: iterator Iter;
     Map.clear ();
     for ( int i = 0; i < N; i ++ ) {
         Iter = Map.find ( Info [i] );
         if ( Iter == Map.end () ) Map [Info [i]] = 0 , Iter = Map.find ( Info [i] );
         Iter->second ++;
     }
     for ( int i = 0; i < N; i ++ )
         for ( int j = 0; j < N; j ++ ) if ( i != j ) {
             Ans = Info [i] + Info [j];
             if ( check ()) {
                  printf ( "%s\n" , Ans.c_str ());
                  return;
             }
         }
}
예제 #9
0
void UniformHLSL::outputHLSLSamplerUniformGroup(
    TInfoSinkBase &out,
    const HLSLTextureSamplerGroup textureGroup,
    const TVector<const TIntermSymbol *> &group,
    const TMap<const TIntermSymbol *, TString> &samplerInStructSymbolsToAPINames,
    unsigned int *groupTextureRegisterIndex)
{
    if (group.empty())
    {
        return;
    }
    unsigned int groupRegisterCount = 0;
    for (const TIntermSymbol *uniform : group)
    {
        const TType &type   = uniform->getType();
        const TString &name = uniform->getSymbol();
        unsigned int registerCount;

        // The uniform might be just a regular sampler or one extracted from a struct.
        unsigned int samplerArrayIndex = 0u;
        const Uniform *uniformByName = findUniformByName(name);
        if (uniformByName)
        {
            samplerArrayIndex = assignUniformRegister(type, name, &registerCount);
        }
        else
        {
            ASSERT(samplerInStructSymbolsToAPINames.find(uniform) !=
                   samplerInStructSymbolsToAPINames.end());
            samplerArrayIndex = assignSamplerInStructUniformRegister(
                type, samplerInStructSymbolsToAPINames.at(uniform), &registerCount);
        }
        groupRegisterCount += registerCount;

        if (type.isArray())
        {
            out << "static const uint " << DecorateIfNeeded(uniform->getName()) << ArrayString(type)
                << " = {";
            for (unsigned int i = 0u; i < type.getArraySize(); ++i)
            {
                if (i > 0u)
                    out << ", ";
                out << (samplerArrayIndex + i);
            }
            out << "};\n";
        }
        else
        {
            out << "static const uint " << DecorateIfNeeded(uniform->getName()) << " = "
                << samplerArrayIndex << ";\n";
        }
    }
    TString suffix = TextureGroupSuffix(textureGroup);
    // Since HLSL_TEXTURE_2D is the first group, it has a fixed offset of zero.
    if (textureGroup != HLSL_TEXTURE_2D)
    {
        out << "static const uint textureIndexOffset" << suffix << " = "
            << (*groupTextureRegisterIndex) << ";\n";
        out << "static const uint samplerIndexOffset" << suffix << " = "
            << (*groupTextureRegisterIndex) << ";\n";
    }
    out << "uniform " << TextureString(textureGroup) << " textures" << suffix << "["
        << groupRegisterCount << "]"
        << " : register(t" << (*groupTextureRegisterIndex) << ");\n";
    out << "uniform " << SamplerString(textureGroup) << " samplers" << suffix << "["
        << groupRegisterCount << "]"
        << " : register(s" << (*groupTextureRegisterIndex) << ");\n";
    *groupTextureRegisterIndex += groupRegisterCount;
}
예제 #10
0
 const_iterator end(void) const {
     return const_iterator(m_Map.end());
 }
예제 #11
0
 iterator end(void) {
     return iterator(m_Map.end());
 }