12.06.2015 Views

The Annoyance Filter.pdf - Fourmilab

The Annoyance Filter.pdf - Fourmilab

The Annoyance Filter.pdf - Fourmilab

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

§37 ANNOYANCE-FILTER FAST DICTIONARY 41<br />

37. Add a new word to the word vector. As this is a new word, we know that its forward link is<br />

fastDictionaryVoidLink . <strong>The</strong> balance of the fields are transcribed from the dictionaryWord we’re<br />

adding.<br />

〈 Add new word to word table 37 〉 ≡<br />

vector〈unsigned char〉::size type wl = words .size ( );<br />

words .resize (words .size ( ) + sizeof (u int32 t ) + sizeof (double) + sizeof<br />

(u int16 t ) + w ⃗ second .get ( ).length ( ));<br />

u int32 t vl = fastDictionaryVoidLink ;<br />

#ifdef OLDWAY<br />

memcpy (words .begin ( ) + wl , &vl , sizeof vl );<br />

#else<br />

Vmemcpy (words , wl , &vl , sizeof vl );<br />

#endif<br />

wl += sizeof vl ;<br />

double jp = w ⃗ second .getJunkProbability ( );<br />

#ifdef OLDWAY<br />

memcpy (words .begin ( ) + wl , &jp, sizeof jp);<br />

#else<br />

Vmemcpy (words , wl , &jp, sizeof jp);<br />

#endif<br />

wl += sizeof jp;<br />

u int16 t wlen = w ⃗ second .get ( ).length ( );<br />

#ifdef OLDWAY<br />

memcpy (words .begin ( ) + wl , &wlen , sizeof wlen );<br />

#else<br />

Vmemcpy (words , wl , &wlen , sizeof wlen );<br />

#endif<br />

wl += sizeof wlen ;<br />

#ifdef OLDWAY<br />

memcpy (words .begin ( ) + wl , w ⃗ second .get ( ).data ( ), wlen );<br />

#else<br />

Vmemcpy (words , wl , w ⃗ second .get ( ).data ( ), wlen );<br />

#endif<br />

This code is used in section 35.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!