/*
    ragmaan/search.h            (C) 2003 Raymond (zandbergen@home.nl)

    "ragmaan" is an anagram generator

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#ifndef	SEARCH_H
#define	SEARCH_H

#include "hash_func.h"
#include "ragmaan.h"

typedef struct SEARCH_STATE_S
  {

/* ----------------------------------------------------------------------*
   keeps a state between invocations of find_word_wl?
   * ---------------------------------------------------------------------- */

    const gchar *target;
    gint search_length;
    gint search_length_min;
    gint search_length_max;
    HASH2_KEY_T *keys;
    gint i, i_end;
    gint target_char_count[26];
    HASH2_KEY_T target_inv_hash2;

  }
SEARCH_STATE_T;

extern gint rm_str_real_len (const gchar *s);

/* ----------------------------------------------------------------------*
   returns # of 'isalnum' characters in s
   * ---------------------------------------------------------------------- */

extern void init_search (HASH_TABLE_T * ht, SEARCH_STATE_T * ss,
			 const gchar *target,
			 gint search_length_max, gint search_length_min,
			 void * pc);

extern void init_search_reverse (HASH_TABLE_T * ht, SEARCH_STATE_T * ss,
				 const gchar *target,
			       gint search_length_max, gint search_length_min,
				 void * pc);

/* ----------------------------------------------------------------------*
   fills a SEARCH_STATE_T variable with initial values to start a search 
   * ---------------------------------------------------------------------- */

extern gchar *find_word_wl (SEARCH_STATE_T * ss, HASH_TABLE_T * ht);
extern gchar *find_word_wl_reverse (SEARCH_STATE_T * ss, HASH_TABLE_T * ht);

/* ----------------------------------------------------------------------*
   returns the next anagram of 'target', needs a SEARCH_STATE_T * as
   initialised with init_search
   * ---------------------------------------------------------------------- */

#endif
