mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-25 18:50:56 +02:00
CODEBASE: Fix lint errors 2 (#1756)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// choose random character for generating plaintexts to compress
|
||||
// choose random characters for generating plaintext to compress
|
||||
export function comprGenChar(): string {
|
||||
const r = Math.random();
|
||||
if (r < 0.4) {
|
||||
@@ -34,13 +34,13 @@ export function comprLZGenerate(): string {
|
||||
return plain.substring(0, length);
|
||||
}
|
||||
|
||||
// compress plaintest string
|
||||
// compress plaintext string
|
||||
export function comprLZEncode(plain: string): string {
|
||||
// for state[i][j]:
|
||||
// if i is 0, we're adding a literal of length j
|
||||
// else, we're adding a backreference of offset i and length j
|
||||
let cur_state: (string | null)[][] = Array.from(Array(10), () => Array(10).fill(null));
|
||||
let new_state: (string | null)[][] = Array.from(Array(10), () => Array(10));
|
||||
let cur_state: (string | null)[][] = Array.from(Array(10), () => Array<string | null>(10).fill(null));
|
||||
let new_state: (string | null)[][] = Array.from(Array(10), () => Array<string | null>(10));
|
||||
|
||||
function set(state: (string | null)[][], i: number, j: number, str: string): void {
|
||||
const current = state[i][j];
|
||||
|
||||
@@ -3,7 +3,7 @@ import { Terminal } from "../Terminal";
|
||||
const deprecatedWarningsGiven = new Set();
|
||||
export function setDeprecatedProperties(
|
||||
obj: object,
|
||||
properties: Record<string, { identifier: string; message: string; value: any }>,
|
||||
properties: Record<string, { identifier: string; message: string; value: unknown }>,
|
||||
) {
|
||||
for (const [name, info] of Object.entries(properties)) {
|
||||
Object.defineProperty(obj, name, {
|
||||
@@ -11,7 +11,7 @@ export function setDeprecatedProperties(
|
||||
deprecationWarning(info.identifier, info.message);
|
||||
return info.value;
|
||||
},
|
||||
set: (value: any) => (info.value = value),
|
||||
set: (value: unknown) => (info.value = value),
|
||||
enumerable: true,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import * as allEnums from "../Enums";
|
||||
import { assertString } from "../Netscript/TypeAssertion";
|
||||
import { errorMessage } from "../Netscript/ErrorMessages";
|
||||
import { getRandomIntInclusive } from "./helpers/getRandomIntInclusive";
|
||||
import { getRecordValues } from "../Types/Record";
|
||||
|
||||
interface GetMemberOptions {
|
||||
/** Whether to use fuzzy matching on the input (case insensitive, ignore spaces and dashes) */
|
||||
@@ -22,7 +23,7 @@ class EnumHelper<EnumObj extends object, EnumMember extends Member<EnumObj> & st
|
||||
constructor(obj: EnumObj, name: string) {
|
||||
this.name = name;
|
||||
this.defaultArgName = name.charAt(0).toLowerCase() + name.slice(1);
|
||||
this.valueArray = Object.values(obj);
|
||||
this.valueArray = getRecordValues(obj);
|
||||
this.valueSet = new Set(this.valueArray);
|
||||
this.fuzzMap = new Map(this.valueArray.map((val) => [val.toLowerCase().replace(/[ -]+/g, ""), val]));
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
export function HammingEncode(data: number): string {
|
||||
const enc: number[] = [0];
|
||||
const data_bits: any[] = data.toString(2).split("").reverse();
|
||||
|
||||
data_bits.forEach((e, i, a) => {
|
||||
a[i] = parseInt(e);
|
||||
});
|
||||
const data_bits: number[] = data
|
||||
.toString(2)
|
||||
.split("")
|
||||
.reverse()
|
||||
.map((value) => parseInt(value));
|
||||
|
||||
let k = data_bits.length;
|
||||
|
||||
@@ -18,35 +18,36 @@ export function HammingEncode(data: number): string {
|
||||
}
|
||||
}
|
||||
|
||||
let parity: any = 0;
|
||||
let parityNumber = 0;
|
||||
|
||||
/* Figure out the subsection parities */
|
||||
for (let i = 0; i < enc.length; i++) {
|
||||
if (enc[i]) {
|
||||
parity ^= i;
|
||||
parityNumber ^= i;
|
||||
}
|
||||
}
|
||||
|
||||
parity = parity.toString(2).split("").reverse();
|
||||
parity.forEach((e: any, i: any, a: any) => {
|
||||
a[i] = parseInt(e);
|
||||
});
|
||||
const parityArray = parityNumber
|
||||
.toString(2)
|
||||
.split("")
|
||||
.reverse()
|
||||
.map((value) => parseInt(value));
|
||||
|
||||
/* Set the parity bits accordingly */
|
||||
for (let i = 0; i < parity.length; i++) {
|
||||
enc[2 ** i] = parity[i] ? 1 : 0;
|
||||
for (let i = 0; i < parityArray.length; i++) {
|
||||
enc[2 ** i] = parityArray[i] ? 1 : 0;
|
||||
}
|
||||
|
||||
parity = 0;
|
||||
parityNumber = 0;
|
||||
/* Figure out the overall parity for the entire block */
|
||||
for (let i = 0; i < enc.length; i++) {
|
||||
if (enc[i]) {
|
||||
parity++;
|
||||
parityNumber++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Finally set the overall parity bit */
|
||||
enc[0] = parity % 2 == 0 ? 0 : 1;
|
||||
enc[0] = parityNumber % 2 == 0 ? 0 : 1;
|
||||
|
||||
return enc.join("");
|
||||
}
|
||||
@@ -68,11 +69,11 @@ export function HammingEncodeProperly(data: number): string {
|
||||
const k: number = 2 ** m - m - 1;
|
||||
|
||||
const enc: number[] = [0];
|
||||
const data_bits: any[] = data.toString(2).split("").reverse();
|
||||
|
||||
data_bits.forEach((e, i, a) => {
|
||||
a[i] = parseInt(e);
|
||||
});
|
||||
const data_bits: number[] = data
|
||||
.toString(2)
|
||||
.split("")
|
||||
.reverse()
|
||||
.map((value) => parseInt(value));
|
||||
|
||||
/* Flip endianness as in the original implementation by Hedrauta
|
||||
* and write the data back to front
|
||||
@@ -83,35 +84,36 @@ export function HammingEncodeProperly(data: number): string {
|
||||
}
|
||||
}
|
||||
|
||||
let parity: any = 0;
|
||||
let parityNumber = 0;
|
||||
|
||||
/* Figure out the subsection parities */
|
||||
for (let i = 0; i < n; i++) {
|
||||
if (enc[i]) {
|
||||
parity ^= i;
|
||||
parityNumber ^= i;
|
||||
}
|
||||
}
|
||||
|
||||
parity = parity.toString(2).split("").reverse();
|
||||
parity.forEach((e: any, i: any, a: any) => {
|
||||
a[i] = parseInt(e);
|
||||
});
|
||||
const parityArray = parityNumber
|
||||
.toString(2)
|
||||
.split("")
|
||||
.reverse()
|
||||
.map((value) => parseInt(value));
|
||||
|
||||
/* Set the parity bits accordingly */
|
||||
for (let i = 0; i < m; i++) {
|
||||
enc[2 ** i] = parity[i] ? 1 : 0;
|
||||
enc[2 ** i] = parityArray[i] ? 1 : 0;
|
||||
}
|
||||
|
||||
parity = 0;
|
||||
parityNumber = 0;
|
||||
/* Figure out the overall parity for the entire block */
|
||||
for (let i = 0; i < n; i++) {
|
||||
if (enc[i]) {
|
||||
parity++;
|
||||
parityNumber++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Finally set the overall parity bit */
|
||||
enc[0] = parity % 2 == 0 ? 0 : 1;
|
||||
enc[0] = parityNumber % 2 == 0 ? 0 : 1;
|
||||
|
||||
return enc.join("");
|
||||
}
|
||||
@@ -121,8 +123,9 @@ export function HammingDecode(data: string): number {
|
||||
const bits: number[] = [];
|
||||
|
||||
/* TODO why not just work with an array of digits from the start? */
|
||||
for (const i in data.split("")) {
|
||||
const bit = parseInt(data[i]);
|
||||
const bitStringArray = data.split("");
|
||||
for (let i = 0; i < bitStringArray.length; ++i) {
|
||||
const bit = parseInt(bitStringArray[i]);
|
||||
bits[i] = bit;
|
||||
|
||||
if (bit) {
|
||||
|
||||
@@ -125,3 +125,9 @@ export function getNsApiDocumentationUrl(isDevBranch: boolean = CONSTANTS.isDevB
|
||||
isDevBranch ? "dev" : "stable"
|
||||
}/markdown/bitburner.ns.md`;
|
||||
}
|
||||
|
||||
export function getKeyFromReactElements(a: string | React.JSX.Element, b: string | React.JSX.Element): string {
|
||||
const keyOfA = typeof a === "string" ? a : a.key ?? "";
|
||||
const keyOfb = typeof b === "string" ? b : b.key ?? "";
|
||||
return keyOfA + keyOfb;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
export function throwIfReachable(missingCase: never) {
|
||||
throw new Error(`The case of ${missingCase} was not handled.`);
|
||||
}
|
||||
Reference in New Issue
Block a user