File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -82,10 +82,15 @@ export const CotarIndexBuilder = {
82
82
currentTime = Date . now ( ) ;
83
83
for ( const file of files ) file . index = Number ( BigInt ( file . hash ) % BigInt ( slotCount ) ) ;
84
84
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 ;
89
94
} ) ;
90
95
logger ?. debug ( { duration : Date . now ( ) - currentTime } , 'Cotar.index:Hash' ) ;
91
96
You can’t perform that action at this time.
0 commit comments