Skip to content

Commit

Permalink
chore: lint code per updated lint rules from package update
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewkeil committed Dec 20, 2024
1 parent c3b0b87 commit dea9709
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 53 deletions.
40 changes: 20 additions & 20 deletions packages/persistent-merkle-tree/src/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,39 @@ export class BranchNode extends Node {
return hashObjectToUint8Array(this.rootHashObject);
}

isLeaf(): boolean {
return false;
}

get left(): Node {
return this._left;
}

get right(): Node {
return this._right;
}

isLeaf(): boolean {
return false;
}
}

/**
* An immutable binary merkle tree node that has no children
*/
export class LeafNode extends Node {
get rootHashObject(): HashObject {
return this;
}

get root(): Uint8Array {
return hashObjectToUint8Array(this);
}

get left(): Node {
throw Error("LeafNode has no left node");
}

get right(): Node {
throw Error("LeafNode has no right node");
}

static fromRoot(root: Uint8Array): LeafNode {
return this.fromHashObject(uint8ArrayToHashObject(root));
}
Expand Down Expand Up @@ -130,26 +146,10 @@ export class LeafNode extends Node {
return LeafNode.fromHashObject(this);
}

get rootHashObject(): HashObject {
return this;
}

get root(): Uint8Array {
return hashObjectToUint8Array(this);
}

isLeaf(): boolean {
return true;
}

get left(): Node {
throw Error("LeafNode has no left node");
}

get right(): Node {
throw Error("LeafNode has no right node");
}

writeToBytes(data: Uint8Array, start: number, size: number): void {
// TODO: Optimize
data.set(this.root.slice(0, size), start);
Expand Down
12 changes: 6 additions & 6 deletions packages/persistent-merkle-tree/src/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ export class Tree {
}

/**
* Create a `Tree` from a `Proof` object
* The root hash of the tree
*/
static createFromProof(proof: Proof): Tree {
return new Tree(createNodeFromProof(proof));
get root(): Uint8Array {
return this.rootNode.root;
}

/**
Expand Down Expand Up @@ -68,10 +68,10 @@ export class Tree {
}

/**
* The root hash of the tree
* Create a `Tree` from a `Proof` object
*/
get root(): Uint8Array {
return this.rootNode.root;
static createFromProof(proof: Proof): Tree {
return new Tree(createNodeFromProof(proof));
}

/**
Expand Down
9 changes: 5 additions & 4 deletions packages/persistent-ts/src/MutableVector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ import {PersistentVector, TransientVector} from "./Vector.js";
*/
export class MutableVector<T> implements Iterable<T> {
public vector: PersistentVector<T> | TransientVector<T>;

private constructor(vector: PersistentVector<T>) {
this.vector = vector;
}

get length(): number {
return this.vector.length;
}

static empty<T>(): MutableVector<T> {
return new MutableVector(PersistentVector.empty);
}
Expand All @@ -31,10 +36,6 @@ export class MutableVector<T> implements Iterable<T> {
return this;
}

get length(): number {
return this.vector.length;
}

get(index: number): T | undefined {
return this.vector.get(index);
}
Expand Down
8 changes: 4 additions & 4 deletions packages/ssz/src/branchNodeStruct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ export class BranchNodeStruct<T> extends Node {
return hashObjectToUint8Array(this.rootHashObject);
}

isLeaf(): boolean {
return false;
}

get left(): Node {
return this.valueToNode(this.value).left;
}

get right(): Node {
return this.valueToNode(this.value).right;
}

isLeaf(): boolean {
return false;
}
}
36 changes: 18 additions & 18 deletions packages/ssz/src/viewDU/bitArray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,6 @@ export class BitArrayTreeViewDU extends TreeViewDU<CompositeType<BitArray, unkno
return;
}

commit(hcOffset = 0, hcByLevel: HashComputationLevel[] | null = null): void {
if (this._bitArray !== null) {
this._rootNode = this.type.value_toTree(this._bitArray);
}

if (hcByLevel !== null && this._rootNode.h0 === null) {
getHashComputations(this._rootNode, hcOffset, hcByLevel);
}
}

// Wrapped API from BitArray

/** @see BitArray.uint8Array */
Expand All @@ -44,6 +34,24 @@ export class BitArrayTreeViewDU extends TreeViewDU<CompositeType<BitArray, unkno
return this.bitArray.bitLen;
}

/** Lazily computed bitArray instance */
private get bitArray(): BitArray {
if (this._bitArray === null) {
this._bitArray = this.type.tree_toValue(this._rootNode);
}
return this._bitArray;
}

commit(hcOffset = 0, hcByLevel: HashComputationLevel[] | null = null): void {
if (this._bitArray !== null) {
this._rootNode = this.type.value_toTree(this._bitArray);
}

if (hcByLevel !== null && this._rootNode.h0 === null) {
getHashComputations(this._rootNode, hcOffset, hcByLevel);
}
}

/** @see BitArray.get */
get(bitIndex: number): boolean {
return this.bitArray.get(bitIndex);
Expand Down Expand Up @@ -79,14 +87,6 @@ export class BitArrayTreeViewDU extends TreeViewDU<CompositeType<BitArray, unkno
return this.bitArray.toBoolArray();
}

/** Lazily computed bitArray instance */
private get bitArray(): BitArray {
if (this._bitArray === null) {
this._bitArray = this.type.tree_toValue(this._rootNode);
}
return this._bitArray;
}

protected clearCache(): void {
this._bitArray = null;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/ssz/test/memory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ for (let i = 0; i < 1e8; i++) {
const u = new Uint8Array(size);

u.fill(4);
// @ts-ignore
// @ts-expect-error __proto__ is hidden and needs to be overridden
u.__proto__ = null;
refs.push(u);
break;
Expand Down Expand Up @@ -211,6 +211,7 @@ for (let i = 0; i < 1e8; i++) {
const heapUsedM = linearRegression(xs, heapUsed).m;
const rssM = linearRegression(xs, rss).m;

// eslint-disable-next-line no-console
console.log(i, {arrayBuffersM, externalM, heapTotalM, heapUsedM, rssM});
}
}
Expand Down

0 comments on commit dea9709

Please sign in to comment.