]> granicus.if.org Git - postgresql/blobdiff - src/backend/utils/adt/chunk.c
Move some system includes into c.h, and remove duplicates.
[postgresql] / src / backend / utils / adt / chunk.c
index 0fc431314cbf8bc80be961d58ad27ced119a16d7..d64ed0cf02d5e8c832c35399da66234c408f2b3b 100644 (file)
@@ -1,12 +1,12 @@
 /*-------------------------------------------------------------------------
  *
- * chunk.c--
+ * chunk.c
  *
  * Copyright (c) 1994, Regents of the University of California
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/chunk.c,v 1.11 1997/12/06 22:57:12 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/chunk.c,v 1.23 1999/07/17 20:17:54 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
 
 #include "postgres.h"
 
-#include <libpq/be-fsstubs.h>
-#include "utils/memutils.h"
-#include "libpq/libpq-fs.h"
-
-#include "storage/fd.h"                        /* for SEEK_ */
-
 #include "catalog/pg_type.h"
-
 #include "fmgr.h"
-#include "utils/array.h"
-
+#include "libpq/be-fsstubs.h"
+#include "libpq/libpq-fs.h"
 #include "optimizer/internal.h"
-#ifndef HAVE_MEMMOVE
-#include <regex/utils.h>
-#else
-#include <string.h>
-#endif
-
+#include "utils/array.h"
+#include "utils/memutils.h"
 
 #define INFTY 500000000
 #define MANY  10000
 static CHUNK_INFO cInfo;
 
 /* non-export function prototypes */
-static int
-_FindBestChunk(int size, int dmax[], int dbest[], int dim,
+static int _FindBestChunk(int size, int *dmax, int *dbest, int dim,
                           int A[MAXPAT][MAXDIM + 1], int N);
-static int     get_next(int d[], int k, int C, int dmax[]);
-static void initialize_info(CHUNK_INFO *A, int ndim, int dim[], int chunk[]);
+static int     get_next(int *d, int k, int C, int *dmax);
+static void initialize_info(CHUNK_INFO *A, int ndim, int *dim, int *chunk);
 
 #ifdef LOARRAY
-static void
-_ConvertToChunkFile(int n, int baseSize, int dim[], int C[],
+static void _ConvertToChunkFile(int n, int baseSize, int *dim, int *C,
                                        int srcfd, int destfd);
-static void
-read_chunk(int chunk_no[], int C[], char a_chunk[], int srcfd,
-                  int n, int baseSize, int PX[], int dist[]);
+static void read_chunk(int *chunk_no, int *C, char *a_chunk, int srcfd,
+                  int n, int baseSize, int *PX, int *dist);
 static int     write_chunk(struct varlena * a_chunk, int ofile);
-static int     seek_and_read(int pos, int size, char buff[], int fp, int from);
+static int     seek_and_read(int pos, int size, char *buff, int fp, int from);
 
 #endif
-static int
-GetChunkSize(FILE *fd, int ndim, int dim[MAXDIM], int baseSize,
+static int GetChunkSize(FILE *fd, int ndim, int dim[MAXDIM], int baseSize,
                         int d[MAXDIM]);
 
 /*------------------------------------------------------------------------
@@ -75,11 +60,11 @@ GetChunkSize(FILE *fd, int ndim, int dim[MAXDIM], int baseSize,
  *        information about the chunked file
  *-----------------------------------------------------------------------
  */
-char      *
+char *
 _ChunkArray(int fd,
                        FILE *afd,
                        int ndim,
-                       int dim[],
+                       int *dim,
                        int baseSize,
                        int *nbytes,
                        char *chunkfile)
@@ -104,7 +89,7 @@ _ChunkArray(int fd,
        else
                cfd = LOopen(chunkfile, O_RDONLY);
        if (cfd < 0)
-               elog(WARN, "Unable to open chunk file");
+               elog(ERROR, "Unable to open chunk file");
 #endif
 
        strcpy(cInfo.lo_name, chunkfile);
@@ -124,7 +109,7 @@ _ChunkArray(int fd,
 }
 
 /*--------------------------------------------------------------------------
- * GetChunkSize --
+ * GetChunkSize
  *               given an access pattern and array dimensionality etc, this program
  *             returns the dimensions of the chunk in "d"
  *-----------------------------------------------------------------------
@@ -148,11 +133,11 @@ GetChunkSize(FILE *fd,
         */
        fscanf(fd, "%d", &N);
        if (N > MAXPAT)
-               elog(WARN, "array_in: too many access pattern elements");
+               elog(ERROR, "array_in: too many access pattern elements");
        for (i = 0; i < N; i++)
                for (j = 0; j < ndim + 1; j++)
                        if (fscanf(fd, "%d ", &(A[i][j])) == EOF)
-                               elog(WARN, "array_in: bad access pattern input");
+                               elog(ERROR, "array_in: bad access pattern input");
 
        /*
         * estimate chunk size
@@ -169,7 +154,7 @@ GetChunkSize(FILE *fd,
 }
 
 /*-------------------------------------------------------------------------
- * _FindBestChunk --
+ * _FindBestChunk
  *               This routine does most of the number crunching to compute the
  *               optimal chunk shape.
  * Called by GetChunkSize
@@ -177,8 +162,8 @@ GetChunkSize(FILE *fd,
  */
 static int
 _FindBestChunk(int size,
-                          int dmax[],
-                          int dbest[],
+                          int *dmax,
+                          int *dbest,
                           int dim,
                           int A[MAXPAT][MAXDIM + 1],
                           int N)
@@ -193,10 +178,10 @@ _FindBestChunk(int size,
        {
 
                /*
-                * compute the number of page fetches for a given chunk size (d[])
-                * and access pattern (A[][])
+                * compute the number of page fetches for a given chunk size (*d)
+                * and access pattern (**A)
                 */
-               register int i,
+               int                     i,
                                        j,
                                        nc;
 
@@ -218,18 +203,18 @@ _FindBestChunk(int size,
                                ;
                }
        }
-       return (mintc);
+       return mintc;
 }
 
 /*----------------------------------------------------------------------
- * get_next --
+ * get_next
  *      Called by _GetBestChunk to get the next tuple in the lexicographic order
  *---------------------------------------------------------------------
  */
 static int
-get_next(int d[], int k, int C, int dmax[])
+get_next(int *d, int k, int C, int *dmax)
 {
-       register int i,
+       int                     i,
                                j,
                                temp;
 
@@ -241,7 +226,7 @@ get_next(int d[], int k, int C, int dmax[])
                        d[j] = min(temp, dmax[j]);
                        temp = max(1, temp / d[j]);
                }
-               return (1);
+               return 1;
        }
 
        for (j = 0, temp = 1; j < k; j++)
@@ -254,7 +239,7 @@ get_next(int d[], int k, int C, int dmax[])
                        break;
        }
        if (i < 0)
-               return (0);
+               return 0;
 
        d[i]++;
        j = C / temp;
@@ -267,16 +252,17 @@ get_next(int d[], int k, int C, int dmax[])
                d[j] = min(temp, dmax[j]);
                temp = max(1, temp / d[j]);
        }
-       return (1);
+       return 1;
 }
 
 #ifdef LOARRAY
-static char a_chunk[BLCKSZ + VARHDRSZ];/* VARHDRSZ since a_chunk is in varlena format */
+static char a_chunk[BLCKSZ + VARHDRSZ]; /* VARHDRSZ since a_chunk is in
+                                                                                * varlena format */
 
 #endif
 
 static void
-initialize_info(CHUNK_INFO *A, int ndim, int dim[], int chunk[])
+initialize_info(CHUNK_INFO *A, int ndim, int *dim, int *chunk)
 {
        int                     i;
 
@@ -299,8 +285,8 @@ initialize_info(CHUNK_INFO *A, int ndim, int dim[], int chunk[])
 static void
 _ConvertToChunkFile(int n,
                                        int baseSize,
-                                       int dim[],
-                                       int C[],
+                                       int *dim,
+                                       int *C,
                                        int srcfd,
                                        int destfd)
 {
@@ -339,14 +325,14 @@ _ConvertToChunkFile(int n,
  *--------------------------------------------------------------------------
  */
 static void
-read_chunk(int chunk_no[],
-                  int C[],
-                  char a_chunk[],
+read_chunk(int *chunk_no,
+                  int *C,
+                  char *a_chunk,
                   int srcfd,
                   int n,
                   int baseSize,
-                  int PX[],
-                  int dist[])
+                  int *PX,
+                  int *dist)
 {
        int                     i,
                                j,
@@ -396,7 +382,7 @@ write_chunk(struct varlena * a_chunk, int ofile)
 #ifdef LOARRAY
        got_n = LOwrite(ofile, a_chunk);
 #endif
-       return (got_n);
+       return got_n;
 }
 
 /*--------------------------------------------------------------------------
@@ -407,35 +393,35 @@ write_chunk(struct varlena * a_chunk, int ofile)
  *--------------------------------------------------------------------------
  */
 static int
-seek_and_read(int pos, int size, char buff[], int fp, int from)
+seek_and_read(int pos, int size, char *buff, int fp, int from)
 {
        struct varlena *v = NULL;
 
        /* Assuming only one file */
        if (lo_lseek(fp, pos, from) < 0)
-               elog(WARN, "File seek error");
+               elog(ERROR, "File seek error");
 #ifdef LOARRAY
        v = (struct varlena *) LOread(fp, size);
 #endif
        if (VARSIZE(v) - VARHDRSZ < size)
-               elog(WARN, "File read error");
+               elog(ERROR, "File read error");
        memmove(buff, VARDATA(v), size);
        pfree(v);
-       return (1);
+       return 1;
 
 }
 
-#endif                                                 /* LOARRAY */
+#endif  /* LOARRAY */
 
 /*----------------------------------------------------------------------------
- * _ReadChunkArray --
+ * _ReadChunkArray
  *               returns the subarray specified bu the range indices "st" and "endp"
  *               from the chunked array stored in file "fp"
  *---------------------------------------------------------------------------
  */
 int
-_ReadChunkArray(int st[],
-                               int endp[],
+_ReadChunkArray(int *st,
+                               int *endp,
                                int bsize,
                                int fp,
                                char *destfp,
@@ -580,7 +566,7 @@ _ReadChunkArray(int st[],
                        block_seek += (to_read / bsize);
 
                        /*
-                        * compute next tuple in range[]
+                        * compute next tuple in *range
                         */
                        {
                                int                     x;
@@ -624,17 +610,17 @@ _ReadChunkArray(int st[],
                        range_end[i] = min((chunk_st[i] + chunk_off[i]) * C[i] + C[i] - 1, endp[i]);
                }
        } while (jj != -1);
-       return (words_read);
+       return words_read;
 }
 
 /*------------------------------------------------------------------------
- * _ReadChunkArray1El --
+ * _ReadChunkArray1El
  *              returns one element of the chunked array as specified by the index "st"
  *              the chunked file descriptor is "fp"
  *-------------------------------------------------------------------------
  */
 struct varlena *
-_ReadChunkArray1El(int st[],
+_ReadChunkArray1El(int *st,
                                   int bsize,
                                   int fp,
                                   ArrayType *array,