Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
closed.h File Reference
#include <math.h>
#include "states.h"

Go to the source code of this file.

Macros

#define NO_STATE   ~0
 
#define free_hash_table(table)   memfree(table)
 

Typedefs

typedef STATEHASH_TABLE
 

Functions

int hash_add (HASH_TABLE state_table, STATE *state)
 
int hash_lookup (HASH_TABLE state_table, STATE *state)
 
HASH_TABLE new_hash_table ()
 

Macro Definition Documentation

#define free_hash_table (   table)    memfree(table)

Definition at line 35 of file closed.h.

#define NO_STATE   ~0

Definition at line 33 of file closed.h.

Typedef Documentation

typedef STATE* HASH_TABLE

Definition at line 32 of file closed.h.

Function Documentation

int hash_add ( HASH_TABLE  state_table,
STATE state 
)

Definition at line 50 of file closed.cpp.

50  {
51  int x;
52  int i = 0;
53  int table_limit = TABLE_SIZE;
54 
55  x = state->part2 % table_limit;
56  while (i < table_limit) {
57  assert (0 <= x && x < table_limit);
58  /* Found it */
59  if ((state_table[x].part2 == state->part2) &&
60  (state_table[x].part1 == state->part1)) {
61  return (FALSE);
62  }
63  /* Not in table */
64  else if (state_table[x].part1 == NO_STATE) {
65  state_table[x].part2 = state->part2;
66  state_table[x].part1 = state->part1;
67  return (TRUE);
68  }
69  i++;
70  if (++x >= table_limit)
71  x = 0;
72  }
73  cprintf("warning: hash table is full");
74 
75  abort();
76  return 0;
77 }
#define NO_STATE
Definition: closed.h:33
uinT32 part1
Definition: states.h:41
#define FALSE
Definition: capi.h:28
uinT32 part2
Definition: states.h:42
void cprintf(const char *format,...)
Definition: callcpp.cpp:41
#define TRUE
Definition: capi.h:27
#define TABLE_SIZE
Definition: closed.cpp:39
int hash_lookup ( HASH_TABLE  state_table,
STATE state 
)

Definition at line 86 of file closed.cpp.

86  {
87  int x;
88  int i = 0;
89  int table_limit = TABLE_SIZE;
90 
91  x = state->part2 % table_limit;
92  while (i < table_limit) {
93  assert (0 <= x && x < table_limit);
94  /* Found it */
95  if ((state_table[x].part2 == state->part2) &&
96  (state_table[x].part1 == state->part1)) {
97  return (TRUE);
98  }
99  /* Not in table */
100  else if (state_table[x].part1 == NO_STATE) {
101  return (FALSE);
102  }
103 
104  i++;
105  if (++x >= table_limit)
106  x = 0;
107  }
108  cprintf ("warning: fell off end of hash table (%x) %x\n",
109  state->part2, state->part2 % table_limit);
110  abort();
111  return 0;
112 }
#define NO_STATE
Definition: closed.h:33
uinT32 part1
Definition: states.h:41
#define FALSE
Definition: capi.h:28
uinT32 part2
Definition: states.h:42
void cprintf(const char *format,...)
Definition: callcpp.cpp:41
#define TRUE
Definition: capi.h:27
#define TABLE_SIZE
Definition: closed.cpp:39
HASH_TABLE new_hash_table ( )

Definition at line 120 of file closed.cpp.

120  {
121  HASH_TABLE ht;
122  int x;
123 
124  ht = (HASH_TABLE) memalloc (TABLE_SIZE * sizeof (STATE));
125  for (x = 0; x < TABLE_SIZE; x++) {
126  ht[x].part1 = NO_STATE;
127  ht[x].part2 = NO_STATE;
128  }
129  return (ht);
130 }
STATE * HASH_TABLE
Definition: closed.h:32
int * memalloc(int size)
Definition: freelist.cpp:22
#define NO_STATE
Definition: closed.h:33
uinT32 part1
Definition: states.h:41
uinT32 part2
Definition: states.h:42
Definition: states.h:39
#define TABLE_SIZE
Definition: closed.cpp:39