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

Nicolas Trésegnie commented on THRIFT-1603:
-------------------------------------------

I think we can:
{code}The elements in the range shall already be sorted according to this same 
criterion (operator< or comp), or at least partitioned with respect to 
val.{code}
Every new insert keeps the vector sorted so bounds.second will contain the 
right position.

{code}members_in_id_order_.insert( elem.get_key(), elem);{code}
You would get a segmentation fault because it's a vector, not a dictionary. The 
position of the field in the vector is different from the field id.

---

For the insertion speed:

# equal_range is O(log(N)) because the elements are sorted
# get_field_by_name is O(N) because it runs through the entire vector
# push_back is O(1)
# insert is O(N) because the entire vector could be copied.
# validate_union_member is O(1)

So the execution time is O(N²) for a structure of N fields. This could be O(N 
log N) using two maps (one for the ids and one for the names) because std::map 
keep the elements sorted (they need to be sorted for the fingerprint 
generation).

The actual version of the code isn't broken, so does it worth the trouble? (The 
getters return a vector, not simply an iterator, so the changes may require a 
little bit of extra work.)
                
> Thrift IDL allows for multiple exceptions, args or struct member names to be 
> the same
> -------------------------------------------------------------------------------------
>
>                 Key: THRIFT-1603
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1603
>             Project: Thrift
>          Issue Type: Bug
>         Environment: RedHat 5.5, C++, thrift-0.8.0
>            Reporter: Michael Popovich
>            Assignee: Kamil Sałaś
>            Priority: Trivial
>             Fix For: 1.0
>
>         Attachments: 
> 0001-Thrift-1603-Provide-unique-names-for-t_struct-elemen.patch
>
>
> I noticed that the Thrift IDL compiler allows for multiple exceptions 
> instances to utilize the same name... This is a problem because when 
> compiling to C++, the generated C++ code will not compile properly:
> service whatever
> {
> void insert(1: string s) throws (1: NS nst, WX wxx, NSTx nst),
> }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to