Rust implementation of NextGraph, a Decentralized and local-first web 3.0 ecosystem
https://nextgraph.org
byzantine-fault-tolerancecrdtsdappsdecentralizede2eeeventual-consistencyjson-ldlocal-firstmarkdownocapoffline-firstp2pp2p-networkprivacy-protectionrdfrich-text-editorself-hostedsemantic-websparqlweb3collaboration
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.3 KiB
46 lines
1.3 KiB
import type { Commit } from "./commit";
|
|
|
|
export class RegularGraphRows<TNode> {
|
|
protected rows = new Map<Commit["hash"], number>();
|
|
|
|
private maxRowCache: number | undefined = undefined;
|
|
|
|
public constructor(commits: Array<Commit<TNode>>) {
|
|
this.computeRowsFromCommits(commits);
|
|
}
|
|
|
|
public getRowOf(commitHash: Commit["hash"]): number {
|
|
return this.rows.get(commitHash) || 0;
|
|
}
|
|
|
|
public getMaxRow(): number {
|
|
// if (this.maxRowCache === undefined) {
|
|
// this.maxRowCache = uniq(Array.from(this.rows.values())).length - 1;
|
|
// }
|
|
return this.maxRowCache;
|
|
}
|
|
|
|
protected computeRowsFromCommits(commits: Array<Commit<TNode>>): void {
|
|
commits.forEach((commit, i) => {
|
|
this.rows.set(commit.hash, i);
|
|
});
|
|
this.maxRowCache = commits.length - 1;
|
|
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Creates a duplicate-free version of an array.
|
|
*
|
|
* Don't use lodash's `uniq` as it increased bundlesize a lot for such a
|
|
* simple function.
|
|
* => The way we bundle for browser seems not to work with `lodash-es`.
|
|
* => I didn't to get tree-shaking to work with `lodash` (the CommonJS version).
|
|
*
|
|
* @param array Array of values
|
|
*/
|
|
// function uniq<T>(array: T[]): T[] {
|
|
// const set = new Set<T>();
|
|
// array.forEach((value) => set.add(value));
|
|
// return Array.from(set);
|
|
// }
|
|
|