From 7d120b7939aa5bae68dbb5fc2f877cc8220c6929 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Mon, 27 Mar 2023 00:18:01 -0700 Subject: make prioritisation behaviour more configurable --- backomp | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/backomp b/backomp index 750576b..aba6450 100755 --- a/backomp +++ b/backomp @@ -6,13 +6,16 @@ set -e function flr(n, s) { return int(n / s) * s } BEGIN { - split("h d w m", buckets) - for (i in buckets) { - if (match(retain, "([*0-9]+)" buckets[i], md) && md[1]) - ret[buckets[i]] = md[1] + split("h d w m", arr) + for (i = 1; i <= length(arr); ++i) { + b = arr[i] - if (index(replace, buckets[i])) - repl[buckets[i]] = 1 + if (!match(retain, "([*0-9]+)" b, md)) + continue + ret[b] = md[1] + buckets[++n_buckets] = b + + repl[b] = !!index(replace, b) } } @@ -25,14 +28,22 @@ BEGIN { bt["m"] = mktime(strftime("%Y %m", t, 1) " 01 00 00 00", 1) bt["w"] = bt["m"] + flr(t - bt["m"], 7*24*60*60) - for (i = 1; i <= length(buckets); ++i) { + for (i = 1; i <= n_buckets; ++i) { b = buckets[i] - if (!ret[b] || (b in repl && (b, bt[b]) in bkeep)) - continue + if (skip = (repl[b] && bt[b] == last[b, b])) { + for (j = 1; j < i; ++j) { + skip = (bt[buckets[j]] != last[b, buckets[j]]) + if (!skip) break + } + if (skip) next + } if ((b, bt[b]) in bkeep || ret[b] == "*" || bc[b]++ < ret[b]) bkeep[b, bt[b]] = $1 + + for (j in buckets) + last[b, buckets[j]] = bt[buckets[j]] } } -- cgit v1.2.3-70-g09d2