473,387 Members | 1,300 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

C++ Contest Challenge

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-M...arch_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;
}

Mar 31 '07 #1
19 2350
On 31 Mar 2007 10:44:45 -0700, vi***********@gmail.com wrote:
>This contest is open to everyone who knows C++. To enter all you need
to do<snip>
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.net
http://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 fuck 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!" `, )
Mar 31 '07 #2
On Sat, 31 Mar 2007 11:23:03 -0800, a rock fell the sky, hitting Onideus
Mad Hatter on the head, and inspiring the following:
On 31 Mar 2007 10:44:45 -0700, vi***********@gmail.com wrote:
>>This contest is open to everyone who knows C++. To enter all you need
to do<snip>

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.
LOL!
--
k
Mar 31 '07 #3
On Mar 31, 1:44 pm, virtualade...@gmail.com wrote:
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-M...arch_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;
}

Mar 31 '07 #4
On Mar 31, 4:09 pm, virtualade...@gmail.com wrote:
On Mar 31, 1:44 pm, virtualade...@gmail.com wrote:
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-M...arch_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;
}
Hehe, nevermind. I'm still installing a compiler. I see where I went
wrong with the algorithm. This won't even find a match.

Mar 31 '07 #5
On 31 Mar 2007 13:16:49 -0700, vi***********@gmail.com wrote:
>On Mar 31, 4:09 pm, virtualade...@gmail.com wrote:
>On Mar 31, 1:44 pm, virtualade...@gmail.com wrote:
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-M...arch_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;
}

Hehe, nevermind. I'm still installing a compiler. I see where I went
wrong with the algorithm. This won't even find a match.
Good luck with your homework assignment, Kiddo.

--

Onideus Mad Hatter
mhm ¹ x ¹
http://www.backwater-productions.net
http://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 fuck 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!" `, )
Mar 31 '07 #6
On Mar 31, 7:44 pm, virtualade...@gmail.com wrote:
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-M...arch_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
; <c2001 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)-
>SLOW
; 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

Mar 31 '07 #7
On Mar 31, 5:37 pm, "boson boss" <junker...@gmail.comwrote:
On Mar 31, 7:44 pm, virtualade...@gmail.com wrote:
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-M...arch_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
; <c2001 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

Apr 1 '07 #8
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?

Apr 1 '07 #9
On Mar 31, 8:32 pm, dave_mikes...@fastmail.fm wrote:
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, stringb_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;
}
Apr 1 '07 #10
On Mar 31, 3:23 pm, Onideus Mad Hatter <use...@backwater-
productions.netwrote:
On 31 Mar 2007 10:44:45 -0700, virtualade...@gmail.com wrote:
This contest is open to everyone who knows C++. To enter all you need
to do<snip>

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.net...et/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 fuck 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.

Apr 1 '07 #11
On 31 Mar 2007 19:50:24 -0700, "Siddhartha"
<si*****************@gmail.comwrote:
>It does to me as well, but you don't have to blurt profanity because
of it.
What the shit is "profanity"? What are you some fucked up Google
froups (L)user who got lost or something? What did you lose your
Usenet map? Tha fuck...every time a Webbie pisses all over Usenet
with their ban happy, chatty board sense of banal, fuckwitted,
Christian conservative cunt crying, child molesting, Jesus killing
stupidity, GOD RAPES A VIRGIN!

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

--

Onideus Mad Hatter
mhm ¹ x ¹
http://www.backwater-productions.net
http://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 fuck 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!" `, )
Apr 1 '07 #12
virtualadepts wrote:
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?

--
Phlip
http://flea.sourceforge.net/PiglegToo_1.html
Apr 1 '07 #13
On Sat, 31 Mar 2007 19:50:24 -0700, a rock fell the sky, hitting
Siddhartha on the head, and inspiring the following:
On Mar 31, 3:23 pm, Onideus Mad Hatter <use...@backwater-
productions.netwrote:
>On 31 Mar 2007 10:44:45 -0700, virtualade...@gmail.com wrote:
>This contest is open to everyone who knows C++. To enter all you need
to do<snip>

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.

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

He does.

--
k
Apr 1 '07 #14
On Apr 1, 1:24 am, Onideus Mad Hatter <use...@backwater-
productions.netwrote:
Tha fuck...every time a Webbie pisses all over Usenet
with their ban happy, chatty board sense of banal, fuckwitted,
Christian conservative cunt crying, child molesting, Jesus killing
stupidity, GOD RAPES A VIRGIN!

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

--

Onideus Mad Hatter
mhm ¹ x ¹http://www.backwater-productions.net
Can't imagine why you don't have more than a handful of clients.
You've got mad PR skillz.

Apr 1 '07 #15
Is this a c++ program ???
What is 'ssize_t'

Apr 1 '07 #16
On 1 Apr 2007 06:46:52 -0700, da***********@fastmail.fm wrote:
>On Apr 1, 1:24 am, Onideus Mad Hatter <use...@backwater-
productions.netwrote:
>Tha fuck...every time a Webbie pisses all over Usenet
with their ban happy, chatty board sense of banal, fuckwitted,
Christian conservative cunt crying, child molesting, Jesus killing
stupidity, GOD RAPES A VIRGIN!

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

--

Onideus Mad Hatter
mhm ¹ x ¹http://www.backwater-productions.net
>Can't imagine why you don't have more than a handful of clients.
Probably has something to do with the fact that I have near zero
advertising and turn down a lot of clients if I'm not particularly
interested in whatever it is they want made (I'm quite picky).
Although if it's a friend or someone I know I usually say yes (which
is why most of those client sites even exist).
>You've got mad PR skillz.
Pffft, Sunshine, I'm an ARTIST, not a fuckin public relations manager.

--

Onideus Mad Hatter
mhm ¹ x ¹
http://www.backwater-productions.net
http://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 fuck 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!" `, )
Apr 1 '07 #17
yongkang.he wrote:
Is this a c++ program ???
What is 'ssize_t'
It'z a Cz++ program; a sspecial dialect invented for ssoftware engineerz
with a lithp.

--
Phlip
http://flea.sourceforge.net/PiglegToo_1.html
Apr 1 '07 #18

<vi***********@gmail.comwrote in message
news:11**********************@p77g2000hsh.googlegr oups.com...
On Mar 31, 8:32 pm, dave_mikes...@fastmail.fm wrote:
>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, stringb_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?

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;
}


Apr 1 '07 #19
On Apr 1, 11:07 pm, "GeekBoy" <n...@nerdy.comwrote:
<virtualade...@gmail.comwrote in message
news:11**********************@p77g2000hsh.googlegr oups.com...
On Mar 31, 8:32 pm, dave_mikes...@fastmail.fm wrote:
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?
[...]
int main( void ) {

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.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Apr 2 '07 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Matt Wade | last post by:
A new PHP Coding Contest has been released at Codewalkers.com. The latest challenge is to play a variation of the Numbers Game as seen on the UK television show Countdown. Basically, you are...
4
by: hicinbothem | last post by:
GLOSSY: The Summer Programmer Of The Month Contest is underway! Deadline is September 30, 2005 http://dinsights.com/POTM...
0
by: hicinbothem | last post by:
GLOSSY: The Summer Programmer Of The Month Contest is underway! Deadline is September 30, 2005 http://dinsights.com/POTM...
2
by: Xcott Craver | last post by:
See here for the inaugural Underhanded C contest: http://www.brainhz.com/underhanded/ The object is to write clear, readable, innocent-looking C code that nevertheless does something...
23
by: Simon Hengel | last post by:
Hello, we are hosting a python coding contest an we even managed to provide a price for the winner... http://pycontest.net/ The contest is coincidentally held during the 22c3 and we will be...
13
by: Xcott Craver | last post by:
The second Underhanded C contest just opened today, and will run until July 4th. The Prize is a ThinkGeek gift certificate. The object is to write deceptive C code, code that does something...
4
by: Nick Halstead | last post by:
Want to test your PHP programming skills? I have just launched a PHP programming contest on my blog. The problem Many years ago there used to be a UK television quiz show (I am sure there has...
0
by: Biswajyoti Pal | last post by:
IIT Kharagpur KSHITIJ 2009 THE ANNUAL TECHNO-MANAGEMENT FEST 29th Jan- 1st Feb THE OVERNITE ACM ICPC 2009 MULTI PROVINCIAL PROGRAMMING CONTEST ( http://overnite.ktj.in )
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.