6b80663a8dd1cfde9d076fa09ff3cecbec527035 kent Sat Jan 30 11:46:34 2021 -0800 Added routine that will calc max of items in a column since it might be reusued. diff --git src/lib/fieldedTable.c src/lib/fieldedTable.c index 79a4658..0166c17 100644 --- src/lib/fieldedTable.c +++ src/lib/fieldedTable.c @@ -1,27 +1,28 @@ /* fieldedTable - a table composed of untyped strings in memory. Includes names for each * field. This is a handy way of storing small-to-medium tab-separated files that begin * with a "#list of fields" line among other things. */ /* Copyright (C) 2013 The Regents of the University of California * See README in this or parent directory for licensing information. */ #include "common.h" #include "localmem.h" #include "linefile.h" #include "hash.h" #include "fieldedTable.h" +#include "sqlNum.h" #include "net.h" struct fieldedTable *fieldedTableNew(char *name, char **fields, int fieldCount) /* Create a new empty fieldedTable with given name, often a file name. */ { struct fieldedTable *table; AllocVar(table); struct lm *lm = table->lm = lmInit(0); table->name = lmCloneString(lm, name); table->cursor = &table->rowList; table->fieldCount = fieldCount; int i; char **row = lmAllocArray(lm, table->fields, fieldCount); for (i=0; i<fieldCount; ++i) { @@ -118,30 +119,51 @@ struct fieldedRow *fr; boolean anyVals = FALSE; for (fr = table->rowList; fr != NULL; fr = fr->next) { char *s = fr->row[fieldIx]; if (s != NULL) { anyVals = TRUE; if (!isNumericString(s)) return FALSE; } } return anyVals; } +double fieldedTableMaxInCol(struct fieldedTable *table, int colIx) +/* Figure out total and count columns from context and use them to figure + * out maximum mean value */ +{ +boolean firstTime = TRUE; +double max = 0.0; +struct fieldedRow *fr; +for (fr = table->rowList; fr != NULL; fr = fr->next) + { + double val = sqlDouble(fr->row[colIx]); + if (firstTime) + { + max = val; + firstTime = FALSE; + } + else if (max < val) + max = val; + } +return max; +} + static int slPairCmpNumbers(const void *va, const void *vb) /* Compare slPairs where name is interpreted as floating point number */ { const struct slPair *a = *((struct slPair **)va); const struct slPair *b = *((struct slPair **)vb); double aVal = atof(a->name); double bVal = atof(b->name); double diff = aVal - bVal; if (diff < 0) return -1; else if (diff > 0) return 1; else return 0; }