Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals

sh_find.c

Go to the documentation of this file.
00001 /*
00002 ** Copyright (C) 2002 by Kevin L. Mitchell <klmitch@mit.edu>
00003 **
00004 ** This library is free software; you can redistribute it and/or
00005 ** modify it under the terms of the GNU Library General Public
00006 ** License as published by the Free Software Foundation; either
00007 ** version 2 of the License, or (at your option) any later version.
00008 **
00009 ** This library is distributed in the hope that it will be useful,
00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 ** Library General Public License for more details.
00013 **
00014 ** You should have received a copy of the GNU Library General Public
00015 ** License along with this library; if not, write to the Free
00016 ** Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00017 ** MA 02111-1307, USA
00018 **
00019 ** @(#)$Id: sh_find.c,v 1.3 2006/07/13 19:16:24 klmitch Exp $
00020 */
00028 #include "dbprim.h"
00029 #include "dbprim_int.h"
00030 
00031 RCSTAG("@(#)$Id: sh_find.c,v 1.3 2006/07/13 19:16:24 klmitch Exp $");
00032 
00041 struct _sh_find_s {
00042   smat_comp_t   sf_comp;        
00043   db_key_t     *sf_key;         
00044 };
00045 
00060 static unsigned long
00061 _sh_find_comp(db_key_t *key, void *data)
00062 {
00063   struct _sh_find_s *sf;
00064 
00065   sf = dk_key(key);
00066 
00067   /* Call the user's comparison function--with some translation */
00068   return (*sf->sf_comp)(sf->sf_key, data);
00069 }
00070 
00071 unsigned long
00072 sh_find(smat_head_t *head, smat_entry_t **elem_p, smat_comp_t comp_func,
00073         smat_entry_t *start, db_key_t *key)
00074 {
00075   unsigned long retval;
00076   link_elem_t *elem;
00077   struct _sh_find_s sf;
00078   db_key_t fkey;
00079 
00080   initialize_dbpr_error_table(); /* initialize error table */
00081 
00082   /* verify arguments */
00083   if (!sh_verify(head) || !elem_p || !comp_func || !key ||
00084       (start && !se_verify(start)))
00085     return DB_ERR_BADARGS;
00086 
00087   /* Set up for the call to ll_find()... */
00088   sf.sf_comp = comp_func;
00089   sf.sf_key = key;
00090   dk_key(&fkey) = &sf;
00091 
00092   /* call into the linked list library to find the element */
00093   if ((retval = ll_find(&head->sh_head, &elem, _sh_find_comp,
00094                         start ? &start->se_link[head->sh_elem] : 0, &fkey)))
00095     return retval;
00096 
00097   *elem_p = le_object(elem); /* set the entry pointer correctly */
00098 
00099   return 0;
00100 }

Generated on Sat Jul 15 14:10:33 2006 for DatabasePrimitivesLibrary by  doxygen 1.4.4