Quickly find whether a value is present in a C array?

前端 未结 15 1270
灰色年华
灰色年华 2021-01-29 17:30

I have an embedded application with a time-critical ISR that needs to iterate through an array of size 256 (preferably 1024, but 256 is the minimum) and check if a value matches

15条回答
  •  无人及你
    2021-01-29 18:12

    In this case, it might be worthwhile investigating Bloom filters. They're capable of quickly establishing that a value is not present, which is a good thing since most of the 2^32 possible values are not in that 1024 element array. However, there are some false positives that will need an extra check.

    Since your table is apparently static, you can determine which false positives exist for your Bloom filter and put those in a perfect hash.

提交回复
热议问题