Alien-libhisto
view release on metacpan or search on metacpan
bundled/tools/src/tui_engine.c view on Meta::CPAN
static int double_cmp(const void *a, const void *b) {
double da = *(const double *)a;
double db = *(const double *)b;
if (isnan(da)) return isnan(db) ? 0 : 1;
if (isnan(db)) return -1;
if (da < db) return -1;
if (da > db) return 1;
return 0;
}
static bool tui_engine_check_and_autorange_locked(tui_engine_t *eng) {
if (!eng || !eng->auto_range || !eng->live_1d || eng->reservoir.count < 50) {
return false;
}
double now = get_time_now_sec();
if (now - eng->last_autorange_time_sec < 1.0) {
return false;
}
double in_range_w = histo_total_weight(eng->live_1d);
bundled/tools/src/tui_engine.c view on Meta::CPAN
eng->live_1d = new_h;
free(tmp_x);
free(tmp_w);
return true;
}
bool tui_engine_check_and_autorange(tui_engine_t *eng) {
if (!eng) return false;
histo_mutex_lock(&eng->mutex);
bool changed = tui_engine_check_and_autorange_locked(eng);
histo_mutex_unlock(&eng->mutex);
return changed;
}
void tui_engine_set_autorange(tui_engine_t *eng, bool enable, double threshold) {
if (!eng) return;
histo_mutex_lock(&eng->mutex);
eng->auto_range = enable;
if (threshold > 0.0) eng->auto_range_threshold = threshold;
histo_mutex_unlock(&eng->mutex);
}
histo_t *tui_engine_get_snapshot_1d(tui_engine_t *eng) {
if (!eng) return NULL;
histo_mutex_lock(&eng->mutex);
tui_engine_check_and_autorange_locked(eng);
histo_t *snap = eng->live_1d ? histo_clone(eng->live_1d, false) : NULL;
histo_mutex_unlock(&eng->mutex);
return snap;
}
histo2d_t *tui_engine_get_snapshot_2d(tui_engine_t *eng) {
if (!eng) return NULL;
histo_mutex_lock(&eng->mutex);
histo2d_t *snap = eng->live_2d ? histo2d_clone(eng->live_2d, false) : NULL;
histo_mutex_unlock(&eng->mutex);
( run in 1.832 second using v1.01-cache-2.11-cpan-800906f7e73 )