Buckets:
| export namespace Binary { | |
| export function search<T>(array: T[], id: string, compare: (item: T) => string): { found: boolean; index: number } { | |
| let left = 0 | |
| let right = array.length - 1 | |
| while (left <= right) { | |
| const mid = Math.floor((left + right) / 2) | |
| const midId = compare(array[mid]) | |
| if (midId === id) { | |
| return { found: true, index: mid } | |
| } else if (midId < id) { | |
| left = mid + 1 | |
| } else { | |
| right = mid - 1 | |
| } | |
| } | |
| return { found: false, index: left } | |
| } | |
| export function insert<T>(array: T[], item: T, compare: (item: T) => string): T[] { | |
| const id = compare(item) | |
| let left = 0 | |
| let right = array.length | |
| while (left < right) { | |
| const mid = Math.floor((left + right) / 2) | |
| const midId = compare(array[mid]) | |
| if (midId < id) { | |
| left = mid + 1 | |
| } else { | |
| right = mid | |
| } | |
| } | |
| array.splice(left, 0, item) | |
| return array | |
| } | |
| } | |
Xet Storage Details
- Size:
- 968 Bytes
- Xet hash:
- 656552564c5a3f3143576ba1b2af86e20060c3e444f534ca5fe95abb66cdc997
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.