Exemplo n.º 1
0
/*
   --------------------------------------
   sort and compress the pencil's entries

   created -- 98may02, cca
   --------------------------------------
*/
void
Pencil_sortAndCompress (
   Pencil   *pencil 
) {

if ( pencil->inpmtxA != NULL ) {
   InpMtx_sortAndCompress(pencil->inpmtxA) ;
}
if ( pencil->inpmtxB != NULL ) {
   InpMtx_sortAndCompress(pencil->inpmtxB) ;
}
return ; }
Exemplo n.º 2
0
/*
   ---------------------------------
   prepare to add more entries, 
   sort/compress and possible resize

   created -- 98apr25, cca
   ---------------------------------
*/
static void
prepareToAddNewEntries (
   InpMtx   *inpmtx,
   int      nnewent
) {
if ( inpmtx->nent + nnewent > inpmtx->maxnent ) {
/*
   -----------------------------------
   vectors are full, sort and compress
   -----------------------------------
*/
   InpMtx_sortAndCompress(inpmtx) ;
   inpmtx->storageMode = INPMTX_SORTED ;
}
if ( inpmtx->nent + nnewent > inpmtx->maxnent ) {
/*
   ------------------------------
   vectors are still full, resize
   ------------------------------
*/
   int   newmaxnent = inpmtx->maxnent * inpmtx->resizeMultiple ;
   if ( newmaxnent < inpmtx->nent + nnewent ) {
      newmaxnent = inpmtx->nent + nnewent ;
   }
   InpMtx_setMaxnent(inpmtx, newmaxnent) ;
}
return ; }
Exemplo n.º 3
0
Arquivo: util.c Projeto: bialk/SPOOLES
/*
   ----------------------------------------------------
   convert from sorted and compressed triples to vector

   created -- 98jan28, cca
   ----------------------------------------------------
*/
void
InpMtx_convertToVectors (
   InpMtx   *inpmtx 
) {
int      *ivec1, *ivec2, *offsets, *sizes, *vecids ;
int      first, id, ient, jj, nent, nvector, value ;
/*
   ---------------
   check the input
   ---------------
*/
if ( inpmtx == NULL ) {
   fprintf(stderr, "\n fatal error in InpMtx_convertToVectors(%p)"
           "\n bad input\n", inpmtx) ;
   exit(-1) ;
}
if ( INPMTX_IS_BY_VECTORS(inpmtx) || (nent = inpmtx->nent) == 0 ) {
   inpmtx->storageMode = INPMTX_BY_VECTORS ;
   return ;
}
if ( INPMTX_IS_RAW_DATA(inpmtx) ) {
   InpMtx_sortAndCompress(inpmtx) ;
}
ivec1 = InpMtx_ivec1(inpmtx) ;
ivec2 = InpMtx_ivec2(inpmtx) ;
/*
   -----------------------------------
   find the number of distinct vectors
   -----------------------------------
*/
value = -1 ;
nvector = 0 ;
for ( ient = 0 ; ient < nent ; ient++ ) {
   if ( ivec1[ient] >= 0 && value != ivec1[ient] ) {
      value = ivec1[ient] ;
      nvector++ ;
#if MYDEBUG > 0
      fprintf(stdout, "\n ient %d, value %d, nvector %d", 
              ient, value, nvector) ;
      fflush(stdout) ;
#endif
   }
}
#if MYDEBUG > 0
fprintf(stdout, "\n %d vectors", nvector) ;
fflush(stdout) ;
#endif
/*
   -----------------------------------------------------------------
   adjust the sizes of the sizes[] and offsets[] arrays if necessary
   -----------------------------------------------------------------
*/
InpMtx_setNvector(inpmtx, nvector) ;
if ( nvector <= 0 ) {
/*
   -----------------------------
   matrix has no entries, return
   -----------------------------
*/
   inpmtx->storageMode = INPMTX_RAW_DATA ;
   InpMtx_setNent(inpmtx, 0) ;
   return ;
}
vecids  = InpMtx_vecids(inpmtx)  ;
sizes   = InpMtx_sizes(inpmtx)   ;
offsets = InpMtx_offsets(inpmtx) ;
/*
   ------------------------------------------------------------
   set the vector sizes and offsets
   note: we skip all entries whose first coordinate is negative
   ------------------------------------------------------------
*/
for ( first = 0 ; first < nent ; first++ ) {
   if ( ivec1[first] >= 0 ) {
      break ;
   }
}
id = 0 ;
if ( first < nent ) {
   value = ivec1[first] ;
   for ( jj = first + 1 ; jj < nent ; jj++ ) {
      if ( ivec1[jj] != value ) {
         vecids[id]  = value      ;
         sizes[id]   = jj - first ;
         offsets[id] = first      ;
#if MYDEBUG > 0
         fprintf(stdout, 
                 "\n vecids[%d] = %d, sizes[%d] = %d, offsets[%d] = %d",
                 id, vecids[id], id, sizes[id], id, offsets[id]) ;
         fflush(stdout) ;
#endif
         first       = jj         ;
         value       = ivec1[jj]  ;
         id++ ;
      }
   }
   vecids[id]  = value      ;
   sizes[id]   = jj - first ;
   offsets[id] = first      ;
#if MYDEBUG > 0
   fprintf(stdout, 
           "\n vecids[%d] = %d, sizes[%d] = %d, offsets[%d] = %d",
           id, vecids[id], id, sizes[id], id, offsets[id]) ;
   fflush(stdout) ;
#endif
}
inpmtx->storageMode = INPMTX_BY_VECTORS ;
#if MYDEBUG > 0
fprintf(stdout, "\n vecidsIV") ;
IV_writeForHumanEye(&inpmtx->vecidsIV, stdout) ;
fprintf(stdout, "\n sizesIV") ;
IV_writeForHumanEye(&inpmtx->sizesIV, stdout) ;
fprintf(stdout, "\n offsetsIV") ;
IV_writeForHumanEye(&inpmtx->offsetsIV, stdout) ;
fflush(stdout) ;
#endif

return ; }