eg_raset.c

Go to the documentation of this file.
00001 /* EGlib "Efficient General Library" provides some basic structures and
00002  * algorithms commons in many optimization algorithms.
00003  *
00004  * Copyright (C) 2005-2010 Daniel Espinoza
00005  * 
00006  * This library is free software; you can redistribute it and/or modify it
00007  * under the terms of the GNU Lesser General Public License as published by the
00008  * Free Software Foundation; either version 2.1 of the License, or (at your
00009  * option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful, but 
00012  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
00013  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
00014  * License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public License
00017  * along with this library; if not, write to the Free Software Foundation,
00018  * Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
00019  * */
00020 /** @file 
00021  * @ingroup EGrSet */
00022 /** @addtogroup EGrSet */
00023 /** @{ */
00024 #include "eg_raset.h"
00025 /* ========================================================================= */
00026 void EGrsetSetgrnd(
00027   EGrset_t*const EGs,
00028   const int32_t grsz)
00029 {
00030   int32_t i=0,r=0;
00031   /* resize arrays if needed */
00032   if(grsz > EGs->asz)
00033   {
00034     EGs->inv = EGrealloc(EGs->inv,sizeof(int32_t)*((size_t)grsz));
00035     EGs->set = EGrealloc(EGs->set,sizeof(int32_t)*((size_t)grsz));
00036     for(i=grsz ; i-->EGs->asz;){
00037       EGs->inv[i] = EGs->set[i] = i;}
00038     EGs->asz = grsz;
00039   }
00040   /* prune possibly bad elements in set */
00041   if(grsz < EGs->grsz)
00042   {
00043     for(i=EGs->grsz ;i-->grsz;)
00044     {
00045       /* delete element */
00046       EGrsetDel(EGs,i);
00047       /* swap elements out of the grsz set */
00048       r=EGs->set[i];
00049       __EGrsetSwap(EGs,i,r);
00050     }
00051   }
00052   /*set new ground size */
00053   EGs->grsz = grsz;
00054 }
00055 /* ========================================================================= */
00056 /** @} */