findall.h

00001 /* File:      findall.h
00002 ** Author(s): Bart Demoen, (mod dsw oct 99)
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: findall.h,v 1.5 2005/07/06 18:29:13 dwarren Exp $
00023 ** 
00024 */
00025 
00026 #ifndef __FINDALL_H__
00027 
00028 #define __FINDALL_H__
00029 
00030 /* Findall copies its templates to a findall-heap.  This heap is allocated in
00031    chunks of FINDALL_CHUNCK_SIZE (Cell)entries.  Since more than one findall
00032    can be active at the same time, each findall gets a number, determined by
00033    the global variables nextfree; this happens in findall_init. The maximal
00034    number of active findalls is MAX_FINDALLS.
00035 
00036    A solution list of findall is represented by its size and a pointer to the
00037    beginning of the solution list and a pointer to the tail of this solution
00038    list.  The size is important for copying back to the heap, to ensure that
00039    there is enough space, before we start copying.  The tail is a free
00040    variable.
00041 
00042    One solution list or template can be in more than one chunk. Chuncks are
00043    linked together by the first field in the chunk; this field is only needed
00044    for the deallocation of the chunks, not for the copying itself.
00045 
00046    Trailing of variables (to ensure proper sharing) is done on a special
00047    purpose trail, which consists also of chuncks, linked together.
00048 
00049    Everything is allocated dynamically, and freed asap.
00050 
00051    findall_clean should be called at the start of every toplevel.  */
00052 
00053 #define FINDALL_CHUNCK_SIZE 4000 /* anything > MAX_ARITY+2 is good */
00054 
00055 /* one invocation of findall is associated with one entry in the
00056    findall_solutions array: we then call this entry active; the type of the
00057    entry is findall_solution_list */
00058 
00059 #define F_TR_NUM 250 /* the number of trail entries in a chunck of the trail
00060                         it must be a multiple of 2
00061                      */
00062 
00063 typedef struct f_tr_chunk {
00064   struct f_tr_chunk *previous ;
00065   CPtr tr[F_TR_NUM] ;
00066 } f_tr_chunk ;
00067 
00068 typedef struct {
00069   CPtr  first_chunk ;    /* chunk in which solution list starts
00070                             the solution list starts at offset +1 */
00071   CPtr   tail ;          /* tail of solution list - always a free var */
00072   CPtr   current_chunk ; /* most recent alloc chunk for this solution list */
00073   CPtr   top_of_chunk ;  /* where next template can be copied to 
00074                             points inside current_chunk */
00075   int size ;             /* size is the size of the solution list - init = 1
00076                             when entry not active, size = the next free entry 
00077                             the last free entry, has size = -1, for overflow
00078                             checking */ 
00079 } findall_solution_list ;
00080 
00081 #ifndef MULTI_THREAD
00082 extern findall_solution_list *findall_solutions, *current_findall ;
00083 
00084 extern CPtr gl_bot, gl_top ;
00085 #endif
00086 
00087 #endif /* __FINDALL_H__ */

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