X-Git-Url: http://git.indexdata.com/?p=idzebra-moved-to-github.git;a=blobdiff_plain;f=rset%2Frset.c;h=d4122c46a3d49bd4942c6cc6290dd74162e4f72d;hp=5050a1d13af79e06be349e4e0df846bcc65fc68a;hb=726c42c6ae793b79a5351d2fce805d220d21321e;hpb=5c7ad71f534d092eaf97f04dd39c5e874e0d45b0 diff --git a/rset/rset.c b/rset/rset.c index 5050a1d..d4122c4 100644 --- a/rset/rset.c +++ b/rset/rset.c @@ -1,53 +1,149 @@ -/* - * Copyright (C) 1994-1995, Index Data I/S - * All rights reserved. - * Sebastian Hammer, Adam Dickmeiss - * - * $Log: rset.c,v $ - * Revision 1.7 1995-10-12 12:41:56 adam - * Private info (buf) moved from struct rset_control to struct rset. - * Bug fixes in relevance. - * - * Revision 1.6 1995/09/08 14:52:41 adam - * Work on relevance feedback. - * - * Revision 1.5 1995/09/07 13:58:43 adam - * New parameter: result-set file descriptor (RSFD) to support multiple - * positions within the same result-set. - * Boolean operators: and, or, not implemented. - * - * Revision 1.4 1995/09/06 16:11:56 adam - * More work on boolean sets. - * - * Revision 1.3 1995/09/04 15:20:39 adam - * More work on temp sets. is_open member removed. - * - * Revision 1.2 1995/09/04 12:33:56 adam - * Various cleanup. YAZ util used instead. - * - * Revision 1.1 1994/11/04 13:21:28 quinn - * Working. - * - */ +/* $Id: rset.c,v 1.33 2004-09-09 10:08:06 heikki Exp $ + Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 + Index Data Aps + +This file is part of the Zebra server. + +Zebra 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, or (at your option) any later +version. + +Zebra 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 Zebra; see the file LICENSE.zebra. If not, write to the +Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA +02111-1307, USA. +*/ + -#include -#include +#include +#include +#include +#include +#include #include -RSET rset_create(const rset_control *sel, void *parms) + +/* creates an rfd. Either allocates a new one, in which case the priv */ +/* pointer is null, and will have to be filled in, or picks up one */ +/* from the freelist, in which case the priv is already allocated, */ +/* and presumably everything that hangs from it as well */ + +RSFD rfd_create_base(RSET rs) +{ + RSFD rnew=rs->free_list; + if (rnew) { + rs->free_list=rnew->next; + assert(rnew->rset==rs); + /* logf(LOG_DEBUG,"rfd-create_base (fl): rfd=%p rs=%p fl=%p priv=%p", + rnew, rs, rs->free_list, rnew->priv); */ + } else { + rnew=nmem_malloc(rs->nmem, sizeof(*rnew)); + rnew->priv=NULL; + rnew->rset=rs; + /* logf(LOG_DEBUG,"rfd_create_base (new): rfd=%p rs=%p fl=%p priv=%p", + rnew, rs, rs->free_list, rnew->priv); */ + } + rnew->next=NULL; /* not part of any (free?) list */ + return rnew; +} + +/* puts an rfd into the freelist of the rset. Only when the rset gets */ +/* deleted, will all the nmem disappear */ +void rfd_delete_base(RSFD rfd) { - RSET new; + RSET rs=rfd->rset; + /* logf(LOG_DEBUG,"rfd_delete_base: rfd=%p rs=%p priv=%p fl=%p", + rfd, rs, rfd->priv, rs->free_list); */ + assert(NULL == rfd->next); + rfd->next=rs->free_list; + rs->free_list=rfd; +} + - logf (LOG_DEBUG, "rs_create(%s)", sel->desc); - new = xmalloc(sizeof(*new)); - new->control = sel; - new->buf = (*sel->f_create)(sel, parms); - return new; +RSET rset_create_base(const struct rset_control *sel, + NMEM nmem, const struct key_control *kcontrol, + int scope) +{ + RSET rnew; + NMEM M; + /* assert(nmem); */ /* can not yet be used, api/t4 fails */ + if (nmem) + M=nmem; + else + M=nmem_create(); + rnew = (RSET) nmem_malloc(M,sizeof(*rnew)); + /* logf (LOG_DEBUG, "rs_create(%s) rs=%p (nm=%p)", sel->desc, rnew, nmem); */ + rnew->nmem=M; + if (nmem) + rnew->my_nmem=0; + else + rnew->my_nmem=1; + rnew->control = sel; + rnew->count = 1; + rnew->priv = 0; + rnew->free_list=NULL; + rnew->keycontrol=kcontrol; + rnew->scope=scope; + return rnew; } void rset_delete (RSET rs) { - (*rs->control->f_delete)(rs); - xfree(rs); + (rs->count)--; +/* logf(LOG_DEBUG,"rs_delete(%s), rs=%p, count=%d", + rs->control->desc, rs, rs->count); */ + if (!rs->count) + { + (*rs->control->f_delete)(rs); + if (rs->my_nmem) + nmem_destroy(rs->nmem); + } +} + +RSET rset_dup (RSET rs) +{ + (rs->count)++; + return rs; } + +#if 0 +void rset_default_pos (RSFD rfd, double *current, double *total) +{ /* This should never really be needed, but it is still used in */ + /* those rsets that we don't really plan to use, like isam-s */ + assert(rfd); + assert(current); + assert(total); + *current=-1; /* signal that pos is not implemented */ + *total=-1; +} /* rset_default_pos */ +#endif + +int rset_default_forward(RSFD rfd, void *buf, + const void *untilbuf) +{ + int more=1; + int cmp=rfd->rset->scope; + logf (LOG_DEBUG, "rset_default_forward starting '%s' (ct=%p rfd=%p)", + rfd->rset->control->desc, rfd->rset, rfd); + /* key_logdump(LOG_DEBUG, untilbuf); */ + while ( (cmp>=rfd->rset->scope) && (more)) + { + logf (LOG_DEBUG, "rset_default_forward looping m=%d c=%d",more,cmp); + more=rset_read(rfd, buf); + if (more) + cmp=(rfd->rset->keycontrol->cmp)(untilbuf,buf); +/* if (more) + key_logdump(LOG_DEBUG,buf); */ + } + logf (LOG_DEBUG, "rset_default_forward exiting m=%d c=%d",more,cmp); + + return more; +} +