c++ - fast rule out if a member is in a set -


i have small group of numbers, need search.

the group static , known @ begining of time.

i know observations of time number searching not in group.

what searching algoroithm in 1 or 2 instructions will:

  1. never number not in group , is
  2. the algorithm or of time predicts if is

for example,

if numbers x,y,z can following:

save:

tmp = (x | y | z) 

when search number can do:

if ((num & tmp) == (num))     real search 

if number x, y or z guarantee return num when doing , it. if not might search nothing - thats ok.

the main problem test of time more 5 numbers in group true if num not in group.

i thinking of using xor magic:

tmp = (x ^ y ^ z) 

and when searching like:

(num ^ tmp) 

but don't see how can me figure if element in group or not.

any ideas ?

thanks,

itay

update

what have found useful using simplistic bloom filter:

i've hashed x, y , z bit array (for example 8 bits). then, have shiftted results correct bits:

uint8_t digest = (1 << (x % 8)) | (1 << (y % 8)) | (1 << (z % 8)) 

and on search function i've used:

if ( (1 << (num % 8)) & digest ) 

i did profiling using random numbers , got using 8 bits gave me false indications on 30% of time. using 16 bit made better.

for 7 numbers, should brute force search through set; it'll faster other method. if values 16 bits or fewer, can in single simd equality test; if they're 32 bits, can in two.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -