C++ Contest Challenge



 DEVELOP > c-Plus-Plus > C++ Contest Challenge

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: ""
Date: 31 Mar 2007 12:44:45 PM
Object: 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-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;
}
.

User: ""

Title: Re: C++ Contest Challenge 01 Apr 2007 11:10:23 AM
Is this a c++ program ???
What is 'ssize_t'
.
User: "Phlip"

Title: Re: C++ Contest Challenge 01 Apr 2007 02:14:51 PM
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
.


User: "Onideus Mad Hatter"

Title: Re: C++ Contest Challenge 31 Mar 2007 02:23:03 PM
On 31 Mar 2007 10:44:45 -0700,
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 ***** 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!" `, )
.
User: "Siddhartha"

Title: Re: C++ Contest Challenge 31 Mar 2007 09:50:24 PM
On Mar 31, 3:23 pm, Onideus Mad Hatter <use...@backwater-
productions.net> wrote:

On 31 Mar 2007 10:44:45 -0700,

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 =B9 x =B9http://www.backwater-productions.nethttp://www.backwater-pro=

ductions.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 ***** 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.
.
User: "Onideus Mad Hatter"

Title: Re: C++ Contest Challenge 01 Apr 2007 12:24:31 AM
On 31 Mar 2007 19:50:24 -0700, "Siddhartha"
<siddharthagandhi211@gmail.com> wrote:

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

What the ***** 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 *****...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 ***** Usenet you stupid *****, 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 ***** 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!" `, )
.
User: ""

Title: Re: C++ Contest Challenge 01 Apr 2007 08:46:52 AM
On Apr 1, 1:24 am, Onideus Mad Hatter <use...@backwater-
productions.net> wrote:

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 ***** Usenet you stupid *****, before I say
something you'll REALLY regret. `, \

--

Onideus Mad Hatter
mhm =B9 x =B9http://www.backwater-productions.net

Can't imagine why you don't have more than a handful of clients.
You've got mad PR skillz.
.
User: "Onideus Mad Hatter"

Title: Re: C++ Contest Challenge 01 Apr 2007 01:57:56 PM
On 1 Apr 2007 06:46:52 -0700,
wrote:

On Apr 1, 1:24 am, Onideus Mad Hatter <use...@backwater-
productions.net> wrote:

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 ***** Usenet you stupid *****, 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 ***** 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!" `, )
.



User: "PerfectReign"

Title: Re: C++ Contest Challenge 01 Apr 2007 08:29:48 AM
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.net> wrote:

On 31 Mar 2007 10:44:45 -0700,

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
.


User: "PerfectReign"

Title: Re: C++ Contest Challenge 31 Mar 2007 01:54:51 PM
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,

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
.


User: ""

Title: Re: C++ Contest Challenge 31 Mar 2007 03:09:00 PM
On Mar 31, 1:44 pm,
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-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;
}
.
User: ""

Title: Re: C++ Contest Challenge 31 Mar 2007 03:16:49 PM
On Mar 31, 4:09 pm,
wrote:

On Mar 31, 1:44 pm,

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

Hehe, nevermind. I'm still installing a compiler. I see where I went
wrong with the algorithm. This won't even find a match.
.
User: "Onideus Mad Hatter"

Title: Re: C++ Contest Challenge 31 Mar 2007 04:28:30 PM
On 31 Mar 2007 13:16:49 -0700,
wrote:

On Mar 31, 4:09 pm,

wrote:

On Mar 31, 1:44 pm,

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


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 ***** 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!" `, )
.



User: "boson boss"

Title: Re: C++ Contest Challenge 31 Mar 2007 04:37:15 PM
On Mar 31, 7:44 pm,
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-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)-

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
.
User: ""

Title: Re: C++ Contest Challenge 31 Mar 2007 07:08:54 PM
On Mar 31, 5:37 pm, "boson boss" <junker...@gmail.com> wrote:

On Mar 31, 7:44 pm,

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-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 =3D nlen-offset-portion;
ssize_t ignore =3D 0;
if(virtual_begin < 0) { ignore =3D -virtual_begin; virtual_begin =

=3D

0; }


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


return
memcmp(needle + nlen - portion + ignore,
needle + virtual_begin,
portion - ignore) =3D=3D 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 <=3D 0 || !haystack || !needle) return NULL;


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


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


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


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


/* Search: */
for(hpos=3D0; hpos <=3D hlen-nlen; )
{
size_t npos=3Dnlen-1;
while(needle[npos] =3D=3D haystack[npos+hpos])
{
if(npos =3D=3D 0) return haystack + hpos;
--npos;
}
hpos +=3D 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 =3D lenBuffer ; ebp =3Dlength of the buffer
; ebx ->pSrchData ; ebx->pointer to data to be searched
for
; edx =3D lenSrchData ; edx=3Dlength 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 =3D length of data to be
searched for
jg Boyer_Moore ;
;... Brute Force Search ..........; for 4 digits or less only!
mov edi, [ebx] ; edi =3D 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 =3D need the bx word only
mov ecx, ebx ;
mov esi, edx ; esi=3Dedx =3D 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=3D -lenSrchData
mov ecx, edx ; ecx =3D edx =3D -lenSrchData
add ebp, edx ; sub lenSrchData from lenBuffer
mov eax, 256 ; eax =3D 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=3D0
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=3Dedx=3D
...

read more =BB

That code is cool, but I can't do anything with it
.
User: ""

Title: Re: C++ Contest Challenge 31 Mar 2007 07:32:32 PM
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?
.
User: ""

Title: Re: C++ Contest Challenge 31 Mar 2007 08:17:08 PM
On Mar 31, 8:32 pm,
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, 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;
}
.
User: "GeekBoy"

Title: Re: C++ Contest Challenge 01 Apr 2007 04:07:06 PM
<virtualadepts@gmail.com> wrote in message
news:1175390228.336375.324500@p77g2000hsh.googlegroups.com...

On Mar 31, 8:32 pm,

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, 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?

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


.
User: "James Kanze"

Title: Re: C++ Contest Challenge 02 Apr 2007 02:45:34 AM
On Apr 1, 11:07 pm, "GeekBoy" <n...@nerdy.com> wrote:

<virtualade...@gmail.com> wrote in message
news:1175390228.336375.324500@p77g2000hsh.googlegroups.com...

On Mar 31, 8:32 pm,

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:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34
.






User: "Phlip"

Title: Re: C++ Contest Challenge 01 Apr 2007 12:20:21 AM
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
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER