How to delete arbitrary objects in repeated field? (protobuf)

后端 未结 5 1217
广开言路
广开言路 2021-02-18 17:51

I have some entries in the repeated field in my proto. Now I want delete some of them. How can I accomplish this? There is a function to delete the last element, but I want to d

5条回答
  •  走了就别回头了
    2021-02-18 18:27

    According to the API docs, there isn't a way to arbitrarily remove an element from within a repeated field, just a way to remove the last one.

    ...
    We don't provide a way to remove any element other than the last because it invites inefficient use, such as O(n^2) filtering loops that should have been O(n). If you want to remove an element other than the last, the best way to do it is to re-arrange the elements so that the one you want removed is at the end, then call RemoveLast()
    ...

提交回复
热议问题