unmacroize update_sample_*plot() #1976

This commit is contained in:
nick black 2021-08-01 23:17:20 -04:00 committed by nick black
parent ba830418c7
commit 67812559d5

View File

@ -348,17 +348,6 @@ int window_slide_##T(nc##X##plot* ncp, int64_t x){ \
return 0; \ return 0; \
} \ } \
\ \
/* x must be within n's window at this point */ \
void update_sample_##T(nc##X##plot* ncp, int64_t x, T y, bool reset){ \
const int64_t diff = ncp->plot.slotx - x; /* amount behind */ \
const int idx = (ncp->plot.slotstart + ncp->plot.slotcount - diff) % ncp->plot.slotcount; \
if(reset){ \
ncp->slots[idx] = y; \
}else{ \
ncp->slots[idx] += y; \
} \
} \
\
/* if we're doing domain detection, update the domain to reflect the value we \ /* if we're doing domain detection, update the domain to reflect the value we \
just set. if we're not, check the result against the known ranges, and \ just set. if we're not, check the result against the known ranges, and \
return -1 if the value is outside of that range. */ \ return -1 if the value is outside of that range. */ \
@ -380,6 +369,9 @@ int update_domain_##T(nc##X##plot* ncp, uint64_t x){ \
} \ } \
return 0; \ return 0; \
} \ } \
\
static void update_sample_##T(nc##X##plot* ncp, int64_t x, T y, bool reset); \
\
int set_sample_##T(nc##X##plot* ncpp, uint64_t x, T y){ \ int set_sample_##T(nc##X##plot* ncpp, uint64_t x, T y){ \
if(window_slide_##T(ncpp, x)){ \ if(window_slide_##T(ncpp, x)){ \
return -1; \ return -1; \
@ -422,6 +414,30 @@ void destroy_##T(nc##X##plot* ncpp){ \
CREATE(uint64_t, u) CREATE(uint64_t, u)
CREATE(double, d) CREATE(double, d)
/* x must be within n's window at this point */
static void
update_sample_uint64_t(ncuplot* ncp, int64_t x, uint64_t y, bool reset){
const int64_t diff = ncp->plot.slotx - x; /* amount behind */
const int idx = (ncp->plot.slotstart + ncp->plot.slotcount - diff) % ncp->plot.slotcount;
if(reset){
ncp->slots[idx] = y;
}else{
ncp->slots[idx] += y;
}
}
/* x must be within n's window at this point */
static void
update_sample_double(ncdplot* ncp, int64_t x, double y, bool reset){
const int64_t diff = ncp->plot.slotx - x; /* amount behind */
const int idx = (ncp->plot.slotstart + ncp->plot.slotcount - diff) % ncp->plot.slotcount;
if(reset){
ncp->slots[idx] = y;
}else{
ncp->slots[idx] += y;
}
}
// takes ownership of n on all paths // takes ownership of n on all paths
ncuplot* ncuplot_create(ncplane* n, const ncplot_options* opts, uint64_t miny, uint64_t maxy){ ncuplot* ncuplot_create(ncplane* n, const ncplot_options* opts, uint64_t miny, uint64_t maxy){
ncuplot* ret = malloc(sizeof(*ret)); ncuplot* ret = malloc(sizeof(*ret));