[ 
https://issues.apache.org/jira/browse/THRIFT-2062?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14161933#comment-14161933
 ] 

Randy Abernethy commented on THRIFT-2062:
-----------------------------------------

Thrift IDL already supports the ability to use custom C + + container types. 
For example a simple map:

{code}
     exception BadFishes {
         1: map<string, i16>  fish_errors 
     }
     $ thrift -gen cpp fish_trade.thrift
     >>  std::map<std::string, int16_t>  fish_errors;
{code}

Can be changed to an unordered map:

{code}
     cpp_include “<unordered_map>”                              

     exception BadFishes {
         1: map cpp_type "std::unordered_map<string, int16_t>" <string, i16>
                fish_errors                                             
     }
     $ thrift -gen cpp fish_trade.thrift
     >>  #include <unordered_map>
     >>  ...
     >>  std::unordered_map<string, int16_t> fish_errors;               
{code}


> cpp flag for using unordered_set instead of set
> -----------------------------------------------
>
>                 Key: THRIFT-2062
>                 URL: https://issues.apache.org/jira/browse/THRIFT-2062
>             Project: Thrift
>          Issue Type: Improvement
>          Components: C++ - Compiler
>            Reporter: Vitali Lovich
>
> It would be nice if the cpp compiler could generate code to use unordered_set 
> instead of set.  unordered_set is faster & usually an unordered_set is wanted 
> rather than an ordered one.  Furthermore, since unordered_set only needs a 
> hash function, we could generate one for every type.
> The hash code generated can be along the lines of what Eclipse does for 
> auto-generated hash codes:
> struct ThriftObj {
>    1: string f1;
>    2: i32 f2;
>    3: SomeOtherThriftObj f3;
> }
> // header file:
> namespace std {
>     template <> struct hash<ThriftObj> {
>         size_t operator()(const ThriftObj& o);
>     }
> }
> // cpp file:
> namespace std {
>     template <> struct hash<ThriftObj> {
>         size_t operator()(const ThriftObj& o)
>             constexpr size_t prime = 31;
>             size_t hashcode = 1;
>             hashcode += o.__isset.f1 ? prime * 
> std::hash<decltype(o.f1)>()(o.f1) : 0;
>             hashcode += o.__isset.f2 ? prime * 
> std::hash<decltype(o.f1)>()(o.f2) : 0;
>             hashcode += o.__isset.f3 ? prime * 
> std::hash<decltype(o.f1)>()(o.f3) : 0;
>         }
>     }
> }



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to