Tesseract  3.02
tesseract-ocr/wordrec/closed.h File Reference
#include <math.h>
#include "states.h"

Go to the source code of this file.

Defines

#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 ()

Define 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.

                                                   {
  int x;
  int i = 0;
  int table_limit = TABLE_SIZE;

  x = state->part2 % table_limit;
  while (i < table_limit) {
    assert (0 <= x && x < table_limit);
    /* Found it */
    if ((state_table[x].part2 == state->part2) &&
    (state_table[x].part1 == state->part1)) {
      return (FALSE);
    }
    /* Not in table */
    else if (state_table[x].part1 == NO_STATE) {
      state_table[x].part2 = state->part2;
      state_table[x].part1 = state->part1;
      return (TRUE);
    }
    i++;
    if (++x >= table_limit)
      x = 0;
  }
  cprintf("warning: hash table is full");

  abort();
  return 0;
}
int hash_lookup ( HASH_TABLE  state_table,
STATE state 
)

Definition at line 86 of file closed.cpp.

                                                      {
  int x;
  int i = 0;
  int table_limit = TABLE_SIZE;

  x = state->part2 % table_limit;
  while (i < table_limit) {
    assert (0 <= x && x < table_limit);
    /* Found it */
    if ((state_table[x].part2 == state->part2) &&
    (state_table[x].part1 == state->part1)) {
      return (TRUE);
    }
    /* Not in table */
    else if (state_table[x].part1 == NO_STATE) {
      return (FALSE);
    }

    i++;
    if (++x >= table_limit)
      x = 0;
  }
  cprintf ("warning: fell off end of hash table  (%x) %x\n",
    state->part2, state->part2 % table_limit);
  abort();
  return 0;
}
HASH_TABLE new_hash_table ( )

Definition at line 120 of file closed.cpp.

                            {
  HASH_TABLE ht;
  int x;

  ht = (HASH_TABLE) memalloc (TABLE_SIZE * sizeof (STATE));
  for (x = 0; x < TABLE_SIZE; x++) {
    ht[x].part1 = NO_STATE;
    ht[x].part2 = NO_STATE;
  }
  return (ht);
}