Original Post
Given a binary string and a trinary string of equal length (length is arbitrary but known a priori ) I''m looking for a fast way to do string comparisons. That is, to compare bits in one string with trits in the other, according to the following truth table,
bit
| 0 | 1 |
---------
0 | 1 | 0 |
trit 1 | 0 | 1 |
2 | 1 | 1 |
and to return the number of positions matched (if all positions match, then obviously the strings match given the truth table).
Note, I only need to perform binary-trinary tests, not trinary-trinary.
So far, the best I have been able to come up with is iterating along the length of the string, comparing individual characters as follows:
For the trinary string, I thought to use a dual binary string representation. So, for example, the trinary string of 0200112202 could be represented by the pair of strings:
0100111101 and 0000110000. Denote a character in the trinary string as ti and thus its twin binary characters are t1i and t2i. The comparison can then be tested for an arbitrary binary string - with characters bi - against both t1i and t2i and a match occurs if (bi AND t1i) OR (bi> AND t2i).
My question is... can anyone think of a faster way of doing this, either using a better representation of the trinary string, the comparison operation, both, or perhaps just a really fast and funky way to implement this with bitwise operations and bit-packed integers (as opposed to arrays of values).
I''d like to be able to do at least one million such string comparisons each second, but obviously I''m limited by algorithmic complexity and hardware. I''m starting with algorithmic complexity... I can worry about hardware later. (Of course, if someone can present a way of achieving more than a million such comparisons per second on current hardware, then huge qudos to you).
Thanks,
Timkin