feat: add development environment configuration and Docker setup
This commit is contained in:
+37
-1
@@ -131,6 +131,42 @@ export const sse = new EventSourceManager();
|
||||
|
||||
export const b2s = (t: number) => {
|
||||
let e = (Math.log2(t) / 10) | 0;
|
||||
// biome-ignore lint/suspicious/noAssignInExpressions: copied
|
||||
return `${(t / 1024 ** (e = e <= 0 ? 0 : e)).toFixed(1)}${" KMGP"[e]}B`;
|
||||
};
|
||||
|
||||
type Node = { count: number; next: Map<string, Node> };
|
||||
|
||||
function node(): Node {
|
||||
return { count: 0, next: new Map() };
|
||||
}
|
||||
|
||||
// find unique shortest code for each string
|
||||
export function shortestPrefixes(values: readonly string[]) {
|
||||
const uniq = [...new Set(values)];
|
||||
const root = node();
|
||||
|
||||
for (const v of uniq) {
|
||||
let cur = root;
|
||||
for (const ch of v) {
|
||||
let n = cur.next.get(ch);
|
||||
if (!n) cur.next.set(ch, (n = node()));
|
||||
n.count++;
|
||||
cur = n;
|
||||
}
|
||||
}
|
||||
|
||||
const res = new Map<string, string>();
|
||||
for (const v of uniq) {
|
||||
let cur = root;
|
||||
let prefix = "";
|
||||
for (const ch of v) {
|
||||
const n = cur.next.get(ch)!;
|
||||
prefix += ch;
|
||||
if (n.count === 1) break;
|
||||
cur = n;
|
||||
}
|
||||
res.set(v, prefix);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user