mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 03:59:50 +02:00
seed basing
This commit is contained in:
1 parent
389052c692
commit
81856276b0
1 file changed
+40
-13
@@ -1,5 +1,5 @@
|
|||||||
import { $ } from "bun";
|
import { $ } from "bun";
|
||||||
import { compress, uncompress } from "lz4-napi";
|
import { compress, decompress } from "lz4js";
|
||||||
import { mkdir, rm } from "node:fs/promises";
|
import { mkdir, rm } from "node:fs/promises";
|
||||||
import { IdArray } from "./idArray";
|
import { IdArray } from "./idArray";
|
||||||
|
|
||||||
@@ -25,6 +25,10 @@ console.log(
|
|||||||
`${chunkCount.toLocaleString()} will be needed for ${ACCOMMODATED_ID_COUNT.toLocaleString()} ids`,
|
`${chunkCount.toLocaleString()} will be needed for ${ACCOMMODATED_ID_COUNT.toLocaleString()} ids`,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const t0 = performance.now();
|
||||||
|
const maxT = 5 * 60 * 60 * 1000;
|
||||||
|
const t1 = t0 + maxT;
|
||||||
|
|
||||||
await mkdir(TEMP, { recursive: true });
|
await mkdir(TEMP, { recursive: true });
|
||||||
await rm(WORKING_DIR, { recursive: true, force: true });
|
await rm(WORKING_DIR, { recursive: true, force: true });
|
||||||
|
|
||||||
@@ -44,9 +48,9 @@ for (let i = 0; true; i++) {
|
|||||||
if (!(await file.exists())) break;
|
if (!(await file.exists())) break;
|
||||||
|
|
||||||
const bytes = await file.bytes();
|
const bytes = await file.bytes();
|
||||||
const uncompressed = await uncompress(bytes);
|
const uncompressed = decompress(bytes);
|
||||||
|
|
||||||
const ids = IdArray.fromBytes(new Uint8Array(uncompressed));
|
const ids = IdArray.fromBytes(uncompressed);
|
||||||
|
|
||||||
discoveredChunks.push(ids);
|
discoveredChunks.push(ids);
|
||||||
}
|
}
|
||||||
@@ -78,20 +82,49 @@ if (discoveredChunks.length === chunkCount) {
|
|||||||
discoveredChunks[i] = null;
|
discoveredChunks[i] = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
await rm(`${CHUNKS_DIR}/*`, { force: true });
|
console.log("Sorting chunks...");
|
||||||
|
|
||||||
|
for (let i = 0; i < chunks.length; i++) chunks[i].sort();
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("Sorting chunks...");
|
const regions = [
|
||||||
|
{ domain: "eu", seed: 5e8, max: 10e8 - 1 },
|
||||||
|
{ domain: "com", seed: 10e8, max: 20e8 - 1 },
|
||||||
|
{ domain: "asia", seed: 20e8, max: 31e8 - 1 },
|
||||||
|
];
|
||||||
|
|
||||||
for (let i = 0; i < chunks.length; i++) chunks[i].sort();
|
console.log("Finding new seed ids...");
|
||||||
|
|
||||||
|
for (let i = 0; i < chunkCount; i++) {
|
||||||
|
const chunk = chunks[i];
|
||||||
|
const size = chunk.size();
|
||||||
|
|
||||||
|
for (let j = 0; j < size; j++) {
|
||||||
|
const id = chunk.get(j);
|
||||||
|
|
||||||
|
for (const region of regions) {
|
||||||
|
if (id <= region.max && id >= region.seed) {
|
||||||
|
region.seed = id + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("Found seeds:");
|
||||||
|
|
||||||
|
for (const region of regions) {
|
||||||
|
console.log(` ${region.domain}: ${region.seed.toLocaleString()}`);
|
||||||
|
}
|
||||||
|
|
||||||
console.log("Saving chunks...");
|
console.log("Saving chunks...");
|
||||||
|
|
||||||
|
await rm(`${CHUNKS_DIR}/*`, { force: true });
|
||||||
|
|
||||||
for (let i = 0; i < chunks.length; i++) {
|
for (let i = 0; i < chunks.length; i++) {
|
||||||
const path = `${CHUNKS_DIR}/chunk-${i}.dat.lz4`;
|
const path = `${CHUNKS_DIR}/chunk-${i}.dat.lz4`;
|
||||||
const chunk = chunks[i];
|
const chunk = chunks[i];
|
||||||
const bytes = chunk.toBytes();
|
const bytes = chunk.toBytes();
|
||||||
const compressed = await compress(bytes);
|
const compressed = compress(bytes);
|
||||||
|
|
||||||
await Bun.write(path, compressed);
|
await Bun.write(path, compressed);
|
||||||
}
|
}
|
||||||
@@ -99,8 +132,6 @@ for (let i = 0; i < chunks.length; i++) {
|
|||||||
// const MAX_IDS = 100;
|
// const MAX_IDS = 100;
|
||||||
// const API_RATE = 10;
|
// const API_RATE = 10;
|
||||||
|
|
||||||
// const BYTES_PER_ID = 64 / 8;
|
|
||||||
|
|
||||||
// const regions = ["eu", "com", "asia"];
|
// const regions = ["eu", "com", "asia"];
|
||||||
// const seeds = [5e8, 10e8, 20e8].map(BigInt);
|
// const seeds = [5e8, 10e8, 20e8].map(BigInt);
|
||||||
|
|
||||||
@@ -111,10 +142,6 @@ for (let i = 0; i < chunks.length; i++) {
|
|||||||
|
|
||||||
// const ids: bigint[] = [];
|
// const ids: bigint[] = [];
|
||||||
|
|
||||||
// const t0 = performance.now();
|
|
||||||
// const maxT = 5 * 60 * 60 * 1000;
|
|
||||||
// const t1 = t0 + maxT;
|
|
||||||
|
|
||||||
// const unfilled = Array.from({ length: seeds.length });
|
// const unfilled = Array.from({ length: seeds.length });
|
||||||
// const offsets = unfilled.map(() => 0n);
|
// const offsets = unfilled.map(() => 0n);
|
||||||
// const queues = unfilled.map(() => [] as bigint[]);
|
// const queues = unfilled.map(() => [] as bigint[]);
|
||||||
|
|||||||
Reference in new issue
Block a user