C++ Contest Challenge

V

virtualadepts

This contest is open to everyone who knows C++. To enter all you need
to do is take the Boyer-Moore String Search Algorithm, as it is
written in C, and make the fastest running C++ program you can out of
it. I'm going to try to write code myself, and if you can beet me,
and your code executes faster, then you win a free I-Pod. My I-Pod is
used, but it comes jam packed with songs I've been listening to. So
take a crack at this problem and post your solution to the group. :)

http://en.wikipedia.org/wiki/Boyer-Moore_string_search_algorithm

#include <string.h>
#include <limits.h>

/* This helper function checks, whether the last "portion" bytes
* of "needle" (which is "nlen" bytes long) exist within the "needle"
* at offset "offset" (counted from the end of the string),
* and whether the character preceding "offset" is not a match.
* Notice that the range being checked may reach beyond the
* beginning of the string. Such range is ignored.
*/
static int boyermoore_needlematch
(const unsigned char* needle, size_t nlen, size_t portion, size_t
offset)
{
ssize_t virtual_begin = nlen-offset-portion;
ssize_t ignore = 0;
if(virtual_begin < 0) { ignore = -virtual_begin; virtual_begin =
0; }

if(virtual_begin > 0 && needle[virtual_begin-1] == needle[nlen-
portion-1])
return 0;

return
memcmp(needle + nlen - portion + ignore,
needle + virtual_begin,
portion - ignore) == 0;
}

static size_t max(ssize_t a, ssize_t b) { return a>b ? a : b; }

/* Returns a pointer to the first occurrence of "needle"
* within "haystack", or NULL if not found.
*/
const unsigned char* memmem_boyermoore
(const unsigned char* haystack, size_t hlen,
const unsigned char* needle, size_t nlen)
{
size_t skip[nlen]; /* Array of shifts with self-substring match
check */
ssize_t occ[UCHAR_MAX+1]; /* Array of last occurrence of each
character */
size_t a, hpos;

if(nlen > hlen || nlen <= 0 || !haystack || !needle) return NULL;

/* Preprocess #1: init occ[]*/

/* Initialize the table to default value */
for(a=0; a<UCHAR_MAX+1; ++a) occ[a] = -1;

/* Then populate it with the analysis of the needle */
/* But ignoring the last letter */
for(a=0; a<nlen-1; ++a) occ[needle[a]] = a;

/* Preprocess #2: init skip[] */
/* Note: This step could be made a lot faster.
* A simple implementation is shown here. */
for(a=0; a<nlen; ++a)
{
size_t value = 0;
while(value < nlen && !boyermoore_needlematch(needle, nlen, a,
value))
++value;
skip[nlen-a-1] = value;
}

/* Search: */
for(hpos=0; hpos <= hlen-nlen; )
{
size_t npos=nlen-1;
while(needle[npos] == haystack[npos+hpos])
{
if(npos == 0) return haystack + hpos;
--npos;
}
hpos += max(skip[npos], npos - occ[haystack[npos+hpos]]);
}
return NULL;
}
 
V

virtualadepts

This contest is open to everyone who knows C++. To enter all you need
to do is take the Boyer-Moore String Search Algorithm, as it is
written in C, and make the fastest running C++ program you can out of
it. I'm going to try to write code myself, and if you can beet me,
and your code executes faster, then you win a free I-Pod. My I-Pod is
used, but it comes jam packed with songs I've been listening to. So
take a crack at this problem and post your solution to the group. :)

http://en.wikipedia.org/wiki/Boyer-Moore_string_search_algorithm

#include <string.h>
#include <limits.h>

/* This helper function checks, whether the last "portion" bytes
* of "needle" (which is "nlen" bytes long) exist within the "needle"
* at offset "offset" (counted from the end of the string),
* and whether the character preceding "offset" is not a match.
* Notice that the range being checked may reach beyond the
* beginning of the string. Such range is ignored.
*/
static int boyermoore_needlematch
(const unsigned char* needle, size_t nlen, size_t portion, size_t
offset)
{
ssize_t virtual_begin = nlen-offset-portion;
ssize_t ignore = 0;
if(virtual_begin < 0) { ignore = -virtual_begin; virtual_begin =
0; }

if(virtual_begin > 0 && needle[virtual_begin-1] == needle[nlen-
portion-1])
return 0;

return
memcmp(needle + nlen - portion + ignore,
needle + virtual_begin,
portion - ignore) == 0;

}

static size_t max(ssize_t a, ssize_t b) { return a>b ? a : b; }

/* Returns a pointer to the first occurrence of "needle"
* within "haystack", or NULL if not found.
*/
const unsigned char* memmem_boyermoore
(const unsigned char* haystack, size_t hlen,
const unsigned char* needle, size_t nlen)
{
size_t skip[nlen]; /* Array of shifts with self-substring match
check */
ssize_t occ[UCHAR_MAX+1]; /* Array of last occurrence of each
character */
size_t a, hpos;

if(nlen > hlen || nlen <= 0 || !haystack || !needle) return NULL;

/* Preprocess #1: init occ[]*/

/* Initialize the table to default value */
for(a=0; a<UCHAR_MAX+1; ++a) occ[a] = -1;

/* Then populate it with the analysis of the needle */
/* But ignoring the last letter */
for(a=0; a<nlen-1; ++a) occ[needle[a]] = a;

/* Preprocess #2: init skip[] */
/* Note: This step could be made a lot faster.
* A simple implementation is shown here. */
for(a=0; a<nlen; ++a)
{
size_t value = 0;
while(value < nlen && !boyermoore_needlematch(needle, nlen, a,
value))
++value;
skip[nlen-a-1] = value;
}

/* Search: */
for(hpos=0; hpos <= hlen-nlen; )
{
size_t npos=nlen-1;
while(needle[npos] == haystack[npos+hpos])
{
if(npos == 0) return haystack + hpos;
--npos;
}
hpos += max(skip[npos], npos - occ[haystack[npos+hpos]]);
}
return NULL;

}

OKAY! I Golfed the algorithm. I just couldn't find an object
oriented way to do it. That means the contest is still open!

bool match()(const string & a, const string & b)
{
int len = a.size();
int mc = len;
int cnt = mc;

while(mc>0){
if(a[mc]==b[cnt]){ mc--; }
else if(mc<len){ mc=len;}
if(cnt==b.size(){ return false; }
cnt++;
}
return true;
}
 
V

virtualadepts

This contest is open to everyone who knows C++. To enter all you need
to do is take the Boyer-Moore String Search Algorithm, as it is
written in C, and make the fastest running C++ program you can out of
it. I'm going to try to write code myself, and if you can beet me,
and your code executes faster, then you win a free I-Pod. My I-Pod is
used, but it comes jam packed with songs I've been listening to. So
take a crack at this problem and post your solution to the group. :)

#include <string.h>
#include <limits.h>
/* This helper function checks, whether the last "portion" bytes
* of "needle" (which is "nlen" bytes long) exist within the "needle"
* at offset "offset" (counted from the end of the string),
* and whether the character preceding "offset" is not a match.
* Notice that the range being checked may reach beyond the
* beginning of the string. Such range is ignored.
*/
static int boyermoore_needlematch
(const unsigned char* needle, size_t nlen, size_t portion, size_t
offset)
{
ssize_t virtual_begin = nlen-offset-portion;
ssize_t ignore = 0;
if(virtual_begin < 0) { ignore = -virtual_begin; virtual_begin =
0; }
if(virtual_begin > 0 && needle[virtual_begin-1] == needle[nlen-
portion-1])
return 0;
return
memcmp(needle + nlen - portion + ignore,
needle + virtual_begin,
portion - ignore) == 0;

static size_t max(ssize_t a, ssize_t b) { return a>b ? a : b; }
/* Returns a pointer to the first occurrence of "needle"
* within "haystack", or NULL if not found.
*/
const unsigned char* memmem_boyermoore
(const unsigned char* haystack, size_t hlen,
const unsigned char* needle, size_t nlen)
{
size_t skip[nlen]; /* Array of shifts with self-substring match
check */
ssize_t occ[UCHAR_MAX+1]; /* Array of last occurrence of each
character */
size_t a, hpos;
if(nlen > hlen || nlen <= 0 || !haystack || !needle) return NULL;
/* Preprocess #1: init occ[]*/
/* Initialize the table to default value */
for(a=0; a<UCHAR_MAX+1; ++a) occ[a] = -1;
/* Then populate it with the analysis of the needle */
/* But ignoring the last letter */
for(a=0; a<nlen-1; ++a) occ[needle[a]] = a;
/* Preprocess #2: init skip[] */
/* Note: This step could be made a lot faster.
* A simple implementation is shown here. */
for(a=0; a<nlen; ++a)
{
size_t value = 0;
while(value < nlen && !boyermoore_needlematch(needle, nlen, a,
value))
++value;
skip[nlen-a-1] = value;
}
/* Search: */
for(hpos=0; hpos <= hlen-nlen; )
{
size_t npos=nlen-1;
while(needle[npos] == haystack[npos+hpos])
{
if(npos == 0) return haystack + hpos;
--npos;
}
hpos += max(skip[npos], npos - occ[haystack[npos+hpos]]);
}
return NULL;

OKAY! I Golfed the algorithm. I just couldn't find an object
oriented way to do it. That means the contest is still open!

bool match()(const string & a, const string & b)
{
int len = a.size();
int mc = len;
int cnt = mc;

while(mc>0){
if(a[mc]==b[cnt]){ mc--; }
else if(mc<len){ mc=len;}
if(cnt==b.size(){ return false; }
cnt++;
}
return true;
}

Hehe, nevermind. I'm still installing a compiler. I see where I went
wrong with the algorithm. This won't even find a match.
 
B

boson boss

This contest is open to everyone who knows C++. To enter all you need
to do is take the Boyer-Moore String Search Algorithm, as it is
written in C, and make the fastest running C++ program you can out of
it. I'm going to try to write code myself, and if you can beet me,
and your code executes faster, then you win a free I-Pod. My I-Pod is
used, but it comes jam packed with songs I've been listening to. So
take a crack at this problem and post your solution to the group. :)

http://en.wikipedia.org/wiki/Boyer-Moore_string_search_algorithm

#include <string.h>
#include <limits.h>

/* This helper function checks, whether the last "portion" bytes
* of "needle" (which is "nlen" bytes long) exist within the "needle"
* at offset "offset" (counted from the end of the string),
* and whether the character preceding "offset" is not a match.
* Notice that the range being checked may reach beyond the
* beginning of the string. Such range is ignored.
*/
static int boyermoore_needlematch
(const unsigned char* needle, size_t nlen, size_t portion, size_t
offset)
{
ssize_t virtual_begin = nlen-offset-portion;
ssize_t ignore = 0;
if(virtual_begin < 0) { ignore = -virtual_begin; virtual_begin =
0; }

if(virtual_begin > 0 && needle[virtual_begin-1] == needle[nlen-
portion-1])
return 0;

return
memcmp(needle + nlen - portion + ignore,
needle + virtual_begin,
portion - ignore) == 0;

}

static size_t max(ssize_t a, ssize_t b) { return a>b ? a : b; }

/* Returns a pointer to the first occurrence of "needle"
* within "haystack", or NULL if not found.
*/
const unsigned char* memmem_boyermoore
(const unsigned char* haystack, size_t hlen,
const unsigned char* needle, size_t nlen)
{
size_t skip[nlen]; /* Array of shifts with self-substring match
check */
ssize_t occ[UCHAR_MAX+1]; /* Array of last occurrence of each
character */
size_t a, hpos;

if(nlen > hlen || nlen <= 0 || !haystack || !needle) return NULL;

/* Preprocess #1: init occ[]*/

/* Initialize the table to default value */
for(a=0; a<UCHAR_MAX+1; ++a) occ[a] = -1;

/* Then populate it with the analysis of the needle */
/* But ignoring the last letter */
for(a=0; a<nlen-1; ++a) occ[needle[a]] = a;

/* Preprocess #2: init skip[] */
/* Note: This step could be made a lot faster.
* A simple implementation is shown here. */
for(a=0; a<nlen; ++a)
{
size_t value = 0;
while(value < nlen && !boyermoore_needlematch(needle, nlen, a,
value))
++value;
skip[nlen-a-1] = value;
}

/* Search: */
for(hpos=0; hpos <= hlen-nlen; )
{
size_t npos=nlen-1;
while(needle[npos] == haystack[npos+hpos])
{
if(npos == 0) return haystack + hpos;
--npos;
}
hpos += max(skip[npos], npos - occ[haystack[npos+hpos]]);
}
return NULL;

}




Here's an idea. Take that the data file contains binary data, it
certainly does anyway.



; Fastest binary string search algo with
; PPlain and PMMX type of processors
; <c> 2001 by buliaNaza ;
; ;
..data? ;
align 4 ; !!!
skip_table DD 256 Dup(?) ; skip table
; ;
;...............................;
; Usage: esi ->pBuffer ; esi->buffer with bytes to be
searched through
; ebp = lenBuffer ; ebp =length of the buffer
; ebx ->pSrchData ; ebx->pointer to data to be searched
for
; edx = lenSrchData ; edx=length of data to be searched
for
; edi ->pskip_table ; edi->pointer to skip table (must be
aligned)
; call BMCaseSNext ;
;.................................;
..code ;
BMCaseSNext: ;
cmp edx, 4 ; edx = length of data to be
searched for
jg Boyer_Moore ;
;... Brute Force Search ..........; for 4 digits or less only!
mov edi, [ebx] ; edi = dword of data to be searched
for
mov ecx, 5 ;
sub ecx, edx ;
lea eax, [esi+edx-1] ; eax->new starting address in
pBuffer
shl ecx, 3 ; *8
mov bl, [ebx+edx-1] ; get last byte only
mov bh, bl ; copy in bh
bswap edi ;
shr edi, cl ;
add ebp, esi ; ebp ->end of buffer
and ebx, 0FFFFh ; ebx = need the bx word only
mov ecx, ebx ;
mov esi, edx ; esi=edx = length of data to be
searched for
shl ecx, 16 ;
test eax, 3 ;
lea ebx, [ebx+ecx] ;
jz Search_2 ;
Unalign_1: ;
cmp eax, ebp ; ebp ->end of buffer
jge Not_found ;
mov cl, [eax] ;
inc eax ;
cmp cl, bl ;
jz Compare_1 ;
Search_1: ;
test eax, 3 ;
jnz Unalign_1 ;
Search_2: ;
cmp eax, ebp ;u ebp ->end of buffer
jge Not_found ;v
mov ecx, [eax] ;u scasb for the last byte from
pSrchData
add eax, 4 ;v
xor ecx, ebx ;u
mov edx, 7EFEFEFFh ;v
add edx, ecx ;u
xor ecx, -1 ;v
xor ecx, edx ;u
mov edx, [eax-4] ;v
and ecx, 81010100h ;u
jz Search_2 ;v
;
cmp dl, bl ;
jz Minus_4 ;
cmp dh, bl ;
jz Minus_3 ;
shr edx, 16 ;
cmp dl, bl ;
jz Minus_2 ;
cmp dh, bl ;
jz Compare_1 ;
jnz Search_2 ;
Minus_2: ;
dec eax ;
jnz Compare_1 ;
Minus_4: ;
sub eax, 3 ;
jnz Compare_1 ;
Minus_3: ;
sub eax, 2 ;
Compare_1: ;
mov edx, edi ;
cmp eax, ebp ; ebp ->end of buffer
jg Not_found ;
cmp esi, 1 ;
jz Found_1 ;
cmp dl, [eax-2] ; eax->pBuffer
jnz Search_1 ;
cmp esi, 2 ;
jz Found_1 ;
cmp dh, [eax-3] ; eax->pBuffer
jnz Search_1 ;
cmp esi, 3 ;
jz Found_1 ;
shr edx, 16 ;
mov cl, [eax-4] ; eax->pBuffer
cmp dl, cl ;
jnz Search_1 ;
Found_1: ;
sub eax, esi ; in eax->pointer to 1st
ret ; occurrence of data found in
pBuffer
;...Boyer Moore Case Sens Next Search...;
Boyer_Moore: ;
add esi, ebp ; esi->pointer to the last byte of
pBuffer
lea ebx, [ebx+edx-1] ; ebx->pointer to the last byte of
pSrchData
neg edx ; edx= -lenSrchData
mov ecx, edx ; ecx = edx = -lenSrchData
add ebp, edx ; sub lenSrchData from lenBuffer
mov eax, 256 ; eax = counter
xor ebp, -1 ; not ebp->current negative index
MaxSkipLens: ;
mov [eax*4+edi-4], edx ; filling up the skip_table with -
lenSrchData
mov [eax*4+edi-8], edx ;
mov [eax*4+edi-12], edx ;
mov [eax*4+edi-16], edx ;
mov [eax*4+edi-20], edx ;
mov [eax*4+edi-24], edx ;
mov [eax*4+edi-28], edx ;
mov [eax*4+edi-32], edx ;
mov [eax*4+edi-36], edx ;
mov [eax*4+edi-40], edx ;
mov [eax*4+edi-44], edx ;
mov [eax*4+edi-48], edx ;
mov [eax*4+edi-52], edx ;
mov [eax*4+edi-56], edx ;
mov [eax*4+edi-60], edx ;
mov [eax*4+edi-64], edx ;
mov [eax*4+edi-68], edx ;
mov [eax*4+edi-72], edx ;
mov [eax*4+edi-76], edx ;
mov [eax*4+edi-80], edx ;
mov [eax*4+edi-84], edx ;
mov [eax*4+edi-88], edx ;
mov [eax*4+edi-92], edx ;
mov [eax*4+edi-96], edx ;
mov [eax*4+edi-100], edx ;
mov [eax*4+edi-104], edx ;
mov [eax*4+edi-108], edx ;
mov [eax*4+edi-112], edx ;
mov [eax*4+edi-116], edx ;
mov [eax*4+edi-120], edx ;
mov [eax*4+edi-124], edx ;
mov [eax*4+edi-128], edx ;
sub eax, 32 ;
jne MaxSkipLens ; loop while eax=0
SkipLens: ;
mov al, [ecx+ebx+1] ;u filling up with the real negative
offset of
inc ecx ;v every byte from the pSrchData,
starting from
mov [eax*4+edi], ecx ;u the last to the first, at the offset
in
jne SkipLens ;v skip_table equal to the ASCII code of
the
; byte, multiplied by 4
Search: ; the main searching loop-> FAST PART
mov al, [esi+ebp] ;u get a byte from pBuffer ->esi +ebp
mov ecx, edx ;v ecx=edx= -lenSrchData
sub ebp, [eax*4+edi] ;u sub negative offset for this byte
from
; skip_table
jc Search ;v if dword ptr [eax*4+edi] AND ebp <> 0
loop
; again
lea ebp, [ebp+esi+1] ;u current negative index -> next byte
(+1)
jge Not_found ;v end of pBuffer control (if ebp>=0
end)
; compare previous bytes from pSrchData
(->ebx)
Compare: ; and current offset in pBuffer (->ebp)-
; PART
mov eax, [ebx+ecx+1] ; one dword from pSrchData -> ebx
inc ecx ; ecx = -lenSrchData
jz Found ; if ecx = 0 Found&Exit
cmp al, [ebp+ecx-1] ; ebp->pBuffer
jnz Not_equal ;
inc ecx ; ecx = -lenSrchData
jz Found ; if ecx = 0 Found&Exit
cmp ah, [ebp+ecx-1] ; ebp->pBuffer
jnz Not_equal ;
inc ecx ; ecx = -lenSrchData
jz Found ; if ecx=0 Found&Exit
shr eax, 16 ;
inc ecx ;
cmp al, [ebp+ecx-2] ; ebp->pBuffer
jnz Not_equal ;
test ecx, ecx ; ecx = -lenSrchData
jz Found ; if ecx=0 Found&Exit
cmp ah, [ebp+ecx-1] ; ebp->pBuffer
jz Compare ;
Not_equal: ;
sub eax, eax ; eax = 0
sub ebp, esi ; restore ebp->current negative index
jl Search ; end of pBuffer control
Not_found: ;
or eax, -1 ; Exit with flag Not_Found eax=-1
ret ;
Found: ;
lea eax, [ebp+edx] ; in eax->pointer to 1st
ret ; occurrence of data found in pBuffer
 
V

virtualadepts

This contest is open to everyone who knows C++. To enter all you need
to do is take the Boyer-Moore String Search Algorithm, as it is
written in C, and make the fastest running C++ program you can out of
it. I'm going to try to write code myself, and if you can beet me,
and your code executes faster, then you win a free I-Pod. My I-Pod is
used, but it comes jam packed with songs I've been listening to. So
take a crack at this problem and post your solution to the group. :)

#include <string.h>
#include <limits.h>
/* This helper function checks, whether the last "portion" bytes
* of "needle" (which is "nlen" bytes long) exist within the "needle"
* at offset "offset" (counted from the end of the string),
* and whether the character preceding "offset" is not a match.
* Notice that the range being checked may reach beyond the
* beginning of the string. Such range is ignored.
*/
static int boyermoore_needlematch
(const unsigned char* needle, size_t nlen, size_t portion, size_t
offset)
{
ssize_t virtual_begin = nlen-offset-portion;
ssize_t ignore = 0;
if(virtual_begin < 0) { ignore = -virtual_begin; virtual_begin =
0; }
if(virtual_begin > 0 && needle[virtual_begin-1] == needle[nlen-
portion-1])
return 0;
return
memcmp(needle + nlen - portion + ignore,
needle + virtual_begin,
portion - ignore) == 0;

static size_t max(ssize_t a, ssize_t b) { return a>b ? a : b; }
/* Returns a pointer to the first occurrence of "needle"
* within "haystack", or NULL if not found.
*/
const unsigned char* memmem_boyermoore
(const unsigned char* haystack, size_t hlen,
const unsigned char* needle, size_t nlen)
{
size_t skip[nlen]; /* Array of shifts with self-substring match
check */
ssize_t occ[UCHAR_MAX+1]; /* Array of last occurrence of each
character */
size_t a, hpos;
if(nlen > hlen || nlen <= 0 || !haystack || !needle) return NULL;
/* Preprocess #1: init occ[]*/
/* Initialize the table to default value */
for(a=0; a<UCHAR_MAX+1; ++a) occ[a] = -1;
/* Then populate it with the analysis of the needle */
/* But ignoring the last letter */
for(a=0; a<nlen-1; ++a) occ[needle[a]] = a;
/* Preprocess #2: init skip[] */
/* Note: This step could be made a lot faster.
* A simple implementation is shown here. */
for(a=0; a<nlen; ++a)
{
size_t value = 0;
while(value < nlen && !boyermoore_needlematch(needle, nlen, a,
value))
++value;
skip[nlen-a-1] = value;
}
/* Search: */
for(hpos=0; hpos <= hlen-nlen; )
{
size_t npos=nlen-1;
while(needle[npos] == haystack[npos+hpos])
{
if(npos == 0) return haystack + hpos;
--npos;
}
hpos += max(skip[npos], npos - occ[haystack[npos+hpos]]);
}
return NULL;

Here's an idea. Take that the data file contains binary data, it
certainly does anyway.

; Fastest binary string search algo with
; PPlain and PMMX type of processors
; <c> 2001 by buliaNaza ;
; ;
.data? ;
align 4 ; !!!
skip_table DD 256 Dup(?) ; skip table
; ;
;...............................;
; Usage: esi ->pBuffer ; esi->buffer with bytes to be
searched through
; ebp = lenBuffer ; ebp =length of the buffer
; ebx ->pSrchData ; ebx->pointer to data to be searched
for
; edx = lenSrchData ; edx=length of data to be searched
for
; edi ->pskip_table ; edi->pointer to skip table (must be
aligned)
; call BMCaseSNext ;
;.................................;
.code ;
BMCaseSNext: ;
cmp edx, 4 ; edx = length of data to be
searched for
jg Boyer_Moore ;
;... Brute Force Search ..........; for 4 digits or less only!
mov edi, [ebx] ; edi = dword of data to be searched
for
mov ecx, 5 ;
sub ecx, edx ;
lea eax, [esi+edx-1] ; eax->new starting address in
pBuffer
shl ecx, 3 ; *8
mov bl, [ebx+edx-1] ; get last byte only
mov bh, bl ; copy in bh
bswap edi ;
shr edi, cl ;
add ebp, esi ; ebp ->end of buffer
and ebx, 0FFFFh ; ebx = need the bx word only
mov ecx, ebx ;
mov esi, edx ; esi=edx = length of data to be
searched for
shl ecx, 16 ;
test eax, 3 ;
lea ebx, [ebx+ecx] ;
jz Search_2 ;
Unalign_1: ;
cmp eax, ebp ; ebp ->end of buffer
jge Not_found ;
mov cl, [eax] ;
inc eax ;
cmp cl, bl ;
jz Compare_1 ;
Search_1: ;
test eax, 3 ;
jnz Unalign_1 ;
Search_2: ;
cmp eax, ebp ;u ebp ->end of buffer
jge Not_found ;v
mov ecx, [eax] ;u scasb for the last byte from
pSrchData
add eax, 4 ;v
xor ecx, ebx ;u
mov edx, 7EFEFEFFh ;v
add edx, ecx ;u
xor ecx, -1 ;v
xor ecx, edx ;u
mov edx, [eax-4] ;v
and ecx, 81010100h ;u
jz Search_2 ;v
;
cmp dl, bl ;
jz Minus_4 ;
cmp dh, bl ;
jz Minus_3 ;
shr edx, 16 ;
cmp dl, bl ;
jz Minus_2 ;
cmp dh, bl ;
jz Compare_1 ;
jnz Search_2 ;
Minus_2: ;
dec eax ;
jnz Compare_1 ;
Minus_4: ;
sub eax, 3 ;
jnz Compare_1 ;
Minus_3: ;
sub eax, 2 ;
Compare_1: ;
mov edx, edi ;
cmp eax, ebp ; ebp ->end of buffer
jg Not_found ;
cmp esi, 1 ;
jz Found_1 ;
cmp dl, [eax-2] ; eax->pBuffer
jnz Search_1 ;
cmp esi, 2 ;
jz Found_1 ;
cmp dh, [eax-3] ; eax->pBuffer
jnz Search_1 ;
cmp esi, 3 ;
jz Found_1 ;
shr edx, 16 ;
mov cl, [eax-4] ; eax->pBuffer
cmp dl, cl ;
jnz Search_1 ;
Found_1: ;
sub eax, esi ; in eax->pointer to 1st
ret ; occurrence of data found in
pBuffer
;...Boyer Moore Case Sens Next Search...;
Boyer_Moore: ;
add esi, ebp ; esi->pointer to the last byte of
pBuffer
lea ebx, [ebx+edx-1] ; ebx->pointer to the last byte of
pSrchData
neg edx ; edx= -lenSrchData
mov ecx, edx ; ecx = edx = -lenSrchData
add ebp, edx ; sub lenSrchData from lenBuffer
mov eax, 256 ; eax = counter
xor ebp, -1 ; not ebp->current negative index
MaxSkipLens: ;
mov [eax*4+edi-4], edx ; filling up the skip_table with -
lenSrchData
mov [eax*4+edi-8], edx ;
mov [eax*4+edi-12], edx ;
mov [eax*4+edi-16], edx ;
mov [eax*4+edi-20], edx ;
mov [eax*4+edi-24], edx ;
mov [eax*4+edi-28], edx ;
mov [eax*4+edi-32], edx ;
mov [eax*4+edi-36], edx ;
mov [eax*4+edi-40], edx ;
mov [eax*4+edi-44], edx ;
mov [eax*4+edi-48], edx ;
mov [eax*4+edi-52], edx ;
mov [eax*4+edi-56], edx ;
mov [eax*4+edi-60], edx ;
mov [eax*4+edi-64], edx ;
mov [eax*4+edi-68], edx ;
mov [eax*4+edi-72], edx ;
mov [eax*4+edi-76], edx ;
mov [eax*4+edi-80], edx ;
mov [eax*4+edi-84], edx ;
mov [eax*4+edi-88], edx ;
mov [eax*4+edi-92], edx ;
mov [eax*4+edi-96], edx ;
mov [eax*4+edi-100], edx ;
mov [eax*4+edi-104], edx ;
mov [eax*4+edi-108], edx ;
mov [eax*4+edi-112], edx ;
mov [eax*4+edi-116], edx ;
mov [eax*4+edi-120], edx ;
mov [eax*4+edi-124], edx ;
mov [eax*4+edi-128], edx ;
sub eax, 32 ;
jne MaxSkipLens ; loop while eax=0
SkipLens: ;
mov al, [ecx+ebx+1] ;u filling up with the real negative
offset of
inc ecx ;v every byte from the pSrchData,
starting from
mov [eax*4+edi], ecx ;u the last to the first, at the offset
in
jne SkipLens ;v skip_table equal to the ASCII code of
the
; byte, multiplied by 4
Search: ; the main searching loop-> FAST PART
mov al, [esi+ebp] ;u get a byte from pBuffer ->esi +ebp
mov ecx, edx ;v ecx=edx=
...

read more »

That code is cool, but I can't do anything with it
 
D

dave_mikesell

What's with all the ding dang Wiccans and magicians using C++ lately?
Can't you just conjure up a solution to your IT problems?
 
V

virtualadepts

What's with all the ding dang Wiccans and magicians using C++ lately?
Can't you just conjure up a solution to your IT problems?


My solution? I got one now. It is a new object oriented design
model. You see I take containers and all the work I do with them
happens inside of the class. So that frees up a lot of space in my
main function, and lets me forget about tired old functions. Take a
peek:

#include <utility>
#include <iostream>
#include <string>
#include <map>

using namespace std;


class Bookz : public map<string, string>
{

public:
Bookz() {
cout << "Welcome to the database. Enter information, and type 'end'
to stop."<< endl;
cout << "Name: ";
}
void add(string name, string number){
typedef pair <string, string> b_Pair;
insert( b_Pair(name, number) );
}
~Bookz(){}
void search_Name(string lookup_Num){
cout << find(lookup_Num) -> second << "." << endl;
}
};

int main( void ) {
Bookz keeper;

string s=;
string n=;


while (s!="end" || n!="end"){
cin >> s;
if(s=="end"){cout <<"Finished inputing data."<<endl<<endl;
break;}
cout<<"Number: ";
cin >> n;
if(n=="end"){cout <<"Finished inputing data."<<endl<<endl;
break;}
keeper.add(s,n);
cout <<"Name: ";
}

cout << "To search the database enter a name. 'quit' exits."<<endl;
while (s != "quit"){
cout<<"$ ";
cin >> s;
keeper.search_Name(s);
}

cout<<"Goodbye."<<endl;

return 0;
}
 
S

Siddhartha

Sounds like spec work to me. Unless you're PAYING ME, UP
FRONT...*shakes head*...I don't fuckin think so, kid. I don't work on
spec...EVER.

--

Onideus Mad Hatter
mhm ¹ x ¹http://www.backwater-productions.nethttp://www.backwater-productions.net/hatter-blog

Hatter Quotes
-------------
"You're only one of the best if you're striving to become one of the
best."

"I didn't make reality, Sunshine, I just verbally bitch slapped you
with it."

"I'm not a professional, I'm an artist."

"Your Usenet blinders are my best friend."

"Usenet Filters - Learn to shut yourself the **** up!"

"Drugs killed Jesus you know...oh wait, no, that was the Jews, my
bad."

"There are clingy things in the grass...burrs 'n such...mmmm..."

"The more I learn the more I'm killing my idols."

"Is it wrong to incur and then use the hate ridden, vengeful stupidity
of complete strangers in random Usenet froups to further my art?"

"Freedom is only a concept, like race it's merely a social construct
that doesn't really exist outside of your ability to convince others
of its relevancy."

"Next time slow up a lil, then maybe you won't jump the gun and start
creamin yer panties before it's time to pop the champagne proper."

"Reality is directly proportionate to how creative you are."

"People are pretty fucking high on themselves if they think that
they're just born with a soul. *snicker*...yeah, like they're just
givin em out for free."

"Quible, quible said the Hare. Quite a lot of quibling...everywhere.
So the Hare took a long stare and decided at best, to leave the rest,
to their merry little mess."

"There's a difference between 'bad' and 'so earth shatteringly
horrible it makes the angels scream in terror as they violently rip
their heads off, their blood spraying into the faces of a thousand
sweet innocent horrified children, who will forever have the terrible
images burned into their tiny little minds'."

"How sad that you're such a poor judge of style that you can't even
properly gauge the artistic worth of your own efforts."

"Those who record history are those who control history."

"I am the living embodiment of hell itself in all its tormentive rage,
endless suffering, unfathomable pain and unending horror...but you
don't get sent to me...I come for you."

"Ideally in a fight I'd want a BGM-109A with a W80 250 kiloton
tactical thermonuclear fusion based war head."

"Tell me, would you describe yourself more as a process or a
function?"

"Apparently this group has got the market cornered on stupid.
Intelligence is down 137 points across the board and the forecast
indicates an increase in Webtv users."

"Is my .sig delimiter broken? Really? You're sure? Awww,
gee...that's too bad...for YOU!" `, )

It does to me as well, but you don't have to blurt profanity because
of it.
 
P

Phlip

virtualadepts said:
This contest is open to everyone who knows C++.

In future, please don't cross-post to groups containing a higher ratio of
idiots than the C++ group, okay?
 
D

dave_mikesell

Tha ****...every time a Webbie pisses all over Usenet
with their ban happy, chatty board sense of banal, fuckwitted,
Christian conservative **** crying, child molesting, Jesus killing
stupidity, GOD RAPES A VIRGIN!

...now get the **** off Usenet you stupid bitch, before I say
something you'll REALLY regret. `, \

Can't imagine why you don't have more than a handful of clients.
You've got mad PR skillz.
 
G

GeekBoy

My solution? I got one now. It is a new object oriented design
model. You see I take containers and all the work I do with them
happens inside of the class. So that frees up a lot of space in my
main function, and lets me forget about tired old functions. Take a
peek:

#include <utility>
#include <iostream>
#include <string>
#include <map>

using namespace std;


class Bookz : public map<string, string>
{

public:
Bookz() {
cout << "Welcome to the database. Enter information, and type 'end'
to stop."<< endl;
cout << "Name: ";
}
void add(string name, string number){
typedef pair <string, string> b_Pair;
insert( b_Pair(name, number) );
}
~Bookz(){}
void search_Name(string lookup_Num){
cout << find(lookup_Num) -> second << "." << endl;
}
};

int main( void ) {

Uhmmm..how can you have main VOID, but yet it still returning a value,
though the value is 0?
 
J

James Kanze

[...]
Uhmmm..how can you have main VOID, but yet it still returning a value,
though the value is 0?

He doesn't have "void main()". "void main()" isn't legal C++,
and won't compile. He's using a C compatibility hack to specify
that main doesn't take any arguments. Not good style, except in
code which must be processed in both C and in C++, but legal.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,962
Messages
2,570,134
Members
46,692
Latest member
JenniferTi

Latest Threads

Top