Finding a set of all pair-wise ORs of two sets of integers

前端 未结 1 1252
有刺的猬
有刺的猬 2021-02-11 01:26

Given two sets, each containing integer values, how could one find a set containing all possible pair-wise ORs of the values of those two sets? E.g. (all numbers ar

相关标签:
1条回答
  • 2021-02-11 01:48

    Although I don't know much about it, I wonder if, depending on the cardinality of the data, using a trie for one set could improve efficiency. When traversing the other set to or with the indexed set, whole branches of the tree may be skipped if it can be determined that bits are matched for the current integer in the indexed set.

    Another optimization could be to skip all pairings of bit-length n if we already have 2^(n-1) results of that length; for example, there are eight possible integers, four bits in length.

    0 讨论(0)
提交回复
热议问题