You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Nitay Joffe (JIRA)" <ji...@apache.org> on 2009/07/09 08:04:14 UTC
[jira] Created: (THRIFT-539) struct hash and print methods for C++
struct hash and print methods for C++
-------------------------------------
Key: THRIFT-539
URL: https://issues.apache.org/jira/browse/THRIFT-539
Project: Thrift
Issue Type: Improvement
Components: Compiler (C++), Library (C++)
Reporter: Nitay Joffe
The current thrift compiler for C++ generates methods for structs like operator== and operator< since it uses maps,sets, etc but it does not generate a hash() method or a human readable print() method.
The idea of this issue is to add functionality to the C++ compiler to generate:
# A boost hash compatible hash_value() function. This should probably be an option to the compiler as it adds a dependency in generated code on boost.
# An operator<< function for printing structs in a nice form. This should be safe to always do?
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (THRIFT-539) struct hash and print methods for C++
Posted by "Nitay Joffe (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/THRIFT-539?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Nitay Joffe updated THRIFT-539:
-------------------------------
Attachment: thrift-539-print.patch
Attaching patch for print part of this JIRA. I realize this can already be done via ThriftDebugString as you say David, but I think it is still nice to have this for certain situations.
Here is an example of what this produces:
{noformat}
ostream work: {num1: 15, num2: 10, op: SUBTRACT, comment: fssdf}
debug work: Work {
01: num1 (i32) = 15,
02: num2 (i32) = 10,
03: op (i32) = 2,
04: comment (string) = "fssdf",
}
{noformat}
The "debug work" part is using ThriftDebugString. The "ostream work" part is using my ostream<< function.
As you can see, they're comparable. I don't print the types, but that can be added.
Thoughts? Comments?
> struct hash and print methods for C++
> -------------------------------------
>
> Key: THRIFT-539
> URL: https://issues.apache.org/jira/browse/THRIFT-539
> Project: Thrift
> Issue Type: New Feature
> Components: Compiler (C++), Library (C++)
> Reporter: Nitay Joffe
> Priority: Minor
> Attachments: thrift-539-hash.patch, thrift-539-print.patch
>
>
> The current thrift compiler for C++ generates methods for structs like operator== and operator< since it uses maps,sets, etc but it does not generate a hash() method or a human readable print() method.
> The idea of this issue is to add functionality to the C++ compiler to generate:
> # A boost hash compatible hash_value() function. This should probably be an option to the compiler as it adds a dependency in generated code on boost.
> # An operator<< function for printing structs in a nice form. This should be safe to always do?
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (THRIFT-539) struct hash and print methods for C++
Posted by "Nitay Joffe (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/THRIFT-539?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Nitay Joffe updated THRIFT-539:
-------------------------------
Attachment: thrift-539-hash.patch
Attaching patch for adding hash portion of this JIRA.
This patch adds a boost::hash compatible hashing function to each struct in the IDL. It is optional to generate the function, because it adds a requirement on boost/functional/hash.hpp. The option to enable it is called boost_hash.
Here is an example of running the thrift compiler with this patch to generate the hash functions:
{noformat}
nitay@coeus ~/code/thrift/tutorial $ ../compiler/cpp/thrift -r --gen cpp:boost_hash tutorial.thrift
{noformat}
Here is the hashing code that is generated for the tutorial:
{noformat}
std::size_t hash_value(const Work &v) {
std::size_t seed = 7;
boost::hash_combine(seed, v.num1);
boost::hash_combine(seed, v.num2);
boost::hash_combine(seed, v.op);
boost::hash_combine(seed, v.__isset.comment);
if (v.__isset.comment) {
boost::hash_combine(seed, v.comment);
}
return seed;
}
{noformat}
Note that the "comment" field is optional, so it is also optionally hashed.
Thoughts?
> struct hash and print methods for C++
> -------------------------------------
>
> Key: THRIFT-539
> URL: https://issues.apache.org/jira/browse/THRIFT-539
> Project: Thrift
> Issue Type: New Feature
> Components: Compiler (C++), Library (C++)
> Reporter: Nitay Joffe
> Priority: Minor
> Attachments: thrift-539-hash.patch
>
>
> The current thrift compiler for C++ generates methods for structs like operator== and operator< since it uses maps,sets, etc but it does not generate a hash() method or a human readable print() method.
> The idea of this issue is to add functionality to the C++ compiler to generate:
> # A boost hash compatible hash_value() function. This should probably be an option to the compiler as it adds a dependency in generated code on boost.
> # An operator<< function for printing structs in a nice form. This should be safe to always do?
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (THRIFT-539) struct hash and print methods for
C++
Posted by "David Reiss (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/THRIFT-539?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12729076#action_12729076 ]
David Reiss commented on THRIFT-539:
------------------------------------
cout << ThriftDebugString(myStruct) << endl;
> struct hash and print methods for C++
> -------------------------------------
>
> Key: THRIFT-539
> URL: https://issues.apache.org/jira/browse/THRIFT-539
> Project: Thrift
> Issue Type: New Feature
> Components: Compiler (C++), Library (C++)
> Reporter: Nitay Joffe
> Priority: Minor
>
> The current thrift compiler for C++ generates methods for structs like operator== and operator< since it uses maps,sets, etc but it does not generate a hash() method or a human readable print() method.
> The idea of this issue is to add functionality to the C++ compiler to generate:
> # A boost hash compatible hash_value() function. This should probably be an option to the compiler as it adds a dependency in generated code on boost.
> # An operator<< function for printing structs in a nice form. This should be safe to always do?
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (THRIFT-539) struct hash and print methods for
C++
Posted by "Nitay Joffe (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/THRIFT-539?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12729071#action_12729071 ]
Nitay Joffe commented on THRIFT-539:
------------------------------------
True, but you can't just do e.g. "cout << myStruct << endl;" which I've found helps a lot in debugging.
> struct hash and print methods for C++
> -------------------------------------
>
> Key: THRIFT-539
> URL: https://issues.apache.org/jira/browse/THRIFT-539
> Project: Thrift
> Issue Type: New Feature
> Components: Compiler (C++), Library (C++)
> Reporter: Nitay Joffe
> Priority: Minor
>
> The current thrift compiler for C++ generates methods for structs like operator== and operator< since it uses maps,sets, etc but it does not generate a hash() method or a human readable print() method.
> The idea of this issue is to add functionality to the C++ compiler to generate:
> # A boost hash compatible hash_value() function. This should probably be an option to the compiler as it adds a dependency in generated code on boost.
> # An operator<< function for printing structs in a nice form. This should be safe to always do?
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (THRIFT-539) struct hash and print methods for C++
Posted by "Nitay Joffe (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/THRIFT-539?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Nitay Joffe updated THRIFT-539:
-------------------------------
Attachment: (was: thrift-539-print.patch)
> struct hash and print methods for C++
> -------------------------------------
>
> Key: THRIFT-539
> URL: https://issues.apache.org/jira/browse/THRIFT-539
> Project: Thrift
> Issue Type: New Feature
> Components: Compiler (C++), Library (C++)
> Reporter: Nitay Joffe
> Priority: Minor
>
> The current thrift compiler for C++ generates methods for structs like operator== and operator< since it uses maps,sets, etc but it does not generate a hash() method or a human readable print() method.
> The idea of this issue is to add functionality to the C++ compiler to generate:
> # A boost hash compatible hash_value() function. This should probably be an option to the compiler as it adds a dependency in generated code on boost.
> # An operator<< function for printing structs in a nice form. This should be safe to always do?
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (THRIFT-539) struct hash and print methods for C++
Posted by "Nitay Joffe (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/THRIFT-539?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Nitay Joffe updated THRIFT-539:
-------------------------------
Attachment: (was: thrift-539-hash.patch)
> struct hash and print methods for C++
> -------------------------------------
>
> Key: THRIFT-539
> URL: https://issues.apache.org/jira/browse/THRIFT-539
> Project: Thrift
> Issue Type: New Feature
> Components: Compiler (C++), Library (C++)
> Reporter: Nitay Joffe
> Priority: Minor
>
> The current thrift compiler for C++ generates methods for structs like operator== and operator< since it uses maps,sets, etc but it does not generate a hash() method or a human readable print() method.
> The idea of this issue is to add functionality to the C++ compiler to generate:
> # A boost hash compatible hash_value() function. This should probably be an option to the compiler as it adds a dependency in generated code on boost.
> # An operator<< function for printing structs in a nice form. This should be safe to always do?
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (THRIFT-539) struct hash and print methods for C++
Posted by "Nitay Joffe (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/THRIFT-539?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Nitay Joffe updated THRIFT-539:
-------------------------------
Attachment: thrift-539.patch
Patch rebased to latest trunk.
This patch has three parts:
# Add operator<< to Thrift structs. This uses some recursive template magic that I added in
# Add an option to generate a boost style hash_value() function to thrift structs. This is only generated if you specify the option "boost_hash" to the thrift compiler. I made this an option because it adds a dependency on the header boost/functional.hash.hpp
# Generate TBB style HashCompare struct. The hash function in this currently just calls the hash_value() above, so this also is only generated if the option "boost_hash" is given. This doesn't actually require any TBB headers to be included, so in theory it's safe to always put it in. If you want, I can make it do it's own hashing (not depend on boost hash_value()) and then always include it.
Let me know what you think. I am fine with ripping out certain pieces of this patch. Please don't dismiss the whole patch because you don't like one part of it.
> struct hash and print methods for C++
> -------------------------------------
>
> Key: THRIFT-539
> URL: https://issues.apache.org/jira/browse/THRIFT-539
> Project: Thrift
> Issue Type: New Feature
> Components: Compiler (C++), Library (C++)
> Reporter: Nitay Joffe
> Priority: Minor
> Attachments: thrift-539.patch
>
>
> The current thrift compiler for C++ generates methods for structs like operator== and operator< since it uses maps,sets, etc but it does not generate a hash() method or a human readable print() method.
> The idea of this issue is to add functionality to the C++ compiler to generate:
> # A boost hash compatible hash_value() function. This should probably be an option to the compiler as it adds a dependency in generated code on boost.
> # An operator<< function for printing structs in a nice form. This should be safe to always do?
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (THRIFT-539) struct hash and print methods for C++
Posted by "David Reiss (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/THRIFT-539?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
David Reiss updated THRIFT-539:
-------------------------------
Priority: Minor (was: Major)
Issue Type: New Feature (was: Improvement)
You can already get a pretty decent human-readable representation of a structure by serializing it with the TDebugProtocol.
> struct hash and print methods for C++
> -------------------------------------
>
> Key: THRIFT-539
> URL: https://issues.apache.org/jira/browse/THRIFT-539
> Project: Thrift
> Issue Type: New Feature
> Components: Compiler (C++), Library (C++)
> Reporter: Nitay Joffe
> Priority: Minor
>
> The current thrift compiler for C++ generates methods for structs like operator== and operator< since it uses maps,sets, etc but it does not generate a hash() method or a human readable print() method.
> The idea of this issue is to add functionality to the C++ compiler to generate:
> # A boost hash compatible hash_value() function. This should probably be an option to the compiler as it adds a dependency in generated code on boost.
> # An operator<< function for printing structs in a nice form. This should be safe to always do?
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.