Unverified Commit a39df508 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Remove extra exports from filter utils (#46860)

These utilities aren't needed so can be removed
parent 8f5ffed7
...@@ -61,34 +61,6 @@ export interface TwoHashesIntAndString { ...@@ -61,34 +61,6 @@ export interface TwoHashesIntAndString {
*/ */
export type HashableInput = string | ArrayBuffer | Buffer export type HashableInput = string | ArrayBuffer | Buffer
/**
* BufferError
*/
export const BufferError =
'The buffer class must be available, if you are a browser user use the buffer package (https://www.npmjs.com/package/buffer)'
/**
* Create a new array fill with a base value
* @param size - The size of the array
* @param defaultValue - The default value used to fill the array. If it's a function, it will be invoked to get the default value.
* @return A newly allocated array
* @memberof Utils
*/
export function allocateArray<T>(
size: number,
defaultValue: T | (() => T)
): Array<T> {
const array: Array<T> = new Array<T>(size)
const getDefault =
typeof defaultValue === 'function'
? (defaultValue as () => T)
: () => defaultValue
for (let ind = 0; ind < size; ind++) {
array[ind] = getDefault()
}
return array
}
/** /**
* Return a number to its Hex format by padding zeroes if length mod 4 != 0 * Return a number to its Hex format by padding zeroes if length mod 4 != 0
* @param elem the element to transform in HEX * @param elem the element to transform in HEX
...@@ -125,52 +97,6 @@ export function randomInt( ...@@ -125,52 +97,6 @@ export function randomInt(
return Math.floor(rn * (max - min + 1)) + min return Math.floor(rn * (max - min + 1)) + min
} }
/**
* Return the non-destructive XOR of two buffers
* @param a - The buffer to copy, then to xor with b
* @param b - The buffer to xor with
* @return The results of the XOR between the two buffers
* @author Arnaud Grall
*/
export function xorBuffer(a: Buffer, b: Buffer): Buffer {
const length = Math.max(a.length, b.length)
const buffer = Buffer.allocUnsafe(length).fill(0)
for (let i = 0; i < length; ++i) {
if (i < a.length && i < b.length) {
buffer[length - i - 1] = a[a.length - i - 1] ^ b[b.length - i - 1]
} else if (i < a.length && i >= b.length) {
buffer[length - i - 1] ^= a[a.length - i - 1]
} else if (i < b.length && i >= a.length) {
buffer[length - i - 1] ^= b[b.length - i - 1]
}
}
// now need to remove leading zeros in the buffer if any
let start = 0
const it = buffer.values()
let value = it.next()
while (!value.done && value.value === 0) {
start++
value = it.next()
}
return buffer.slice(start)
}
/**
* Return true if the buffer is empty, i.e., all value are equals to 0.
* @param buffer - The buffer to inspect
* @return True if the buffer only contains zero, False otherwise
* @author Arnaud Grall
*/
export function isEmptyBuffer(buffer: Buffer | null): boolean {
if (buffer === null || !buffer) return true
for (const value of buffer) {
if (value !== 0) {
return false
}
}
return true
}
/** /**
* Return the default seed used in the package * Return the default seed used in the package
* @return A seed as a floating point number * @return A seed as a floating point number
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment