wordrec/tally.h

Go to the documentation of this file.
00001 
00020 #ifndef TALLY_H
00021 #define TALLY_H
00022 
00023 /*----------------------------------------------------------------------
00024               I n c l u d e s
00025 ----------------------------------------------------------------------*/
00026 #include <stdio.h>
00027 
00028 /*----------------------------------------------------------------------
00029               T y p e s
00030 ----------------------------------------------------------------------*/
00039 typedef struct _TALLY_
00040 {
00041   int count;
00042   int num_buckets;
00043   int buckets[1];
00044 } *TALLY;
00045 
00046 /*----------------------------------------------------------------------
00047               M a c r o s
00048 ----------------------------------------------------------------------*/
00049 /* ================== */
00053 #define inc_tally_bucket(t,i) \
00054 (t->count++,                \
00055    ((i < t->num_buckets) ?    \
00056    (t->buckets[i]++) :       \
00057    (t->buckets[t->num_buckets-1]++)))
00058 
00059 /* ================== */
00063 #define iterate_tally(t,i)  \
00064 for (i=0; i<t->num_buckets; i++)
00065 
00066 /* ================== */
00070 #define tally_entry(t,i)            \
00071 (t->buckets[i])
00072 
00073 /* ==================
00074  * tally_value
00075  *
00076  * Access one of the buckets of a tally record with bounds checking.
00077  **********************************************************************
00078 
00079 #define tally_value(t,i)            \
00080 ((i>=0 && i<t->num_buckets) ?     \
00081   (tally_entry (t,i))   :          \
00082   (cprintf ("error: tried to access non-existant bucket %d\n", i)))
00083 */
00084 
00085 /*----------------------------------------------------------------------
00086               F u n c t i o n s
00087 ----------------------------------------------------------------------*/
00088 TALLY new_tally(int num_buckets); 
00089 
00090 void print_tally(FILE *file, const char *string, TALLY t); 
00091 #endif

Generated on Wed Feb 28 19:49:13 2007 for Tesseract by  doxygen 1.5.1