455,905 Members | 1,283 Online
Need help? Post your question and get tips & solutions from a community of 455,905 IT Pros & Developers. It's quick & easy.

# Q: Recoding some masking routine

 P: n/a Hi, Got a query, don't know if anyone would be kind enough to help... I have to either match a string exactly eg "123456789ABCDEF123456789ABCDEF" == "123456789ABCDEF123456789ABCDEF", or if a packed byte bit mask is set mask1 = 1, mask2 = 4, "123456789ABCDEF123456789ABCDEF" == "123456789ABCDEF1234x6789ABCDEx". The mask means that the character at x can match either the original number, or a set character ('x'). The original string can be up to 80 chars long with 10 8-bit bytes containg the masks. I have done this, by a plodding for loop with lots of ifs, alas it's untidy and slow. Any pointers to tidy & speed would be a great help. Thank-you. May 23 '07 #1
9 Replies

 P: n/a What is the relationship between x and the mask? May 23 '07 #2

 P: n/a Quentin Godfroy . -- Keith Thompson (The_Other_Keith) ks***@mib.org San Diego Supercomputer Center <* "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" May 24 '07 #3

 P: n/a On 23 May 2007 16:35:34 -0700, Quentin Godfroy What is the relationship between x and the mask? if that byte is masked, the field can either be it's original value or one other pre-defined character so string to compare against = "12345678", mask = 2 (00000010), pre-defined char = "Z" Strings to compare:- "12345678" = match "123456Z8" = match "12345Z78" = NO match "12345578" = NO match Hope that makes it a little clearer. May 24 '07 #4

 P: n/a On 24 May, 00:09, f...@off.spammers.org wrote: Hi, Got a query, don't know if anyone would be kind enough to help... I have to either match a string exactly eg "123456789ABCDEF123456789ABCDEF" == "123456789ABCDEF123456789ABCDEF", or if a packed byte bit mask is set mask1 = 1, mask2 = 4, "123456789ABCDEF123456789ABCDEF" == "123456789ABCDEF1234x6789ABCDEx". The mask means that the character at x can match either the original number, or a set character ('x'). The original string can be up to 80 chars long with 10 8-bit bytes containg the masks. I have done this, by a plodding for loop with lots of ifs, alas it's untidy and slow. Any pointers to tidy & speed would be a great help. As far as I understand the required behaviour, you have a string ("original") of up to 80 bytes which you are examining, and another string ("pattern") of the same size (?) against which you are comparing it. In addition to simple character equality, you need to test bytes at specific locations - bytes at these locations in "original" can either match the corresponding byte in "pattern" or match a single specific other byte. Locations for this dual matching are specified by bit masks in an additional byte array, with one byte in the array corresponding to 8 bytes in the original string. Is that correct so far? My natural instinct here is to split the matching down into 8-byte "chunks". This was fairly easy to do and IMHO didn't seem hugely ugly (I'm not going to post my code yet, as it's far from clear that I've understood the requirement). How ugly is your code? Could you post a small self-contained example to show what you've currently tried? I haven't measured speed in my case. Why do you feel it's slow in yours? What measures have you used? Have you profiled to the code to see where the time is going? May 24 '07 #5