1: # include "stdio.h"
   2: # include "assert.h"
   3: whash(ft, fa, fb, nhash, iflong, ptotct, phused)
   4:     FILE *fa, *fb, *ft;
   5:     int nhash, *phused;
   6:     long *ptotct;
   7: {
   8: char line[100];
   9: int hash 0, hused 0;
  10: long totct 0L;
  11: int ct 0;
  12: long point;
  13: long opoint -1;
  14: int m;
  15: int k; long lp;
  16: long *hpt;
  17: int *hfreq NULL;
  18: 
  19: hpt = calloc (nhash+1, sizeof(*hpt));
  20: _assert (hpt != NULL);
  21: hfreq = calloc (nhash, sizeof(*hfreq));
  22: _assert (hfreq !=NULL);
  23: hpt[0] = 0;
  24: lp= 0;
  25: while (fgets(line, 100, ft))
  26:     {
  27:     totct++;
  28:     sscanf(line, "%d %ld", &k, &point);
  29:     if (hash < k)
  30:         {
  31:         hused++;
  32:         if (iflong) putl(-1L, fb); else putw(-1, fb);
  33:         hfreq[hash]=ct;
  34:         while (hash<k)
  35:             {
  36:             hpt[++hash] = lp;
  37:             hfreq[hash] = 0;
  38:             }
  39:         hpt[hash] = lp += iflong? sizeof(long) : sizeof(int);
  40:         opoint= -1;
  41:         ct=0;
  42:         }
  43:     if (point!=opoint)
  44:         {
  45:         if (iflong)
  46:             putl(opoint=point, fb);
  47:         else
  48:             putw( (int)(opoint=point), fb);
  49:         lp += iflong? sizeof(long) : sizeof(int);
  50:         ct++;
  51:         }
  52:     }
  53: if (iflong) putl(-1L, fb); else putw(-1,fb);
  54: while (hash<nhash)
  55:     hpt[++hash]=lp;
  56: fwrite(&nhash, sizeof(nhash), 1, fa);
  57: fwrite(&iflong, sizeof(iflong), 1, fa);
  58: fwrite(hpt, sizeof(*hpt), nhash, fa);
  59: fwrite (hfreq, sizeof(*hfreq), nhash, fa);
  60: *ptotct = totct;
  61: *phused = hused;
  62: }
  63: putl(ll, f)
  64:     long ll;
  65:     FILE *f;
  66: {
  67: int *x;
  68: x = &ll;
  69: putw(x[0], f);
  70: putw(x[1], f);
  71: }
  72: long getl(f)
  73:     FILE *f;
  74: {
  75: int x[2];
  76: int *ll;
  77: x[0] = getw(f);
  78: x[1] = getw(f);
  79: ll = x;
  80: return (*ll);
  81: }

Defined functions

getl defined in line 72; used 3 times
putl defined in line 63; used 3 times
whash defined in line 3; used 1 times
Last modified: 1981-07-10
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 714
Valid CSS Valid XHTML 1.0 Strict