If the database is fairly static, you may need to build a tree data structure on it.
Search a tree recursively or in multiple threads, and the actual variable is stored for each search. If the actual difference becomes larger than what you think is βsimilar,β interrupt the search.
eg. Suppose we have the following tree:
root
0 1
0 1 0 1
0 1 0 1 0 1 0 1
If you want to search for patterns similar to 011 and only want to allow a maximum of 1 bit, do a search like this (recursively or multithreaded):
- Start from the root
- Take the left branch (0), it looks like so the difference is still 0
- Take the left branch (0), this is different, so the difference becomes 1, which is still acceptable
- take the left branch (0), it's different, so the difference becomes 2, which is too big. Cancel the search in this thread.
- (1), , 1, ( ).
- (1), , 0,
, .
, .
, 64- .