Skip to content

Commit d18691d

Browse files
committed
fix: cannot sort using bigint returns
1 parent a968a11 commit d18691d

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

packages/core/src/binary/binary.index.builder.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,15 @@ export const CotarIndexBuilder = {
8282
currentTime = Date.now();
8383
for (const file of files) file.index = Number(BigInt(file.hash) % BigInt(slotCount));
8484
files.sort((a, b) => {
85-
let ret = a.index - b.index;
86-
if (ret === 0) ret = a.offset - b.offset;
87-
if (ret === 0) return a.hash - b.hash;
88-
return ret;
85+
const indexDiff = a.index - b.index;
86+
if (indexDiff !== 0) return indexDiff;
87+
88+
const offsetDiff = a.offset - b.offset;
89+
if (offsetDiff !== 0) return offsetDiff;
90+
91+
// Hashes can not collide so a.hash must be > or < b.hash
92+
if (a.hash > b.hash) return 1;
93+
return -1;
8994
});
9095
logger?.debug({ duration: Date.now() - currentTime }, 'Cotar.index:Hash');
9196

0 commit comments

Comments
 (0)