Skip to content

Commit

Permalink
remove uwanted changes
Browse files Browse the repository at this point in the history
  • Loading branch information
JanLewDev committed Aug 30, 2024
1 parent b31fd1d commit 94fe07d
Showing 1 changed file with 2 additions and 45 deletions.
47 changes: 2 additions & 45 deletions packages/object/src/hashgraph/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,7 @@ export class HashGraph<T> {
return result;
}

linearizeOperations(
areCausallyRelatedFn: (v1: Hash, v2: Hash) => boolean = this
.areCausallyRelated,
): Operation<T>[] {
linearizeOperations(): Operation<T>[] {
const order = this.topologicalSort();
const result: Operation<T>[] = [];
let i = 0;
Expand All @@ -194,7 +191,7 @@ export class HashGraph<T> {
while (j < order.length) {
const moving = order[j];

if (!areCausallyRelatedFn(anchor, moving)) {
if (!this.areCausallyRelated(anchor, moving)) {
const v1 = this.vertices.get(anchor);
const v2 = this.vertices.get(moving);
let action: ActionType;
Expand Down Expand Up @@ -253,46 +250,6 @@ export class HashGraph<T> {
return test1 || test2;
}

areCausallyRelatedOld(hash1: Hash, hash2: Hash): boolean {
const visited = new Set<Hash>();
const stack = [hash1];

while (stack.length > 0) {
const current = stack.pop();
if (current === hash2) return true;
if (current === undefined) continue;
visited.add(current);

const vertex = this.vertices.get(current);
if (!vertex) continue;
for (const dep of vertex.dependencies) {
if (!visited.has(dep)) {
stack.push(dep);
}
}
}

visited.clear();
stack.push(hash2);

while (stack.length > 0) {
const current = stack.pop();
if (current === hash1) return true;
if (current === undefined) continue;
visited.add(current);

const vertex = this.vertices.get(current);
if (!vertex) continue;
for (const dep of vertex.dependencies) {
if (!visited.has(dep)) {
stack.push(dep);
}
}
}

return false;
}

// Time complexity: O(1), Space complexity: O(1)
getFrontier(): Hash[] {
return Array.from(this.frontier);
Expand Down

0 comments on commit 94fe07d

Please sign in to comment.