[protobuf] Re: How to sort the repeated element?

2013-01-20 Thread Xingliang Ni
how to sort it using java?



在 2009年7月30日星期四UTC+8上午2时28分29秒,Kenton Varda写道:
>
> In C++, you can use the standard STL sort() function:
>   http://www.sgi.com/tech/stl/sort.html
>
> RepeatedPtrField supports 
> iterators, so you can do something like:
>
>   #include 
>
>   struct StudentOrdering {
> inline operator()(const Student* a, const Student* b) {
>   return a->score() < b->score();
> }
>   }
>
>   void SortStudents(Class* cls) {
> std::sort(cls->mutable_student()->begin(),
>   cls->mutable_student()->end(),
>   StudentOrdering());
>   }
>
> On Tue, Jul 28, 2009 at 8:03 PM, 李海波 >wrote:
>
>>
>> example:
>> ==.proto file 
>> message Class{
>>message Student{
>>required string name = 1;
>>required int32 score  = 2;
>>}
>>
>>repeated Student student = 1;
>> }
>> =
>>
>> I want to sort students of the class by score,how can i do?
>>
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/protobuf/-/Vcc9Khru_KoJ.
To post to this group, send email to protobuf@googlegroups.com.
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.



[protobuf] Re: How to sort the repeated element?

2013-01-20 Thread Xingliang Ni
hi,do you know how to do this in java?

On Thursday, July 30, 2009 2:28:29 AM UTC+8, Kenton Varda wrote:
>
> In C++, you can use the standard STL sort() function:
>   http://www.sgi.com/tech/stl/sort.html
>
> RepeatedPtrField supports 
> iterators, so you can do something like:
>
>   #include 
>
>   struct StudentOrdering {
> inline operator()(const Student* a, const Student* b) {
>   return a->score() < b->score();
> }
>   }
>
>   void SortStudents(Class* cls) {
> std::sort(cls->mutable_student()->begin(),
>   cls->mutable_student()->end(),
>   StudentOrdering());
>   }
>
> On Tue, Jul 28, 2009 at 8:03 PM, 李海波 >wrote:
>
>>
>> example:
>> ==.proto file 
>> message Class{
>>message Student{
>>required string name = 1;
>>required int32 score  = 2;
>>}
>>
>>repeated Student student = 1;
>> }
>> =
>>
>> I want to sort students of the class by score,how can i do?
>>
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/protobuf/-/NYDe0QdPlUEJ.
To post to this group, send email to protobuf@googlegroups.com.
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.



Re: How to sort the repeated element?

2009-07-30 Thread 李海波

thanks,this is what i looking for.

On Jul 30, 2:28 am, Kenton Varda  wrote:
> In C++, you can use the standard STL sort() 
> function:http://www.sgi.com/tech/stl/sort.html
>
> RepeatedPtrField supports iterators,
> so you can do something like:
>
>   #include 
>
>   struct StudentOrdering {
>     inline operator()(const Student* a, const Student* b) {
>       return a->score() < b->score();
>     }
>   }
>
>   void SortStudents(Class* cls) {
>     std::sort(cls->mutable_student()->begin(),
>               cls->mutable_student()->end(),
>               StudentOrdering());
>   }
>
>
>
> On Tue, Jul 28, 2009 at 8:03 PM, 李海波  wrote:
>
> > example:
> > ==.proto file 
> > message Class{
> >    message Student{
> >        required string name = 1;
> >        required int32 score  = 2;
> >    }
>
> >    repeated Student student = 1;
> > }
> > =
>
> > I want to sort students of the class by score,how can i do?- Hide quoted 
> > text -
>
> - Show quoted text -
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to protobuf@googlegroups.com
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en
-~--~~~~--~~--~--~---



Re: How to sort the repeated element?

2009-07-29 Thread Kenton Varda
In C++, you can use the standard STL sort() function:
http://www.sgi.com/tech/stl/sort.html

RepeatedPtrField supports iterators,
so you can do something like:

  #include 

  struct StudentOrdering {
inline operator()(const Student* a, const Student* b) {
  return a->score() < b->score();
}
  }

  void SortStudents(Class* cls) {
std::sort(cls->mutable_student()->begin(),
  cls->mutable_student()->end(),
  StudentOrdering());
  }

On Tue, Jul 28, 2009 at 8:03 PM, 李海波  wrote:

>
> example:
> ==.proto file 
> message Class{
>message Student{
>required string name = 1;
>required int32 score  = 2;
>}
>
>repeated Student student = 1;
> }
> =
>
> I want to sort students of the class by score,how can i do?
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to protobuf@googlegroups.com
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en
-~--~~~~--~~--~--~---



Re: How to sort the repeated element?

2009-07-28 Thread xiliu tang
You can write a customize sort functor when using the stl, which sort the
index of the students, like:struct SortStudent : public
binnary_function {
  SortStudent(Class *cl) : cl_(cl) {
  }
  bool operator() (int i, int j) {
   int32 score1 = cl_->student(i).score();
   int32 score2 = cl_->student(j).score();
   return score1 < score2;
  }
  Class *cl_;
};

Class *cl; // Where you can get the Class instance.
int num_student = cl->student_size();
vector student_indice;
for (int i = 0; i < num_student; ++i) {
  student_indice.push_back(i);
}
sort(student_indice.begin(), student_indice.end(), SortStudent(cl));

2009/7/29 李海波 

>
> example:
> ==.proto file 
> message Class{
>message Student{
>required string name = 1;
>required int32 score  = 2;
>}
>
>repeated Student student = 1;
> }
> =
>
> I want to sort students of the class by score,how can i do?
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to protobuf@googlegroups.com
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en
-~--~~~~--~~--~--~---



How to sort the repeated element?

2009-07-28 Thread 李海波

example:
==.proto file 
message Class{
message Student{
required string name = 1;
required int32 score  = 2;
}

repeated Student student = 1;
}
=

I want to sort students of the class by score,how can i do?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to protobuf@googlegroups.com
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en
-~--~~~~--~~--~--~---