/*
 *  smoke16/include/hashtbl.h - Header file for smoke16/hashtbl.c.
 *  $Revision: 1.15 $
 *  Copyright 1997, Benjamin Sittler
 *
 *  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.
 *
 */

#ifndef SMOKE16__HASHTBL_H_INCLUDED
#define SMOKE16__HASHTBL_H_INCLUDED

/* #define DEBUG_SEARCH */

#include <smoke16/a_out.h>

struct Node {
   struct Node *next;
   char *word;
   u16 index;
   struct a_out16_nlist nlist;
   int sect;
   int refcnt;
};

extern int wordhash( struct Node  *);

extern int wordcompare( struct Node  *, struct Node  *);

extern struct Node  *lookup(
      struct Node  **,              	/* hash table */
      struct Node  *,		/* node to look up */
      int (*hash)(struct Node  *),	/* hash function */
      int (*compare)(                   /* comparison function */
	    struct Node  *,
	    struct Node  *) );

extern struct Node  *enter(
      struct Node  **,    		/* hash table */
      struct Node  *,     		/* new node to insert */
      int (*hash)(struct Node  *) );	/* hash function */

struct SearchContext {
  struct Node **table; /* hash table */
  int bucket; /* initialize to -1 */
  struct Node *node; /* initialize to 0 */
  int (*criterion)(struct Node *); /* returns nonzero if node meets search criteria. */
};

/* start a search using the given criterion - returns first match, or 0 if done */
extern struct Node *start_search(struct Node **, /* hash table */
			 struct SearchContext *, /* an uninitialized search context */
			 int (*)(struct Node *) ); /* a criterion function which returns nonzero if the node matches */

/* find the next matching node, or return 0 if done */
extern struct Node *next_node(struct SearchContext *); /* search context */

extern int any_node(struct Node *); /* returns 1 -- useful as a criterion function */
extern int extern_node(struct Node *); /* returns 1 for symbols with non-zero refcount,
					  and for external symbols */
extern int common_node(struct Node *); /* returns 1 for common symbols (.comm/.lcomm) */

#endif SMOKE16__HASHTBL_H_INCLUDED
