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
-~--~~~~--~~--~--~---



"Lite" mode is in SVN -- mostly

2009-07-28 Thread Kenton Varda
I just committed the new "lite mode" refactoring for C++ and Java to SVN.
To use the new feature, add this line to your .proto file:
  option optimize_for = LITE_RUNTIME;
This will cause protoc to generate code which is just as fast as with
optimize_for = SPEED, but lacks descriptors, reflection, UnknownFieldSet,
and features which are tied to them.  This means the code can be linked
against a much smaller subset of the protocol buffers runtime library and
will not spend time at start-up building descriptors.

Currently, the C++ Makefile will compile libprotobuf and libprotobuf-lite as
independent, stand-alone libraries, even though the latter is a subset of
the former.  Is this what we want?  I'm not sure.  If we make libprotobuf
depend on libprotobuf-lite, then users who want the full library will have
to specify *both* when linking their own apps, unless we provide a
"protobuf-config" script or something like that.  Complicating things
further, if you app does not use extensions, then extension_set.cc can be
removed from the lite library to make it even smaller, but having three
separate libraries just seems excessive!
For Java, I have not yet updated the Maven POM to separate the libraries.
 I'm not sure how -- Greg, can you work on this?  "Lite" messages need only
the following classes:
  AbstractMessageLite.java
  ByteString.java
  CodedInputStream.java
  CodedOutputStream.java
  ExtensionRegistryLite.java
  FieldSet.java
  GeneratedMessageLite.java
  InvalidProtocolBufferException.java
  Internal.java
  MessageLite.java
  UninitializedMessageException.java
  WireFormat.java

*Numbers*

C++, as measured by the "size" command on Linux:
  libprotobuf.so: 948k
  libprotobuf-lite.so: 148k
  libprotobuf-lite.so with extension_set.cc removed: 91k

Java, measured by totalling the sizes of the .class files:
  full library:  904k
  lite library:  120k

I suspect we can further reduce some of these numbers with some more work.
 For instance, an extension-less Java lite library might be as much as 50k
smaller, though will require a bit more work than simply yanking some
classes.

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---