I have multiple arrays with about 100 possible values, ie:
a[0] = (a, b, c, d)
a[1] = (a, e)
a[2] = (d, f, g)
I want to FASTLY return which arrays contains (a || b) && (d || e)
in this example, 0 and 1
I was thinking about bitwise operations... like representing "abcd" by "1111"; "ad" by "1001", and so on. Then I could solve the "OR" with just a bitwise OR, and then check if both are non-zero
can anyone think on a better solution? this one isn't very pratical since it doesn't seem to be very escalable
are there any DBMS that can do that quickly? I tried with mongodb, but it seems they didn't add the "$and" function yet (doc says it's on version 1.9.1, but I can only download 1.9.0, and it's not stable anyway)
I suppose that's a "boolean search", similar to what google does all the time... so I'm guessing there's a better way (maybe not so fast, but more escalable) than that
The boolean array can be used to store boolean datatype values only and the default value of the boolean array is false. An array of booleans are initialized to false and arrays of reference types are initialized to null. In some cases, we need to initialize all values of the boolean array with true or false.
Binary Search is a searching algorithm for finding an element's position in a sorted array. In this approach, the element is always searched in the middle of a portion of an array. Binary search can be implemented only on a sorted list of items. If the elements are not sorted already, we need to sort them first.
Use filter if you want to find all items in an array that meet a specific condition. Use find if you want to check if that at least one item meets a specific condition. Use includes if you want to check if an array contains a particular value. Use indexOf if you want to find the index of a particular item in an array.
Boolean arrays can be used to select elements of other numpy arrays. If a is any numpy array and b is a boolean array of the same dimensions then a[b] selects all elements of a for which the corresponding value of b is True .
Yes, a bitwise solution works quite nicely for this. Yes, some databases include such a capability, usually named a bitmapped column (or bitmapped index, depending). The usual advice is to apply it to a column that has relatively low cardinality (i.e., a fairly small number of possible values, such as sex).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With