2013-04-25 3 views
1

Boost 문서에는 많은 내용이 설명되어 있지 않지만 ptree에 전달할 수있는 (선택 사항 인) KeyCompare 기능이 있습니다.boost :: ptree 및 KeyCompare 기능?

누구나 맞춤형 KeyCompare 기능을 사용하는 좋은 예가 있습니까?

저는 최근에 진짜 느린 ptree로 작업했습니다. 내 키는 긴 문자열 (경로)이며, 문자열 비교가 속도가 느린 것으로 가정합니다.

내가 수집 할 수있는 항목에서 기본 KeyCompare는 std :: less()입니다. 이것을 변경하고 싶습니다. 나는 두 문자열의 해시를 비교하는 것으로 생각합니다.

이 작업을 용이하게하기 위해 다른 객체를 사용한다는 것은 말할 필요도 없습니다. (std :: string + hash), 대신 std :: 끈. 해시는 생성 중에 계산됩니다.

감사합니다. Rik.

답변

0

부스트 소스 코드에서이 발견 : 대소 문자를 구분 KeyCompare의 예 :

template<class T> 
    struct less_nocase 
    { 
     typedef typename T::value_type Ch; 
     std::locale m_locale; 
     inline bool operator()(Ch c1, Ch c2) const 
     { 
      return std::toupper(c1, m_locale) < std::toupper(c2, m_locale); 
     } 
     inline bool operator()(const T &t1, const T &t2) const 
     { 
      return std::lexicographical_compare(t1.begin(), t1.end(), 
               t2.begin(), t2.end(), *this); 
     } 
    }; 

을 그럼 당신이 할 필요가 basic_ptree 클래스에 전달할 수 있습니다 :

typedef basic_ptree<std::string, std::string, 
         less_nocase<std::string> > iptree; 
관련 문제