c++ - Delete a random value from repeated string ( list ) in Google Protocol buffer -


i want delete item repeated field

for have message defination:

message foo { repeated string temp1 ;  repeated string temp2 ;  } 

i want remove item temp1 @ random index;

as per knowledge can delete swapping last element , using removelast; dont know how use that. code snapshot in c++ ?

here 1 reason why there no remove() in protocol buffer.

i didn't want provide remove(int) because o(n). version 1 of protocol buffers had such function, , saw people writing loops like:

 (int = 0; < field.size(); i++) {   if (shouldfilter(field[i])) {     field.remove(i);     --i;   } } 

this loop o(n^2), bad, it's hard tell o(n^2). idea behind providing removelast() force either clever (like swapping element last element first, documentation suggests) or write own loop makes time complexity of code obvious.

two options here:

  • copy item end of list space formerly occupied item want delete, call removelast().

  • by using iterator erase(const_iterator position), should start begin(), check whether value of iterator should removed.


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -