hash_xsb.h

00001 /* File:      hash_xsb.h
00002 ** Author(s): Ernie Johnson
00003 ** Contact:   xsb-contact@cs.sunysb.edu
00004 ** 
00005 ** Copyright (C) The Research Foundation of SUNY, 1986, 1993-1998
00006 ** Copyright (C) ECRC, Germany, 1990
00007 ** 
00008 ** XSB is free software; you can redistribute it and/or modify it under the
00009 ** terms of the GNU Library General Public License as published by the Free
00010 ** Software Foundation; either version 2 of the License, or (at your option)
00011 ** any later version.
00012 ** 
00013 ** XSB is distributed in the hope that it will be useful, but WITHOUT ANY
00014 ** WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00015 ** FOR A PARTICULAR PURPOSE.  See the GNU Library General Public License for
00016 ** more details.
00017 ** 
00018 ** You should have received a copy of the GNU Library General Public License
00019 ** along with XSB; if not, write to the Free Software Foundation,
00020 ** Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00021 **
00022 ** $Id: hash_xsb.h,v 1.3 2005/01/14 18:31:16 ruim Exp $
00023 ** 
00024 */
00025 
00026 
00027 /*
00028  *  Structure of a dynamic hash table for dynamic objects.
00029  */
00030 
00031 typedef struct hash_table {
00032   unsigned long size;
00033   unsigned long contains;
00034   void **table;
00035 } Hash_Table;
00036 
00037 
00038 /*
00039  *  Non-numerical objects are stored in these dynamic hash tables.
00040  */
00041 
00042 extern Hash_Table symbol_table;
00043 extern Hash_Table string_table;
00044 
00045 
00046 /*
00047  *  Macros for hash table overflow checks.
00048  */
00049 
00050 #ifndef DEBUG_ASSERTIONS
00051 #define string_table_increment_and_check_for_overflow               \
00052   {                                                                 \
00053     string_table.contains++;                                        \
00054     if (string_table.contains > (string_table.size << 2))           \
00055       expand_string_table();                                        \
00056   }
00057 
00058 #define symbol_table_increment_and_check_for_overflow               \
00059   {                                                                 \
00060     symbol_table.contains++;                                        \
00061     if (symbol_table.contains > (symbol_table.size << 2))           \
00062       expand_symbol_table();                                        \
00063   }
00064 
00065 #else
00066 
00067 #define string_table_increment_and_check_for_overflow               \
00068   {                                                                 \
00069     string_table.contains++;                                        \
00070     if (string_table.contains > (string_table.size << 2)) {         \
00071       printf("\nBEFORE:\n");                                        \
00072       string_table_stats();                                         \
00073       expand_string_table();                                        \
00074       printf("\nAFTER:\n");                                         \
00075       string_table_stats();                                         \
00076     }                                                               \
00077   }
00078 
00079 #define symbol_table_increment_and_check_for_overflow               \
00080   {                                                                 \
00081     symbol_table.contains++;                                        \
00082     if (symbol_table.contains > (symbol_table.size << 2)) {         \
00083       printf("\nBEFORE:\n");                                        \
00084       symbol_table_stats();                                         \
00085       expand_symbol_table();                                        \
00086       printf("\nAFTER:\n");                                         \
00087       symbol_table_stats();                                         \
00088     }                                                               \
00089   }
00090 #endif
00091 
00092 
00093 /*
00094  *  Function prototypes for dynamic hash table use.
00095  */
00096 
00097 unsigned long  next_prime(unsigned long  some_integer);
00098 unsigned long  hash(char *atom_name, byte arity, word hash_table_size);
00099 void  expand_symbol_table();
00100 void  expand_string_table();
00101 void  symbol_table_stats();
00102 void  string_table_stats();

Generated on Wed Jul 26 13:30:41 2006 for XSB by  doxygen 1.4.5