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.

§15 ANNOYANCE-FILTER DICTIONARY WORD 23<br />

}<br />

}<br />

16. This method writes a binary representation of the word to an output stream. This is used to create<br />

the binary word database used to avoid rebuilding the letter and character category counts every time. Each<br />

entry begins with the number of characters in the word followed by its text. After this, the count and<br />

probability fields are output in portable big-endian format. We do assume IEEE floating point compatibility<br />

across platforms, but auto-detect floating point byte order.<br />

〈 Class implementations 11 〉 +≡<br />

void dictionaryWord ::exportToBinaryFile (ostream &os ){ unsigned char c;<br />

const unsigned char ∗fp;<br />

const double k1 = −1.0;<br />

#define outCount (x)c = (x); os .put (c)<br />

#define outNumber (x)os .put ((x ≫ 24) & # FF);<br />

os .put ((x ≫ 16) & # FF);<br />

os .put ((x ≫ 8) & # FF); os .put (x & # FF)<br />

outCount (text .length ( ));<br />

os .write (text .data ( ), text .length ( ));<br />

outNumber (n mail ( ));<br />

outNumber (n junk ( ));<br />

fp = reinterpret cast〈const unsigned char ∗〉(&k1 );<br />

if (fp[0] ≡ 0) {<br />

fp = reinterpret cast〈unsigned char ∗〉(&junkProbability );<br />

for (unsigned int i = 0; i < (sizeof junkProbability ); i++) {<br />

outCount (fp[((sizeof junkProbability ) − 1) − i]);<br />

}<br />

}<br />

else { /∗ Big-endian platform ∗/<br />

os .write (reinterpret cast〈const char ∗〉(&junkProbability ), sizeof junkProbability );<br />

}<br />

#undef outCount<br />

#undef outNumber<br />

}

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

Saved successfully!

Ooh no, something went wrong!