Which is the fastest STL container for find?

后端 未结 5 1222
慢半拍i
慢半拍i 2020-12-08 00:35

Alright as a preface I have a need to cache a relatively small subset of rarely modified data to avoid querying the database as frequently for performance reasons. This data

5条回答
  •  情书的邮戳
    2020-12-08 01:13

    If you only want to search for distinct values, one specific column in the table, then std::hash is fastest.

    If you want to be able to search using several different predicates, you will need some kind of index structure. It can be implemented by extending your current vector based approach with several hash tables or maps, one for each field to search for, where the value is either an index into the vector, or a direct pointer to the element in the vector.

    Going further, if you want to be able to search for ranges, such as all occasions having a date in July you need an ordered data structure, where you can extract a range.

提交回复
热议问题