    <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/">
     <channel>
        <title>ACCU  :: The Wall</title>
        <link>https://members.accu.org/index.php/articles/1010</link>
        <description>Professionalism in Programming</description>
        <dc:language>en-us</dc:language> 
        <dc:creator>Administrator</dc:creator> 
        <admin:generatorAgent rdf:resource="http://www.xaraya.org" /> 
        <admin:errorReportsTo rdf:resource="mailto:webeditor@accu.org" />
       <sy:updatePeriod>hourly</sy:updatePeriod>
       <sy:updateFrequency>1</sy:updateFrequency>
       <docs>http://backend.userland.com/rss</docs>




<div class="xar-mod-head"><span class="xar-mod-title">Letters to the Editor + CVu Journal Vol 12, #3 - May 2000</span></div>

<table border="0" cellpadding="1" cellspacing="0">
    <tbody>
    <tr>
        <td valign="top">
            Browse in :
       </td>
       <td valign="top">

                                            <a href="https://members.accu.org/index.php/articles/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c184/">Journal Columns</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c186/">LettersEditor</a>
<br />

                                            <a href="https://members.accu.org/index.php/articles/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c76/">Journals</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c77/">CVu</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c126/">123</a>
<br />

                                            <a href="https://members.accu.org/index.php/articles/c186-126/">Any of these categories</a>

                    -                        <a href="https://members.accu.org/index.php/articles/c186+126/">All of these categories</a>
<br />
</td>
   </tr>
   </tbody>
</table>




<div class="xar-error">
   <p>
 <strong>Note:</strong> when you create a new publication type,
the articles module will automatically use the templates
<em>user-display-[publicationtype].xt</em>
and <em>user-summary-[publicationtype].xt</em>.
If those templates do not exist when you try to preview or display a new article,
you'll get this warning :-)  Please place your own templates in themes/<em>yourtheme</em>/modules/articles . The templates will get the extension .xt there. </p>
</div>
<div class="xar-norm xar-standard-box-padding">
   <h1><strong>Title:</strong>&nbsp;The Wall</h1>
<p><strong>Author:</strong>&nbsp;</p>
<p>
<strong>Date:</strong> 08 May 2000 13:15:36 +01:00 or Mon, 08 May 2000 13:15:36 +01:00</p>
<p><strong>Summary:</strong>&nbsp;</p>
<p><strong>Body:</strong>&nbsp;<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e22" id="d0e22"></a>eliminate in
one</h2>
</div>
<p>Dear Francis,</p>
<p>Since you asked for an implementation of the <tt class=
"function">eliminate</tt> function which used neither <tt class=
"literal">break</tt> nor a function, I thought I would try my hand
at my first letter to ACCU. I initially sketched this out on the
train, but lost the piece of paper in dashing for a connection.</p>
<p>The obvious efficient implementation of this function was
suggested by Pete Disdale, using a 256-element array, building it
up.</p>
<p>I chose to use 32-bit words rather than bytes so that I could
erase the <tt class="varname">discard</tt> array easily using the
initialiser. With memory so cheap, it would have been quicker to
just allocate 256 bytes of memory and use the <tt class=
"type">char</tt> as a location in that array. I chose to be space
efficient and use a mask and shift method to get the word and bit
indices.</p>
<p>I also used <tt class="type">unsigned char</tt> internally to
allow the function to cope with any extended ASCII characters it
may be given. To make this code really portable, I should be
generating the constants (i.e. <tt class=
"constant">num_elements</tt>, <tt class="constant">index_shift</tt>
and <tt class="constant">mask_bits</tt>) according to <tt class=
"literal">sizeof (unsigned long)</tt> but I could not think of a
way to generate the latter two at compile time.</p>
<p>As is so often the case, the code to test the function to my
satisfaction ended up being larger than the code I was writing.</p>
<pre class="programlisting">
/* ACCU_eliminate.cpp
   Function to eliminate characters within one string from another string, returning a pointer to the eliminated string. Note that this is a destructive function, i.e. it destroys the source string in generating the result.
   Also included is my rough and ready tests, these test the obvious boundary conditions of the parts of the function. Also tested is the high bit handling.
*/
#include &quot;stdafx.h&quot;
char * eliminate(const char these[],
                 char from[]);
void testme(const char these[], 
              char from[]);
int main(){
  char teststring1[] = 
    &quot;This test removes all vowels and spaces.&quot;;
  char removeme1[] = &quot;aeiou &quot;;
  char teststring2[] = 
          &quot;This test removes all of self.&quot;;
  char teststring3[] =
             &quot;This test removes nothing.&quot;;
  char teststring4[] = 
     &quot;This test removes the first character.&quot;;
  char removeme4[] = &quot;T&quot;;
  char teststring5[] = 
      &quot;This test removes the last character.&quot;;
  char removeme5[] = &quot;.&quot;;
  unsigned char teststringA[] = { 0x01, 0x1f,   
    0x20, 0x44, 0x80, 0x81, 0xc0, 0xff, 0x00};
  unsigned char removemeA[] = { 0x01, 0x1f, 
          0x44, 0x80, 0x81, 0xff, 0x00};
  unsigned char teststringB[] = { 0x01, 0x1f, 
    0x20, 0x44, 0x80, 0x81, 0xc0, 0xff ,0x00};
  testme(removeme1, teststring1);
  testme(teststring2, teststring2);
  testme(&quot;&quot;, teststring3);
  testme(removeme4, teststring4);
  testme(removeme5, teststring5);
  testme((char*)removemeA, (char*)teststringA);
  testme((char*)teststringB, (char*)teststringB);
  return 0;
}
void testme(char const *these, char *from) {
  char *teststring;
  printf(&quot;eliminate \&quot;%s\&quot; from \&quot;%s\&quot;\n&quot;,
                 these, from);
  teststring = eliminate(these, from);
  printf(&quot; = \&quot;%s\&quot;\n&quot;, teststring);
}
char *eliminate(char const *these, char *from) {
  unsigned char *src, *dst;
/* Assume a 32-bit minimum size unsigned long */
  int const num_elements = 8; /* 256 / 32 = 8 */
  unsigned long discard[num_elements] = {0};
  int const index_shift = 5; /* 2^5 = 32 *8 */
  int const mask_bits = 0x1F;
  int i;
/* Bits 0-4 index into word, 5-7 into array. */
/* Set up discard */
  for (src=(unsigned char*)these; *src; src++){
/* Add char to discard. Find the word */
    i = (*src) &gt;&gt; index_shift;
/* and set the correct bit */
    discard[i] = discard[i] | 
            1 &lt;&lt; (*src &amp; mask_bits);
  }  
/* Do eliminate */
  dst=src=(unsigned char *)from;
  while (*dst = *src++) {
/* Find the discard word */
    i = (*dst) &gt;&gt; index_shift;
/* and test for the correct bit */
    if (!(discard[i] &amp; 
        1 &lt;&lt; (*dst &amp; mask_bits))) dst++;
    }
  }
  return from;
}
</pre>
<p class="c3"><span class="remark">Thanks. I made a few changes in
the code that have no effect on the results. I changed your
declarations to meet the house style where cv-qualification is to
the right of the thing qualified. I simplified your initialosation
of <tt class="varname">discard</tt>.</span></p>
</div>
</p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
