/*
   "search.h" - part of "RAGMAAN, een anagrammengenerator" 

   Copyright (C) 1999 Raymond Zandbergen

   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., 675 Mass Ave, Cambridge, MA 02139, USA.

   The maintainer of this program is Raymond Zandbergen (ray@wirehub.nl)
 */

#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 char *target;
    int search_length;
    int search_length_min;
    int search_length_max;
    HASH2_KEY_T *keys;
    int i, i_end;
    int target_char_count[26];
    HASH2_KEY_T target_inv_hash2;
    progress_callback_t *pc;

  }
SEARCH_STATE_T;

extern int rm_str_real_len (const char *s);

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

extern void init_search (HASH_TABLE_T * ht, SEARCH_STATE_T * ss,
			 const char *target,
			 int search_length_max, int search_length_min,
			 progress_callback_t pc);

extern void init_search_reverse (HASH_TABLE_T * ht, SEARCH_STATE_T * ss,
				 const char *target,
			       int search_length_max, int search_length_min,
				 progress_callback_t pc);

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

extern char *expand_result (HASH_TABLE_T * ht, char *target,
			    char *anagram, char *c, char *rest);

/* ----------------------------------------------------------------------*
   expands an 'anagram' of 'target' : fills c with a character

   ! indicating 'anagram' is a full anagram of 'target'
   + there is a remainder 'rest' that has anagrams
   X there is a remainder 'rest' that has no anagrams
   * ---------------------------------------------------------------------- */

extern char *find_word_wl (SEARCH_STATE_T * ss, HASH_TABLE_T * ht);
extern char *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
   * ---------------------------------------------------------------------- */

extern char *find_word_wl2 (SEARCH_STATE_T * ss, HASH_TABLE_T * ht,
			    char *c, char *rest);

/* ----------------------------------------------------------------------*
   a combination of find_word_wl and expand_result
   * ---------------------------------------------------------------------- */

#endif
