2017-01-31 5 views
0

たとえば、いくつかのデータ型の繰り返しでprotoファイルを作成します。Google Protobufで反復処理される時間複雑化された反復オブジェクト

DocList.Builder docList = new DocList.newBuilder() 
docList.addAllDocId(docIDlist);   // docIDList is ArrayList<String> 

今、私たちはインデックスのオブジェクトを取得するには、次のget操作を実行します。

message DocList{ 
    repeated string docId = 1; 
} 

は今、我々はそれが次のようにビルダーオブジェクトのにオブジェクトを挿入します。

docList.getDocId(i); // Some index i 

私はこれを得る操作はO(1)またはO(n)があるかどうかを知りたいですか?

答えて

1

いるProtobuf ListValueが故に、それがGET()

OpenJDK ArrayList

@SuppressWarnings("unchecked") 
E elementData(int index) { 
    return (E) elementData[index]; 
} 
ためのO(1)である java.util.ArrayListの

if (!((mutable_bitField0_ & 0x00000001) == 0x00000001)) { 
     values_ = new java.util.ArrayList<com.google.protobuf.Value>(); 
     mutable_bitField0_ |= 0x00000001; 
} 

によって支えられて