A
A
Askar Fuzaylov2015-04-16 12:58:04
Programming
Askar Fuzaylov, 2015-04-16 12:58:04

How to compare compose a bitmask with more conditions?

There are many conditions (country, device model, manufacturer, etc.). I need to create a bitmask for various existing devices to determine if a particular item is available.
A couple of conditions:
One product can belong to several countries and manufacturers.
The product may not have a country.
I can't figure out how to create a mask, for example, for countries, in order to later determine whether there is a certain country or not.
How can I create a bitmask so that I can compare the new product with the conditions?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2015-04-16
Protko @Fesor

In general, it seems to me that bit masks are not the most efficient way to organize a faceted search.
It is possible to make multiple bitmasks, such as each bit of the value being a country-specific presence flag (this implies the restriction that we can only use 32/64 countries per value depending on the platform for long unsigned). Well, further by analogy.

E
evnuh, 2015-04-16
@evnuh

For each item from the filter (country-Russia, for example, or model-a5, for example), store a bitmap of length N bits, where N is the total number of goods. In the bitmap, 1 in place of k means that the product with id=k belongs to this filter item. That's all. Obviously product ids should start at 1, or fix offset = MIN(id) for each product index to map it to a bit in the bitmap.
With this approach, you have no restrictions - on multiple membership, on a selection with AND or OR conditions (for example, the color is red AND the country is Russia, or the color is red OR the color is green), which are solved by simply multiplying or adding bitmaps.
All this economy is perfectly stored in Redis with its excellent support for bitmaps and a full set of operations on them.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question