|
-
Jan 31st, 2014, 01:47 PM
#1
Thread Starter
Hyperactive Member
Finding Patterns In A Byte Array
Assume the following byte array: {0, 0, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 3, 4, 3, 4, 3, 4}.
I am trying to find the patterns in the array. I have been able to find the following patterns easily:
Pattern 1: {0, 0}
Pattern 2: {1, 2}
Pattern 3: {3, 4}
I then store the indices and counts of each pattern in another array, like so: {0, 0, 1, 6, 2, 2}. Basically, they are stored in two bytes each. The first byte is the pattern index, while the second byte is the count - 1.
e.g. Pattern 1 (index 0) is found 1 time (stored as count - 1, or 0). Pattern 2 (index 1) is found 7 times (stored as count - 1, or 6), et cetera.
What I want is: Instead of storing the pattern index and the count, I would just store the pattern index. The patterns would look like this:
Pattern 1: {0, 0}
Pattern 2: {1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2}
Pattern 3: {3, 4, 3, 4, 3, 4}
I could then store them just by their index, i.e. {0, 1, 2}.
Here is another example: {0, 0, 1, 2, 1, 2, 1, 2, 3, 4, 3, 4, 3, 4, 1, 2, 1, 2, 1, 2, 0, 0}.
The patterns would be: {0, 0}, {1, 2, 1, 2, 1, 2}, {3, 4, 3, 4, 3, 4}. When stored, the resulting array would be: {0, 1, 2, 1, 0}.
Thanks.
Prefix has no suffix, but suffix has a prefix.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|