Skip to contentSkip to conversation

libstats: replace data->size by data->index

PATCH In review Kiran 2 participants 2 messages Jul 31, 2009 – Aug 3, 2009

lore
Share & tools
lore

Kiran

author
#0 lore raw

PATCH 2/3 libstats: replace data->size by data->index

This patch replaces the occurrences of data->size by data->index+1 as the index starts with 0 and ends at data->size-1.
data->size holds the max size of the records list in data->container_t. data->index holds the index of the last record in the list. Since the records list may not be completely filled, data->index + 1 gives the total number of records currently in the list and it may not be equal to data->size.

testcases/realtime/lib/libstats.c +14 -13
diff -upr ltp-full-20090531_orig/testcases/realtime/lib/libstats.c ltp-full-20090531/testcases/realtime/lib/libstats.c
@@ -105,7 +105,7 @@ int stats_container_free(stats_container
 int stats_sort(stats_container_t *data, enum stats_sort_method method)
 {
 	// method not implemented, always ascending on y atm
-	qsort(data->records, data->size, sizeof(stats_record_t),
+	qsort(data->records, data->index + 1, sizeof(stats_record_t),
 	      stats_record_compare);
 	return 0;
 }
@@ -117,7 +117,7 @@ float stats_stddev(stats_container_t *da
 	long n;
 
 	sd = 0.0;
-	n = data->size;
+	n = data->index + 1;
 	sum = 0.0;
 
 	/* calculate the mean */
@@ -145,7 +145,7 @@ float stats_avg(stats_container_t *data)
 	float avg, sum;
 	long n;
 
-	n = data->size;
+	n = data->index + 1;
 	sum = 0.0;
 
 	/* calculate the mean */
@@ -163,7 +163,7 @@ long stats_min(stats_container_t *data)
 	long min;
 	long n;
 
-	n = data->size;
+	n = data->index + 1;
 
 	/* calculate the mean */
 	min = data->records[0].y;
@@ -182,7 +182,7 @@ long stats_max(stats_container_t *data)
 	long max;
 	long n;
 
-	n = data->size;
+	n = data->index + 1;
 
 	/* calculate the mean */
 	max = data->records[0].y;
@@ -223,16 +223,17 @@ int stats_quantiles_calc(stats_container
 	int index;
 
 	// check for sufficient data size of accurate calculation
-	if (data->size <= 0 || data->size < (long)exp10(quantiles->nines)) {
+	if (data->index < 0 || (data->index + 1) \
+	    < (long)exp10(quantiles->nines)) {
 		//printf("ERROR: insufficient data size for %d nines\n", data->size);
 		return -1;
 	}
 
-	size = data->size;
+	size = data->index + 1;
 	stats_sort(data, ASCENDING_ON_Y);
 
 	for (i = 2; i <= quantiles->nines; i++) {
-		index = data->size - data->size / exp10(i);
+		index = size - size / exp10(i);
 		quantiles->quantiles[i-2] = data->records[index].y;
 	}
 	return 0;
@@ -259,13 +260,13 @@ int stats_hist(stats_container_t *hist, 
 
 	ret = 0;
 
-	if (hist->size <= 0 || data->size <= 0) {
+	if (hist->size <= 0 || data->index < 0) {
 		return -1;
 	}
 
 	/* calculate the range of dataset */
 	min = max = data->records[0].y;
-	for (i = 0; i < data->size; i++) {
+	for (i = 0; i <= data->index; i++) {
 		y = data->records[i].y;
 		if (y > max) max = y;
 		if (y < min) min = y;
@@ -284,7 +285,7 @@ int stats_hist(stats_container_t *hist, 
 	}
 
 	/* fill in the counts */
-	for (i = 0; i < data->size; i++) {
+	for (i = 0; i <= data->index; i++) {
 		y = data->records[i].y;
 		b = MIN((y-min)/width, hist->size-1);
 		//printf("%d will go in bucket %d\n", y, b);
@@ -336,8 +337,8 @@ int stats_container_save(char *filename,
         return -1;
     } else {
         minx = maxx = data->records[0].x;
-        miny = maxy = data->records[0].y;
-        for (i = 0; i < data->size; i++) {
+	miny = maxy = data->records[0].y;
+	for (i = 0; i <= data->index; i++) {
             rec = &data->records[i];
             minx = MIN(minx, rec->x);
             maxx = MAX(maxx, rec->x);
Signature · 13 lines
Thanks,
Kiran


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#1 lore raw
Quoted 9 lines · Kiran

This patch replaces the occurrences of data->size by data->index+1 as the index starts with 0 and ends at data->size-1.
data->size holds the max size of the records list in data->container_t. data->index holds the index of the last record in the list. Since the records list may not be completely filled, data->index + 1 gives the total number of records currently in the list and it may not be equal to data->size.

Thanks.

Regards--
Subrata

Quoted 126 lines

diff -upr ltp-full-20090531_orig/testcases/realtime/lib/libstats.c ltp-full-20090531/testcases/realtime/lib/libstats.c

testcases/realtime/lib/libstats.c +14 -13
@@ -105,7 +105,7 @@ int stats_container_free(stats_container
 int stats_sort(stats_container_t *data, enum stats_sort_method method)
 {
 	// method not implemented, always ascending on y atm
-	qsort(data->records, data->size, sizeof(stats_record_t),
+	qsort(data->records, data->index + 1, sizeof(stats_record_t),
 	      stats_record_compare);
 	return 0;
 }
@@ -117,7 +117,7 @@ float stats_stddev(stats_container_t *da
 	long n;
 
 	sd = 0.0;
-	n = data->size;
+	n = data->index + 1;
 	sum = 0.0;
 
 	/* calculate the mean */
@@ -145,7 +145,7 @@ float stats_avg(stats_container_t *data)
 	float avg, sum;
 	long n;
 
-	n = data->size;
+	n = data->index + 1;
 	sum = 0.0;
 
 	/* calculate the mean */
@@ -163,7 +163,7 @@ long stats_min(stats_container_t *data)
 	long min;
 	long n;
 
-	n = data->size;
+	n = data->index + 1;
 
 	/* calculate the mean */
 	min = data->records[0].y;
@@ -182,7 +182,7 @@ long stats_max(stats_container_t *data)
 	long max;
 	long n;
 
-	n = data->size;
+	n = data->index + 1;
 
 	/* calculate the mean */
 	max = data->records[0].y;
@@ -223,16 +223,17 @@ int stats_quantiles_calc(stats_container
 	int index;
 
 	// check for sufficient data size of accurate calculation
-	if (data->size <= 0 || data->size < (long)exp10(quantiles->nines)) {
+	if (data->index < 0 || (data->index + 1) \
+	    < (long)exp10(quantiles->nines)) {
 		//printf("ERROR: insufficient data size for %d nines\n", data->size);
 		return -1;
 	}
 
-	size = data->size;
+	size = data->index + 1;
 	stats_sort(data, ASCENDING_ON_Y);
 
 	for (i = 2; i <= quantiles->nines; i++) {
-		index = data->size - data->size / exp10(i);
+		index = size - size / exp10(i);
 		quantiles->quantiles[i-2] = data->records[index].y;
 	}
 	return 0;
@@ -259,13 +260,13 @@ int stats_hist(stats_container_t *hist, 
 
 	ret = 0;
 
-	if (hist->size <= 0 || data->size <= 0) {
+	if (hist->size <= 0 || data->index < 0) {
 		return -1;
 	}
 
 	/* calculate the range of dataset */
 	min = max = data->records[0].y;
-	for (i = 0; i < data->size; i++) {
+	for (i = 0; i <= data->index; i++) {
 		y = data->records[i].y;
 		if (y > max) max = y;
 		if (y < min) min = y;
@@ -284,7 +285,7 @@ int stats_hist(stats_container_t *hist, 
 	}
 
 	/* fill in the counts */
-	for (i = 0; i < data->size; i++) {
+	for (i = 0; i <= data->index; i++) {
 		y = data->records[i].y;
 		b = MIN((y-min)/width, hist->size-1);
 		//printf("%d will go in bucket %d\n", y, b);
@@ -336,8 +337,8 @@ int stats_container_save(char *filename,
         return -1;
     } else {
         minx = maxx = data->records[0].x;
-        miny = maxy = data->records[0].y;
-        for (i = 0; i < data->size; i++) {
+	miny = maxy = data->records[0].y;
+	for (i = 0; i <= data->index; i++) {
             rec = &data->records[i];
             minx = MIN(minx, rec->x);
             maxx = MAX(maxx, rec->x);
Signature · 15 lines
-- 

Thanks,
Kiran


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list