[GRASS-SVN] r62372 - in grass/trunk: include lib/segment

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Oct 24 00:30:34 PDT 2014


Author: mmetz
Date: 2014-10-24 00:30:34 -0700 (Fri, 24 Oct 2014)
New Revision: 62372

Modified:
   grass/trunk/include/segment.h
   grass/trunk/lib/segment/address.c
   grass/trunk/lib/segment/flush.c
   grass/trunk/lib/segment/get.c
   grass/trunk/lib/segment/get_row.c
   grass/trunk/lib/segment/init.c
   grass/trunk/lib/segment/local_proto.h
   grass/trunk/lib/segment/pagein.c
   grass/trunk/lib/segment/pageout.c
   grass/trunk/lib/segment/put.c
   grass/trunk/lib/segment/put_row.c
   grass/trunk/lib/segment/seek.c
   grass/trunk/lib/segment/setup.c
Log:
libsegment: fix r62324, separate internal and external functions

Modified: grass/trunk/include/segment.h
===================================================================
--- grass/trunk/include/segment.h	2014-10-24 07:02:00 UTC (rev 62371)
+++ grass/trunk/include/segment.h	2014-10-24 07:30:34 UTC (rev 62372)
@@ -37,12 +37,12 @@
     int fast_seek;      	/* toggles fast seek mode */
     int lenbits;        	/* data size bitshift */
     int sizebits;       	/* segment size bitshift */
-    int (*Segment_address)();
-    int (*Segment_seek)();
+    int (*address)();
+    int (*seek)();
     
     char *fname;		/* segment file name */
     int fd;			/* file descriptor to read/write segment */
-    struct Segment_SCB		/* control blocks */
+    struct scb			/* control blocks */
     {
 	char *buf;		/* data buffer */
 	char dirty;		/* dirty flag */

Modified: grass/trunk/lib/segment/address.c
===================================================================
--- grass/trunk/lib/segment/address.c	2014-10-24 07:02:00 UTC (rev 62371)
+++ grass/trunk/lib/segment/address.c	2014-10-24 07:30:34 UTC (rev 62372)
@@ -27,7 +27,7 @@
 #define INDEX_ADJ(SEG, i) \
     ((SEG)->fast_seek ? ((i) << (SEG)->lenbits) : ((i) * (SEG)->len))
 
-int Segment_address_fast(const SEGMENT * SEG, off_t row, off_t col, int *n,
+int seg_address_fast(const SEGMENT * SEG, off_t row, off_t col, int *n,
 			 int *index)
 {
 
@@ -70,7 +70,7 @@
     return 0;
 }
 
-int Segment_address_slow(const SEGMENT * SEG, off_t row, off_t col, int *n,
+int seg_address_slow(const SEGMENT * SEG, off_t row, off_t col, int *n,
 			 int *index)
 {
     if (row) {
@@ -92,7 +92,9 @@
 }
 
 /**
- * \brief Gets segment address and returns <b>n</b> and <b>index</b>.
+ * \brief Internal use only
+ * 
+ * Gets segment address and sets<b>n</b> and <b>index</b>.
  *
  * \param[in] SEG segment
  * \param[in] row
@@ -102,7 +104,7 @@
  * \return always returns 0
  */
 
-int Segment_address(const SEGMENT * SEG, off_t row, off_t col, int *n, int *index)
+int seg_address(const SEGMENT * SEG, off_t row, off_t col, int *n, int *index)
 {
     /* old code
      *n = row / SEG->srows * SEG->spr + col / SEG->scols;
@@ -112,5 +114,5 @@
     /* this function is called at least once every time data are accessed in SEG
      * avoid very slow modulus and divisions, modulus was the main time killer */
 
-    return SEG->Segment_address(SEG, row, col, n, index);
+    return SEG->address(SEG, row, col, n, index);
 }

Modified: grass/trunk/lib/segment/flush.c
===================================================================
--- grass/trunk/lib/segment/flush.c	2014-10-24 07:02:00 UTC (rev 62371)
+++ grass/trunk/lib/segment/flush.c	2014-10-24 07:30:34 UTC (rev 62372)
@@ -35,7 +35,7 @@
 
     for (i = 0; i < SEG->nseg; i++)
 	if (SEG->scb[i].n >= 0 && SEG->scb[i].dirty)
-	    Segment_pageout(SEG, i);
+	    seg_pageout(SEG, i);
 
     return 0;
 }

Modified: grass/trunk/lib/segment/get.c
===================================================================
--- grass/trunk/lib/segment/get.c	2014-10-24 07:02:00 UTC (rev 62371)
+++ grass/trunk/lib/segment/get.c	2014-10-24 07:30:34 UTC (rev 62372)
@@ -40,8 +40,8 @@
 {
     int index, n, i;
 
-    SEG->Segment_address(SEG, row, col, &n, &index);
-    if ((i = Segment_pagein(SEG, n)) < 0)
+    SEG->address(SEG, row, col, &n, &index);
+    if ((i = seg_pagein(SEG, n)) < 0)
 	return -1;
 
     memcpy(buf, &SEG->scb[i].buf[index], SEG->len);

Modified: grass/trunk/lib/segment/get_row.c
===================================================================
--- grass/trunk/lib/segment/get_row.c	2014-10-24 07:02:00 UTC (rev 62371)
+++ grass/trunk/lib/segment/get_row.c	2014-10-24 07:30:34 UTC (rev 62372)
@@ -52,8 +52,8 @@
     size = scols * SEG->len;
 
     for (col = 0; col < ncols; col += scols) {
-	SEG->Segment_address(SEG, row, col, &n, &index);
-	SEG->Segment_seek(SEG, n, index);
+	SEG->address(SEG, row, col, &n, &index);
+	SEG->seek(SEG, n, index);
 
 	if (read(SEG->fd, buf, size) != size) {
 	    G_warning("Segment_get_row: %s", strerror(errno));
@@ -68,8 +68,8 @@
 	buf = ((char *)buf) + size;
     }
     if ((size = SEG->spill * SEG->len)) {
-	SEG->Segment_address(SEG, row, col, &n, &index);
-	SEG->Segment_seek(SEG, n, index);
+	SEG->address(SEG, row, col, &n, &index);
+	SEG->seek(SEG, n, index);
 
 	if (read(SEG->fd, buf, size) != size) {
 	    G_warning("Segment_get_row: %s", strerror(errno));

Modified: grass/trunk/lib/segment/init.c
===================================================================
--- grass/trunk/lib/segment/init.c	2014-10-24 07:02:00 UTC (rev 62371)
+++ grass/trunk/lib/segment/init.c	2014-10-24 07:30:34 UTC (rev 62372)
@@ -75,7 +75,7 @@
 	|| !read_int(fd, &SEG->len))
 	return -1;
 
-    return Segment_setup(SEG);
+    return seg_setup(SEG);
 }
 
 

Modified: grass/trunk/lib/segment/local_proto.h
===================================================================
--- grass/trunk/lib/segment/local_proto.h	2014-10-24 07:02:00 UTC (rev 62371)
+++ grass/trunk/lib/segment/local_proto.h	2014-10-24 07:30:34 UTC (rev 62372)
@@ -3,25 +3,26 @@
 
 #include <grass/segment.h>
 
+/* internal functions */
+
 /* address.c */
-int Segment_address(const SEGMENT *, off_t, off_t, int *, int *);
-int Segment_address_fast(const SEGMENT *, off_t, off_t, int *, int *);
-int Segment_address_slow(const SEGMENT *, off_t, off_t, int *, int *);
+int seg_address(const SEGMENT *, off_t, off_t, int *, int *);
+int seg_address_fast(const SEGMENT *, off_t, off_t, int *, int *);
+int seg_address_slow(const SEGMENT *, off_t, off_t, int *, int *);
 
 /* pagein.c */
-int Segment_pagein(SEGMENT *, int);
+int seg_pagein(SEGMENT *, int);
 
 /* pageout.c */
-int Segment_pageout(SEGMENT *, int);
+int seg_pageout(SEGMENT *, int);
 
 /* seek.c */
-int Segment_seek(const SEGMENT *, int, int);
-int Segment_seek_fast(const SEGMENT *, int, int);
-int Segment_seek_slow(const SEGMENT *, int, int);
+int seg_seek(const SEGMENT *, int, int);
+int seg_seek_fast(const SEGMENT *, int, int);
+int seg_seek_slow(const SEGMENT *, int, int);
 
 /* setup.c */
-int Segment_setup(SEGMENT *);
+int seg_setup(SEGMENT *);
 
-
 #endif /* Segment_LOCAL_H */
 

Modified: grass/trunk/lib/segment/pagein.c
===================================================================
--- grass/trunk/lib/segment/pagein.c	2014-10-24 07:02:00 UTC (rev 62371)
+++ grass/trunk/lib/segment/pagein.c	2014-10-24 07:30:34 UTC (rev 62372)
@@ -21,10 +21,10 @@
 
 
 /**
- * \fn int Segment_pagein (SEGMENT *SEG, int n)
+ * \brief Internal use only
+ * 
+ * Segment pagein.
  *
- * \brief Segment pagein.
- *
  * Finds <b>n</b> in the segment file, <b>seg</b>, and selects it as the 
  * current segment.
  *
@@ -34,7 +34,7 @@
  * \return -1 if unable to seek or read segment file
  */
 
-int Segment_pagein(SEGMENT * SEG, int n)
+int seg_pagein(SEGMENT * SEG, int n)
 {
     int cur;
     int read_result;
@@ -77,7 +77,7 @@
 
 	    /* write it out if dirty */
 	    if (SEG->scb[cur].dirty) {
-		if (Segment_pageout(SEG, cur) < 0)
+		if (seg_pageout(SEG, cur) < 0)
 		    return -1;
 	    }
 	}
@@ -90,20 +90,20 @@
     /* read in the segment */
     SEG->scb[cur].n = n;
     SEG->scb[cur].dirty = 0;
-    SEG->Segment_seek(SEG, SEG->scb[cur].n, 0);
+    SEG->seek(SEG, SEG->scb[cur].n, 0);
 
     read_result = read(SEG->fd, SEG->scb[cur].buf, SEG->size);
     if (read_result != SEG->size) {
-	G_debug(2, "Segment_pagein: read_result=%d  SEG->size=%d",
+	G_debug(2, "Segment pagein: read_result=%d  SEG->size=%d",
 		read_result, SEG->size);
 
 	if (read_result < 0)
-	    G_warning("Segment_pagein: %s", strerror(errno));
+	    G_warning("Segment pagein: %s", strerror(errno));
 	else if (read_result == 0)
-	    G_warning("Segment_pagein: read EOF");
+	    G_warning("Segment pagein: read EOF");
 	else
 	    G_warning
-		("Segment_pagein: short count during read(), got %d, expected %d",
+		("Segment pagein: short count during read(), got %d, expected %d",
 		 read_result, SEG->size);
 
 	return -1;

Modified: grass/trunk/lib/segment/pageout.c
===================================================================
--- grass/trunk/lib/segment/pageout.c	2014-10-24 07:02:00 UTC (rev 62371)
+++ grass/trunk/lib/segment/pageout.c	2014-10-24 07:30:34 UTC (rev 62372)
@@ -21,10 +21,10 @@
 
 
 /**
- * \fn int Segment_pageout(SEGMENT *SEG, int i)
+ * \brief Internal use only
+ * 
+ * Pages segment to disk.
  *
- * \brief Pages segment to disk.
- *
  * Finds segment value <b>i</b> in segment <b>seg</b> and pages it out 
  * to disk.
  *
@@ -34,11 +34,11 @@
  * \return -1 on error
  */
 
-int Segment_pageout(SEGMENT * SEG, int i)
+int seg_pageout(SEGMENT * SEG, int i)
 {
-    SEG->Segment_seek(SEG, SEG->scb[i].n, 0);
+    SEG->seek(SEG, SEG->scb[i].n, 0);
     if (write(SEG->fd, SEG->scb[i].buf, SEG->size) != SEG->size) {
-	G_warning("Segment_pageout: %s", strerror(errno));
+	G_warning("Segment pageout: %s", strerror(errno));
 	return -1;
     }
     SEG->scb[i].dirty = 0;

Modified: grass/trunk/lib/segment/put.c
===================================================================
--- grass/trunk/lib/segment/put.c	2014-10-24 07:02:00 UTC (rev 62371)
+++ grass/trunk/lib/segment/put.c	2014-10-24 07:30:34 UTC (rev 62372)
@@ -46,8 +46,8 @@
 {
     int index, n, i;
 
-    SEG->Segment_address(SEG, row, col, &n, &index);
-    if ((i = Segment_pagein(SEG, n)) < 0) {
+    SEG->address(SEG, row, col, &n, &index);
+    if ((i = seg_pagein(SEG, n)) < 0) {
 	G_warning("segment lib: put: pagein failed");
 	return -1;
     }

Modified: grass/trunk/lib/segment/put_row.c
===================================================================
--- grass/trunk/lib/segment/put_row.c	2014-10-24 07:02:00 UTC (rev 62371)
+++ grass/trunk/lib/segment/put_row.c	2014-10-24 07:30:34 UTC (rev 62372)
@@ -56,8 +56,8 @@
     /*      printf("Segment_put_row ncols: %d, scols %d, size: %d, col %d, row: %d,  SEG->fd: %d\n",ncols,scols,size,col,row, SEG->fd); */
 
     for (col = 0; col < ncols; col += scols) {
-	SEG->Segment_address(SEG, row, col, &n, &index);
-	SEG->Segment_seek(SEG, n, index);
+	SEG->address(SEG, row, col, &n, &index);
+	SEG->seek(SEG, n, index);
 
 	if ((result = write(SEG->fd, buf, size)) != size) {
 	    G_warning("Segment_put_row write error %s", strerror(errno));
@@ -74,8 +74,8 @@
     }
 
     if ((size = SEG->spill * SEG->len)) {
-	SEG->Segment_address(SEG, row, col, &n, &index);
-	SEG->Segment_seek(SEG, n, index);
+	SEG->address(SEG, row, col, &n, &index);
+	SEG->seek(SEG, n, index);
 
 	if (write(SEG->fd, buf, size) != size) {
 	    G_warning("Segment_put_row final write error: %s",

Modified: grass/trunk/lib/segment/seek.c
===================================================================
--- grass/trunk/lib/segment/seek.c	2014-10-24 07:02:00 UTC (rev 62371)
+++ grass/trunk/lib/segment/seek.c	2014-10-24 07:30:34 UTC (rev 62372)
@@ -22,7 +22,9 @@
 
 
 /**
- * \brief Seek into a segment.
+ * \brief Internal use only
+ * 
+ * Seek into a segment.
  *
  * \param[in,out] SEG segment
  * \param[in] n
@@ -37,27 +39,27 @@
 #define SEG_SEEK_SLOW(SEG, n, index) \
     ((off_t) (n) * (SEG)->size + (index) + (SEG)->offset)
 
-int Segment_seek_fast(const SEGMENT * SEG, int n, int index)
+int seg_seek_fast(const SEGMENT * SEG, int n, int index)
 {
     if (lseek((SEG)->fd, SEG_SEEK_FAST(SEG, n, index), 
         SEEK_SET) == (off_t) -1) {
-	G_fatal_error("Segment_seek: %s", strerror(errno));
+	G_fatal_error("Segment seek: %s", strerror(errno));
     }
 
     return 0;
 }
 
-int Segment_seek_slow(const SEGMENT * SEG, int n, int index)
+int seg_seek_slow(const SEGMENT * SEG, int n, int index)
 {
     if (lseek((SEG)->fd, SEG_SEEK_SLOW(SEG, n, index), 
         SEEK_SET) == (off_t) -1) {
-	G_fatal_error("Segment_seek: %s", strerror(errno));
+	G_fatal_error("Segment seek: %s", strerror(errno));
     }
 
     return 0;
 }
 
-int Segment_seek(const SEGMENT * SEG, int n, int index)
+int seg_seek(const SEGMENT * SEG, int n, int index)
 {
-    return SEG->Segment_seek(SEG, n, index);
+    return SEG->seek(SEG, n, index);
 }

Modified: grass/trunk/lib/segment/setup.c
===================================================================
--- grass/trunk/lib/segment/setup.c	2014-10-24 07:02:00 UTC (rev 62371)
+++ grass/trunk/lib/segment/setup.c	2014-10-24 07:30:34 UTC (rev 62372)
@@ -20,10 +20,10 @@
 
 
 /**
- * \fn int Segment_setup (SEGMENT *SEG)
+ * \brief Internal use only
+ * 
+ * Setup segment.
  *
- * \brief Setup segment.
- *
  * <b>SEG</b> must have the following parms set:
  *  fd (open for read and write), nrows, ncols, srows, scols, len, nseg
  *
@@ -33,7 +33,7 @@
  * \return -2 if unable to allocate memory
  */
 
-int Segment_setup(SEGMENT * SEG)
+int seg_setup(SEGMENT * SEG)
 {
     int i;
     int seg_exp, n_total_segs;
@@ -43,7 +43,7 @@
     if (SEG->nrows <= 0 || SEG->ncols <= 0
 	|| SEG->srows <= 0 || SEG->scols <= 0
 	|| SEG->len <= 0 || SEG->nseg <= 0) {
-	G_warning("Segment_setup: illegal segment file parameters");
+	G_warning("Segment setup: illegal segment file parameters");
 	return -1;
     }
 
@@ -71,13 +71,13 @@
 	    SEG->srowbits = seg_exp;
 	    SEG->segbits = SEG->srowbits + SEG->scolbits;
 	    SEG->fast_adrs = 1;
-	    G_debug(1, "Segment_setup: fast address activated");
+	    G_debug(1, "Segment setup: fast address activated");
 	}
     }
     if (SEG->fast_adrs)
-	SEG->Segment_address = Segment_address_fast;
+	SEG->address = seg_address_fast;
     else
-	SEG->Segment_address = Segment_address_slow;
+	SEG->address = seg_address_slow;
     
     /* fast seek */
     SEG->fast_seek = 0;
@@ -89,25 +89,25 @@
 	    SEG->lenbits = seg_exp;
 	    SEG->sizebits = SEG->segbits + SEG->lenbits;
 	    SEG->fast_seek = 1;
-	    G_debug(1, "Segment_setup: fast seek activated");
+	    G_debug(1, "Segment setup: fast seek activated");
 	}
     }
     if (SEG->fast_seek)
-	SEG->Segment_seek = Segment_seek_fast;
+	SEG->seek = seg_seek_fast;
     else
-	SEG->Segment_seek = Segment_seek_slow;
+	SEG->seek = seg_seek_slow;
 
     /* adjust number of open segments if larger than number of total segments */
     n_total_segs = SEG->spr * ((SEG->nrows + SEG->srows - 1) / SEG->srows);
     if (SEG->nseg > n_total_segs) {
-	G_debug(1, "Segment_setup: reducing number of open segments from %d to %d",
+	G_debug(1, "Segment setup: reducing number of open segments from %d to %d",
 		  SEG->nseg, n_total_segs);
 	SEG->nseg = n_total_segs;
     }
 
     if ((SEG->scb =
-	 (struct Segment_SCB *)G_malloc(SEG->nseg *
-					sizeof(struct Segment_SCB))) == NULL)
+	 (struct scb *)G_malloc(SEG->nseg *
+					sizeof(struct scb))) == NULL)
 	return -2;
 
     if ((SEG->freeslot = (int *)G_malloc(SEG->nseg * sizeof(int))) == NULL)
@@ -148,15 +148,16 @@
     SEG->cur = 0;
     SEG->open = 1;
 
-    /* SEG->loaded = rbtree_create(Segment_compare, sizeof(SEGID)); */
+    /* index for each segment, same like cache of r.proj */
+
+    /* alternative using less memory: RB Tree */
+    /* SEG->loaded = rbtree_create(cmp, sizeof(SEGID)); */
     /* SEG->loaded = NULL; */
-    
-    /* index for each segment, same like cache of r.proj  */
+
     SEG->load_idx = G_malloc(n_total_segs * sizeof(int));
 
     for (i = 0; i < n_total_segs; i++)
 	SEG->load_idx[i] = -1;
-    
 
     return 1;
 }



More information about the grass-commit mailing list