Add electron
This commit is contained in:
35
backend/src/Model/Edge.ts
Normal file
35
backend/src/Model/Edge.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { Hashable, TreeNode } from './'
|
||||
const sha1 = require('sha1')
|
||||
|
||||
export class Edge implements Hashable {
|
||||
public name: string
|
||||
|
||||
public node!: TreeNode
|
||||
public source?: TreeNode | undefined
|
||||
private cachedHash?: string
|
||||
|
||||
constructor(name: string) {
|
||||
this.name = name
|
||||
}
|
||||
|
||||
public edges() {
|
||||
return this.node ? Object.values(this.node.edges) : []
|
||||
}
|
||||
|
||||
public hash(): string {
|
||||
if (!this.cachedHash) {
|
||||
let previousHash = (this.source && this.source.sourceEdge) ? this.source.sourceEdge.hash() : ''
|
||||
this.cachedHash = 'H' + sha1(previousHash + this.name)
|
||||
}
|
||||
|
||||
return this.cachedHash
|
||||
}
|
||||
|
||||
public firstEdge(): Edge {
|
||||
if (this.source && this.source.sourceEdge) {
|
||||
return this.source.sourceEdge.firstEdge()
|
||||
} else {
|
||||
return this
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user