Ignore:
Timestamp:
2004-11-29T15:43:11+13:00 (20 years ago)
Author:
kjdon
Message:

Added the changes from Emanuel Dejanu (Simple Words) - mostly efficiency changes. For example, changing i++ to ++i, delete xxx to delete []xxx, some stuff to do with UCArrays...

Location:
trunk/indexers/mgpp/lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/indexers/mgpp/lib/bitio_m_random.cpp

    r3365 r8692  
    1616
    1717random_bitio_buffer::~random_bitio_buffer() {
    18   if (buffer != NULL) delete buffer;
     18  if (buffer != NULL) delete []buffer;
    1919}
    2020
     
    2222  // delete the old buffer
    2323  if (buffer != NULL) {
    24     delete buffer;
     24    delete []buffer;
    2525    buffer = NULL;
    2626  }
     
    5454  // delete the old buffer
    5555  if (buffer != NULL) {
    56     delete buffer;
     56    delete []buffer;
    5757    buffer = NULL;
    5858  }
     
    131131  flush();
    132132  if (buffer != NULL) {
    133     delete buffer;
     133    delete []buffer;
    134134    buffer = NULL;
    135135  }
  • trunk/indexers/mgpp/lib/huffman.cpp

    r3365 r8692  
    5656
    5757  /* Initialise the pointers to the leaves */
    58   for (count = i = 0; i < num; i++)
     58  for (count = i = 0; i < num; ++i)
    5959    if (heap[num + i])
    6060      heap[count++] = num + i;
     
    6262  /* Reorganise the pointers so that it is a heap */
    6363  HNum = count;
    64   for (i = HNum / 2; i > 0; i--)
     64  for (i = HNum / 2; i > 0; --i)
    6565    {
    6666      register int curr, child;
     
    7070    {
    7171      if (child < HNum && heap[heap[child]] < heap[heap[child - 1]])
    72         child++;
     72        ++child;
    7373      if (heap[heap[curr - 1]] > heap[heap[child - 1]])
    7474        {
     
    9191      int pos[2];
    9292
    93       for (i = 0; i < 2; i++)
     93      for (i = 0; i < 2; ++i)
    9494    {
    9595      register int curr, child;
     
    102102          if (child < HNum &&
    103103          heap[heap[child]] < heap[heap[child - 1]])
    104         child++;
     104        ++child;
    105105          if (heap[heap[curr - 1]] > heap[heap[child - 1]])
    106106        {
     
    124124      {
    125125    register int parent, curr;
    126     HNum++;
     126    ++HNum;
    127127    curr = HNum;
    128128    parent = curr >> 1;
     
    143143  heap[0] = -1UL;
    144144  heap[1] = 0;
    145   for (i = 2; i < num * 2; i++)
     145  for (i = 2; i < num * 2; ++i)
    146146    heap[i] = heap[heap[i]] + 1;
    147147
     
    152152
    153153  /* Set the code length of each leaf in the huffman tree */
    154   for (i = 0; i < num; i++)
     154  for (i = 0; i < num; ++i)
    155155    {
    156156      register u_long codelen = heap[i + num];
     
    162162      if (codelen < hd->mincodelen)
    163163    hd->mincodelen = codelen;
    164       hd->lencount[codelen]++;
     164      ++hd->lencount[codelen];
    165165    }
    166166
     
    174174      /* Calculate the current codes for each different code length */
    175175      hd->min_code[hd->maxcodelen] = 0;
    176       for (i = hd->maxcodelen - 1; i>=0; i--)
     176      for (i = hd->maxcodelen - 1; i>=0; --i)
    177177    hd->min_code[i] = (hd->min_code[i + 1] + hd->lencount[i + 1]) >> 1;
    178178    }
    179   delete heap;
     179  delete []heap;
    180180  return (hd);
    181181
    182182error2:
    183   delete heap;
     183  delete []heap;
    184184error1:
    185185  if (!data)
     
    204204    *mem += data->num_codes * sizeof (*codes);
    205205  memcpy (mc, data->min_code, sizeof (mc));
    206   for (i = 0; i < data->num_codes; i++)
     206  for (i = 0; i < data->num_codes; ++i)
    207207    if (data->clens[i])
    208208      codes[i] = mc[(int) (data->clens[i])]++;
     
    226226  if (!(values = new unsigned long *[MAX_HUFFCODE_LEN + 1]))
    227227    {
    228       delete vals;
     228      delete []vals;
    229229      return (NULL);
    230230    }
     
    237237
    238238  fcode[0] = values[0] = &vals[0];
    239   for (i = 1; i <= data->maxcodelen; i++)
     239  for (i = 1; i <= data->maxcodelen; ++i)
    240240    fcode[i] = values[i] = &vals[(values[i - 1] - vals) + data->lencount[i - 1]];
    241241
    242   for (i = 0; i < data->num_codes; i++)
     242  for (i = 0; i < data->num_codes; ++i)
    243243    if (data->clens[i])
    244244      *fcode[(int) (data->clens[i])]++ = i;
     
    256256  if (!Generate_Huffman_Data (num, freqs, &hd, NULL))
    257257    return -1;
    258   for (i = 0; i < num; i++)
     258  for (i = 0; i < num; ++i)
    259259    size += counts[i] * hd.clens[i];
    260   delete hd.clens;
     260  delete []hd.clens;
    261261  return size;
    262262}
     
    290290      /* [RPAP - Jan 97: Endian Ordering] */
    291291      int i;
    292       for (i = hd->mincodelen; i < hd->maxcodelen + 1; i++)
     292      for (i = hd->mincodelen; i < hd->maxcodelen + 1; ++i)
    293293    HTONSI(hd->lencount[i]);
    294       for (i = 0; i < hd->maxcodelen + 1; i++)
     294      for (i = 0; i < hd->maxcodelen + 1; ++i)
    295295    HTONUL(hd->min_code[i]);
    296296
     
    308308
    309309      /* [RPAP - Jan 97: Endian Ordering] */
    310       for (i = hd->mincodelen; i < hd->maxcodelen + 1; i++)
     310      for (i = hd->mincodelen; i < hd->maxcodelen + 1; ++i)
    311311    NTOHSI(hd->lencount[i]);
    312       for (i = 0; i < hd->maxcodelen + 1; i++)
     312      for (i = 0; i < hd->maxcodelen + 1; ++i)
    313313    NTOHUL(hd->min_code[i]);
    314314    }
     
    350350
    351351      /* [RPAP - Jan 97: Endian Ordering] */
    352       for (i = hd->mincodelen; i < hd->maxcodelen + 1; i++)
     352      for (i = hd->mincodelen; i < hd->maxcodelen + 1; ++i)
    353353    NTOHSI(hd->lencount[i]);
    354354
     
    363363
    364364      /* [RPAP - Jan 97: Endian Ordering] */
    365       for (i = 0; i < hd->maxcodelen + 1; i++)
     365      for (i = 0; i < hd->maxcodelen + 1; ++i)
    366366    NTOHUL(hd->min_code[i]);
    367367
Note: See TracChangeset for help on using the changeset viewer.